mutationCustomerAccessTokenDelete.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package graphql
  2. import (
  3. "context"
  4. "github.com/gshopify/service-wrapper/auth"
  5. "gshopper.com/gshopify/customer/graphql/generated"
  6. "gshopper.com/gshopify/customer/model"
  7. )
  8. func (r *mutationResolver) CustomerAccessTokenDelete(
  9. ctx context.Context, t string) (*generated.CustomerAccessTokenDeletePayload, error) {
  10. var (
  11. response = &generated.CustomerAccessTokenDeletePayload{}
  12. session = auth.SessionManager()
  13. claims *model.Claims
  14. err error
  15. )
  16. _, claims, err = r.decodeAccessToken(ctx, t)
  17. if err != nil {
  18. response.UserErrors = append(response.UserErrors, ErrToken(err.Error()))
  19. return response, nil
  20. }
  21. _ = session.DeleteToken(ctx, claims.SessionId)
  22. admin, err := r.conf.Admin.Token(r.client, ctx)
  23. if err != nil {
  24. response.UserErrors = append(response.UserErrors, ErrToken(err.Error()))
  25. return response, nil
  26. }
  27. if err = r.client.LogoutUserSession(ctx, admin.AccessToken, r.conf.Cli.Realm, claims.SessionId); err != nil {
  28. response.UserErrors = append(response.UserErrors, ErrToken(err.Error()))
  29. return response, nil
  30. }
  31. response.DeletedAccessToken = &t
  32. response.DeletedCustomerAccessTokenID = &claims.SessionId
  33. return response, nil
  34. }