1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package graphql
- import (
- "context"
- "github.com/gshopify/service-wrapper/auth"
- "github.com/gshopify/service-wrapper/scalar"
- "gshopper.com/gshopify/customer/graphql/generated"
- "gshopper.com/gshopify/customer/model"
- )
- func (r *mutationResolver) CustomerAccessTokenRenew(ctx context.Context, t string) (*generated.CustomerAccessTokenRenewPayload, error) {
- var (
- response = &generated.CustomerAccessTokenRenewPayload{}
- session = auth.SessionManager()
- claims *model.Claims
- err error
- )
- _, claims, err = r.decodeAccessToken(ctx, t)
- if err != nil {
- response.UserErrors = append(response.UserErrors, ErrTokenNotExists)
- return response, nil
- }
- refresh, err := session.Token(ctx, claims.SessionId)
- if err != nil {
- response.UserErrors = append(response.UserErrors, ErrToken(err.Error()))
- return response, nil
- }
- token, err := r.client.RefreshToken(ctx, refresh, r.conf.Cli.ClientId, r.conf.Cli.ClientSecret, r.conf.Cli.Realm)
- if err != nil {
- response.UserErrors = append(response.UserErrors, ErrTokenExpired)
- return response, nil
- }
- if err = r.saveSession(ctx, token); err != nil {
- response.UserErrors = append(response.UserErrors, ErrToken(err.Error()))
- return response, nil
- }
- response.CustomerAccessToken = &generated.CustomerAccessToken{
- AccessToken: token.AccessToken,
- ExpiresAt: scalar.NewDateTimeIn(token.RefreshExpiresIn),
- }
- return response, nil
- }
|