attempting token refreshing but, I dont like adding echo to that package
This commit is contained in:
parent
5361e3c655
commit
ed1ca5831a
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user