django-graphql-social-auth

Python Social Auth support for Graphene Django

Showing:

Popularity

Downloads/wk

0

GitHub Stars

98

Maintenance

Last Commit

2yrs ago

Contributors

5

Package

Dependencies

0

License

MIT

Categories

Readme

Django GraphQL Social Auth

|Pypi| |Wheel| |Build Status| |Codecov| |Code Climate|

Python Social Auth support for Django GraphQL

.. _Django GraphQL: https://github.com/graphql-python/graphene-django

Dependencies

  • Python ≥ 3.4
  • Django ≥ 1.11

Installation

Install last stable version from Pypi.

.. code:: sh

pip install django-graphql-social-auth

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

.. _documentation: http://python-social-auth.readthedocs.io/en/latest/configuration/django.html

Add the SocialAuth mutation to your GraphQL schema.

.. code:: python

import graphene
import graphql_social_auth


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

Session_ authentication via accessToken.

.. _Session: https://docs.djangoproject.com/en/2.0/topics/http/sessions/

  • provider: provider name from Authentication backend list_.
  • accessToken: third-party (Google, Facebook...) OAuth token obtained with any OAuth client.

.. _Authentication backend list: https://github.com/flavors/django-graphql-social-auth/wiki/Authentication-backends

.. code:: graphql

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_.

.. _JSON Web Token: https://jwt.io/

Install additional requirements.

.. code:: sh

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

Add the SocialAuthJWT mutation to your GraphQL schema.

.. code:: python

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.

.. code:: graphql

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

Relay

Complete support for Relay_.

.. _Relay: https://facebook.github.io/relay/

.. code:: python

import graphene
import graphql_social_auth


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

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

Relay mutations_ only accepts one argument named input:

.. _Relay mutations: https://facebook.github.io/relay/graphql/mutations.htm

.. code:: graphql

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

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.

.. code:: python

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.

.. code:: graphql

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.

.. _Django project template: https://github.com/ice-creams/graphql-social-auth-template


Gracias @omab / Python Social Auth.

.. _@omab: https://github.com/omab .. _Python Social Auth: http://python-social-auth.readthedocs.io/

.. |Pypi| image:: https://img.shields.io/pypi/v/django-graphql-social-auth.svg :target: https://pypi.python.org/pypi/django-graphql-social-auth

.. |Wheel| image:: https://img.shields.io/pypi/wheel/django-graphql-social-auth.svg :target: https://pypi.python.org/pypi/django-graphql-social-auth

.. |Build Status| image:: https://travis-ci.org/flavors/django-graphql-social-auth.svg?branch=master :target: https://travis-ci.org/flavors/django-graphql-social-auth

.. |Codecov| image:: https://img.shields.io/codecov/c/github/flavors/django-graphql-social-auth.svg :target: https://codecov.io/gh/flavors/django-graphql-social-auth

.. |Code Climate| image:: https://api.codeclimate.com/v1/badges/c579bcfde0fbb7f6334c/maintainability :target: https://codeclimate.com/github/flavors/django-graphql-social-auth

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial