123456789101112131415161718192021222324252627282930313233343536373839 |
- package graphql
- import (
- "context"
- "github.com/Nerzal/gocloak/v12"
- "github.com/gshopify/service-wrapper/scalar"
- "gshopper.com/gshopify/customer/graphql/generated"
- )
- func (r *mutationResolver) CustomerAccessTokenCreate(
- ctx context.Context,
- input generated.CustomerAccessTokenCreateInput) (*generated.CustomerAccessTokenCreatePayload, error) {
- var (
- token *gocloak.JWT
- err error
- response = &generated.CustomerAccessTokenCreatePayload{}
- )
- if token, err = r.client.Login(
- ctx, r.conf.Cli.ClientId, r.conf.Cli.ClientSecret, r.conf.Cli.Realm, input.Email, input.Password); err != nil {
- response.CustomerUserErrors = append(response.CustomerUserErrors,
- CustomerError(generated.CustomerErrorCodeUnidentifiedCustomer, err))
- return response, nil
- }
- if err = r.saveSession(ctx, token); err != nil {
- response.CustomerUserErrors = append(response.CustomerUserErrors,
- CustomerError(generated.CustomerErrorCodeBlank, err))
- return response, nil
- }
- response.CustomerAccessToken = &generated.CustomerAccessToken{
- AccessToken: token.AccessToken,
- ExpiresAt: scalar.NewDateTimeIn(token.RefreshExpiresIn),
- }
- return response, nil
- }
|