pythondjangogoogle-apigoogle-oauthdjango-socialauth

How to restrict the login google api with specific domain name only?


I'm creating a web application which I'm using Google API for authentication. Also, the library that I've applied was social-auth-app-django. Then, my goal is to allow only specific domain name like user@example.com with a domain of example.com.

Upon reading its documentation this line of code should be added to settings.py SOCIAL_AUTH__WHITELISTED_DOMAINS = ['foo.com', 'bar.com'] however, it is not working to me.

settings.py configuration

AUTHENTICATION_BACKENDS = (
    'social_core.backends.google.GoogleOAuth2',
    'django.contrib.auth.backends.ModelBackend',
)
SOCIAL_AUTH_GOOGLE_OAUTH2_WHITELISTED_DOMAINS = ['example.com.hk']

How can I restrict the google api to only allow the specified whitelisted domains?


Solution

  • You have to add and specify the authorize domains to your google API credentials.