OAuth ConfigurationΒΆ

OAuth functionality (e.g. sign up using Facebook) is enabled by third-party module social_django.

Below are just the steps needed to make social_django compatible with django_flex_user. For a complete configuration example refer to the Reference Project.

For instructions on how to configure social_django, refer to its documentation here

  1. Configure AUTHENTICATION_BACKENDS in settings.py:

        'django_flex_user.backends.FlexUserFacebookOAuth2', # Add me
        'django_flex_user.backends.FlexUserGoogleOAuth2', # Add me


    At present, the only OAuth providers django_flex_user provides built-in support for are Facebook and Google.

    If you want to add support for additional OAuth providers, extend the corresponding backend in social_core.backends and override its get_user_details() method. (See django_flex_user.backends.FlexUserFacebookOAuth2 for an implementation example.)

    Once done, append the new class to AUTHENTICATION_BACKENDS.

  2. Configure SOCIAL_AUTH_CLEAN_USERNAME_FUNCTION in settings.py:

    SOCIAL_AUTH_CLEAN_USERNAME_FUNCTION = 'django_flex_user.validators.flex_user_clean_username'
  3. Configure SOCIAL_AUTH_PIPELINE in settings.py:

     1# Pipeline configuration
     3    # Get the information we can about the user and return it in a simple
     4    # format to create the user instance later. On some cases the details are
     5    # already part of the auth response from the provider, but sometimes this
     6    # could hit a provider API.
     7    'social_core.pipeline.social_auth.social_details',
     9    # Get the social uid from whichever service we're authing thru. The uid is
    10    # the unique identifier of the given user in the provider.
    11    'social_core.pipeline.social_auth.social_uid',
    13    # Verifies that the current auth process is valid within the current
    14    # project, this is where emails and domains whitelists are applied (if
    15    # defined).
    16    'social_core.pipeline.social_auth.auth_allowed',
    18    # Checks if the current social-account is already associated in the site.
    19    'social_core.pipeline.social_auth.social_user',
    21    # Make up a username for this person, appends a random string at the end if
    22    # there's any collision.
    23    'social_core.pipeline.user.get_username',
    25    # Send a validation email to the user to verify its email address.
    26    'django_flex_user.verification.mail_validation',
    28    # Associates the current social details with another user account with
    29    # a similar email address.
    30    'social_core.pipeline.social_auth.associate_by_email',
    32    # Create a user account if we haven't found one yet.
    33    'social_core.pipeline.user.create_user',
    35    # Create the record that associated the social account with this user.
    36    'social_core.pipeline.social_auth.associate_user',
    38    # Populate the extra_data field in the social record with the values
    39    # specified by settings (and the default ones like access_token, etc).
    40    'social_core.pipeline.social_auth.load_extra_data',
    42    # Update the user record with any changed info from the auth service.
    43    'social_core.pipeline.user.user_details'


    On line 26 we introduce a custom pipeline function.

  4. Configure email validation in settings.py: