features/token-things #2

Merged
jtom38 merged 7 commits from features/token-things into main 2024-07-07 08:03:00 -07:00
Showing only changes of commit ed1ca5831a - Show all commits

View File

@ -6,6 +6,7 @@ import (
"net/url" "net/url"
"git.jamestombleson.com/jtom38/newsbot-api/domain" "git.jamestombleson.com/jtom38/newsbot-api/domain"
"github.com/labstack/echo/v4"
) )
const ( const (
@ -16,6 +17,7 @@ type Users interface {
Login(username, password string) (domain.LoginResponse, error) Login(username, password string) (domain.LoginResponse, error)
SignUp(username, password string) (domain.BaseResponse, error) SignUp(username, password string) (domain.BaseResponse, error)
RefreshJwtToken(username, refreshToken string) (domain.LoginResponse, error) RefreshJwtToken(username, refreshToken string) (domain.LoginResponse, error)
RefreshJwtTokenFromContext(ctx echo.Context) (domain.LoginResponse, error)
RefreshSessionToken(jwtToken string) (domain.BaseResponse, error) RefreshSessionToken(jwtToken string) (domain.BaseResponse, error)
} }
@ -81,6 +83,23 @@ func (a userClient) RefreshJwtToken(username, refreshToken string) (domain.Login
return bind, nil 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) { func (a userClient) RefreshSessionToken(jwtToken string) (domain.BaseResponse, error) {
endpoint := fmt.Sprintf("%s/%s/refresh/sessionToken", a.serverAddress, UserBaseRoute) endpoint := fmt.Sprintf("%s/%s/refresh/sessionToken", a.serverAddress, UserBaseRoute)