Python Social Auth support for Django GraphQL
Project description
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 accessToken.
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 accessToken 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
If you want to customize the SocialAuth behavior, you’ll need to customize the .resolve() method on 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 resolve(cls, root, info, social, **kwargs):
return cls(user=social.user)
Authenticate via accessToken to obtain the user id.
mutation SocialAuth($provider: String!, $accessToken: String!) {
socialAuth(provider: $provider, accessToken: $accessToken) {
social {
uid
}
user {
id
}
}
}
Project template
There is a Django project template to start a demo project.
Gracias @omab / Python Social Auth.
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
Built Distribution
Hashes for django-graphql-social-auth-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79e27e7bf968b56b114abd96687563188f3060354b76003e04a6c550ebdea005 |
|
MD5 | 51482cb1ccfc69354ccab0edcabed094 |
|
BLAKE2b-256 | 42c4154758f3bf151e4e2c8520a62c1c091de7d92cb7d7c86b1a8439fa38eb81 |
Hashes for django_graphql_social_auth-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 950a079d87d0644f731ebf86fa2639c8bedf058c9253e2644f1088ea14535690 |
|
MD5 | 204737520ab1d967c2a28886d5d1f106 |
|
BLAKE2b-256 | c2c9e8516332cdaaddf4eeee62672bbe58efb5398aa4eddaf31e179ffc9caca8 |