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 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
Built Distribution
Hashes for django-graphql-social-auth-0.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09b39319a1b4b27b892b51efec66e2e54cca3abcae22612e0e135586d8c595e2 |
|
MD5 | eb3f6205aae098090c1d9aecccb24825 |
|
BLAKE2b-256 | 90bbb58919e767a44da2d0ffa95ecd24766acd2ac90013c8ed7f36baf645c075 |
Hashes for django_graphql_social_auth-0.0.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13090aad86f3021ac828dcbe8c0a0a9a27f4cd9c8f3ce232f47735da76729a07 |
|
MD5 | e6a261354f7dd2797c19968a5b4fa67a |
|
BLAKE2b-256 | 5812dbb76b20fb9023df99f3ffe86ad6f7f710991caae5577ccb7e57cd233fff |