Skip to main content

Python Social Auth support for Django GraphQL

Project description

Pypi Wheel Build Status Codecov Code Climate

Python Social Auth support for Django GraphQL

Dependencies

  • Python ≥ 3.4

  • Django ≥ 1.11

Installation

Install last stable version from Pypi.

pip install django-graphql-social-auth

See the documentation for further guidance on setting Python Social Auth.

Add the SocialAuth mutation to your GraphQL schema.

import graphene
import graphql_social_auth


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

Session authentication via access_token.

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

JSON Web Token (JWT)

Authentication solution based on JSON Web Token.

Install additional requirements.

pip install 'django-graphql-social-auth[jwt]'

Add the SocialAuthJWT mutation to your GraphQL schema.

import graphene
import graphql_social_auth


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

Authenticate via access_token to obtain a JSON Web Token.

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

Relay

Complete support for Relay.

import graphene
import graphql_social_auth


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

graphql_social_auth.relay.SocialAuthJWT for JSON Web Token (JWT) authentication.

Customizing

Some kinds of projects may have authentication requirements for which SocialAuth mutation is not always appropriate.

You can override the default payload by providing a subclass of SocialAuthMutation or .relay.SocialAuthMutation.

import graphene
import graphql_social_auth


class SocialAuth(graphql_social_auth.SocialAuthMutation):
    user = graphene.Field(UserType)

    @classmethod
    def do_auth(cls, info, social, **kwargs):
        return cls(user=social.user)

Authenticate via access_token to obtain the user id.

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

Gracias Matías.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-graphql-social-auth-0.0.3.tar.gz (7.8 kB view hashes)

Uploaded Source

Built Distribution

django_graphql_social_auth-0.0.3-py2.py3-none-any.whl (10.8 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page