social-app-django icon indicating copy to clipboard operation
social-app-django copied to clipboard

Google User's username does not match UserSocialAuth UID

Open samcrane8 opened this issue 6 years ago • 0 comments

The issue I ran into is the User created for my google login has a username that is slightly different than the UID in UserSocialAuth, making it impossible to query for it.

(Google Auth) User username: google-oauth2.110110613553672810407 UserSocialAuth uid: google-oauth2|110110613553672810407

The two are very similar, but after 'google-oauth2' in the first is a '.', where as in the second 'googl-oauth2' there is a '|'.

Right now in my code I am changing the '.' to a '|' before I look for the actual user association, but I was wondering if this is a broader issue with the library that can be fixed.

Below is the social auth portion of my django settings.py file in case that's helpful.

# Auth0

AUTH0_DOMAIN = os.environ.get('AUTH0_DOMAIN') # The subdomain Auth0 provided (e.g. greenzie.auth0.com)
AUTH0_AUDIENCE = os.environ.get('AUTH0_AUDIENCE') # The address where this server is hosted.
PUBLIC_KEY = None
JWT_ISSUER = None

if AUTH0_DOMAIN:
    JWT_ISSUER = 'https://' + AUTH0_DOMAIN + '/'

JWT_AUTH = {
    'JWT_PAYLOAD_GET_USERNAME_HANDLER':
        'auth0authorization.utils.jwt_get_username_from_payload_handler',
    'JWT_DECODE_HANDLER':
        'auth0authorization.utils.jwt_decode_token',
    'JWT_ALGORITHM': 'RS256',
    'JWT_AUDIENCE': AUTH0_AUDIENCE,
    'JWT_ISSUER': JWT_ISSUER,
    'JWT_AUTH_HEADER_PREFIX': 'Bearer',
}

# Auth0 Django App Workflow

SOCIAL_AUTH_TRAILING_SLASH = False  # Remove trailing slash from routes
SOCIAL_AUTH_AUTH0_DOMAIN = os.environ.get('AUTH0_DOMAIN')
SOCIAL_AUTH_AUTH0_KEY = os.environ.get('SOCIAL_AUTH_AUTH0_KEY')
SOCIAL_AUTH_AUTH0_SECRET = os.environ.get('SOCIAL_AUTH_AUTH0_SECRET')
SOCIAL_AUTH_AUTH0_SCOPE = [
    'openid',
    'profile',
    'email',
    'first_name',
    'username'
]

AUTHENTICATION_BACKENDS = {
    'auth0authorization.auth0backend.Auth0',
    'django.contrib.auth.backends.RemoteUserBackend',
    'django.contrib.auth.backends.ModelBackend'
}

LOGIN_URL = 'http://localhost:8080/'
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'

Also a question: why is UID in UserSocialAuth a text field rather than a foreign key to a User record?

samcrane8 avatar Jan 10 '20 18:01 samcrane8