Roy Martinez
Roy Martinez

Reputation: 358

How to get the Refresh Token with the django-graphql-social-auth library

Hi I am using the django-graphql-social-auth library and whenever I create a social user using this mutation:

import graphene
import graphql_social_auth


class Mutations(graphene.ObjectType):
    social_auth = graphql_social_auth.SocialAuthJWT.Field()

and this Graphql mutation:

mutation SocialAuth($provider: String!, $accessToken: String!) {
  socialAuth(provider: $provider, accessToken: $accessToken) {
    social {
      uid
    }  
    token
    refreshToken
    }
 }

I get this error:

    {
  "errors": [
    {
      "message": "Cannot query field \"refreshToken\" on type \"SocialAuthJWT\".",
      "locations": [
        {
          "line": 29,
          "column": 5
        }
      ]
    }
  ]
}

Thanks in advance for your help.

Upvotes: 0

Views: 623

Answers (1)

Roy Martinez
Roy Martinez

Reputation: 358

I solved it as follows:

    # Social authentication
class SocialAuth(graphql_social_auth.SocialAuthMutation):
    token = graphene.String()
    refresh_token = graphene.String()

    @classmethod
    def resolve(cls, root, info, social, **kwargs):
        if social.user.refresh_tokens.count() >= 1:
            return cls(token=get_token(social.user), refresh_token=social.user.refresh_tokens.last())
        else:
            return cls(token=get_token(social.user), refresh_token=create_refresh_token(social.user))

Upvotes: 2

Related Questions