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"
|
"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)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user