From ed1ca5831ad5b7ed713c646fda2ed8d6a611e302 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Sun, 7 Jul 2024 08:00:23 -0700 Subject: [PATCH] attempting token refreshing but, I dont like adding echo to that package --- apiclient/users.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/apiclient/users.go b/apiclient/users.go index 37ec219..de6b343 100644 --- a/apiclient/users.go +++ b/apiclient/users.go @@ -6,6 +6,7 @@ import ( "net/url" "git.jamestombleson.com/jtom38/newsbot-api/domain" + "github.com/labstack/echo/v4" ) const ( @@ -16,6 +17,7 @@ type Users interface { Login(username, password string) (domain.LoginResponse, error) SignUp(username, password string) (domain.BaseResponse, error) RefreshJwtToken(username, refreshToken string) (domain.LoginResponse, error) + RefreshJwtTokenFromContext(ctx echo.Context) (domain.LoginResponse, error) RefreshSessionToken(jwtToken string) (domain.BaseResponse, error) } @@ -81,6 +83,23 @@ func (a userClient) RefreshJwtToken(username, refreshToken string) (domain.Login return bind, nil } + +func (a userClient) RefreshJwtTokenFromContext(ctx echo.Context) (domain.LoginResponse, error) { + resp := domain.LoginResponse{} + + username, err := ctx.Cookie("newsbot.user") + if err != nil { + return resp, err + } + + refreshToken, err := ctx.Cookie("newsbot.refreshToken") + if err != nil { + return resp, err + } + + return a.RefreshJwtToken(username.Value, refreshToken.Value) +} + func (a userClient) RefreshSessionToken(jwtToken string) (domain.BaseResponse, error) { endpoint := fmt.Sprintf("%s/%s/refresh/sessionToken", a.serverAddress, UserBaseRoute)