oquidave

django google login with social auth

Apr 30th, 2014
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.98 KB | None | 0 0
  1. #settings.py
  2.  
  3. '''#authentication using social media and google using social auth extension'''
  4.  
  5. #First setup your base-line login urls
  6. LOGIN_URL = '/login/'
  7. LOGIN_REDIRECT_URL = '/members/'
  8. LOGIN_ERROR_URL = '/login-error/'
  9.  
  10. #Add social_auth to your INSTALLED_APPS
  11. INSTALLED_APPS += (
  12.     'social_auth',
  13.     )
  14.  
  15. #Add a new config setting which will define the authentication types you wish to support
  16. AUTHENTICATION_BACKENDS = (
  17.   'social_auth.backends.google.GoogleOAuth2Backend',
  18.   'social_auth.backends.contrib.github.GithubBackend',
  19.   'django.contrib.auth.backends.ModelBackend',
  20. )
  21.  
  22. #Add social_auth as a template processor
  23. TEMPLATE_CONTEXT_PROCESSORS += (
  24.   "social_auth.context_processors.social_auth_by_type_backends",
  25. )
  26.  
  27. #Some social_auth specific settings
  28. SOCIAL_AUTH_DEFAULT_USERNAME = 'new_social_auth_user'
  29. SOCIAL_AUTH_UID_LENGTH = 16
  30. SOCIAL_AUTH_ASSOCIATION_HANDLE_LENGTH = 16
  31. SOCIAL_AUTH_NONCE_SERVER_URL_LENGTH = 16
  32. SOCIAL_AUTH_ASSOCIATION_SERVER_URL_LENGTH = 16
  33. SOCIAL_AUTH_ASSOCIATION_HANDLE_LENGTH = 16
  34.  
  35. #social_auth backends
  36. SOCIAL_AUTH_ENABLED_BACKENDS = ('google', 'github')
  37.  
  38. #Add your respective social API information.
  39. GITHUB_API_KEY = ''
  40. GITHUB_API_SECRET = ''
  41.  
  42. GOOGLE_OAUTH2_CLIENT_ID = 'some client id from google developer console.apps.googleusercontent.com'
  43. GOOGLE_OAUTH2_CLIENT_SECRET = 'some client key from google developer console'
  44.  
  45. #url.py
  46. #social login
  47. urlpatterns += patterns('',
  48.   url(r'', include('social_auth.urls')),
  49. )
  50.  
  51. #html
  52. """
  53. <li><a href="{% url 'socialauth_begin' 'google-oauth2' %}">Login with Google</a></li>
  54. """
  55.  
  56. #developer console configs
  57. """
  58. Redirect URIs   https://127.0.0.1:8000/oauth2callback
  59. Javascript Origins  https://127.0.0.1:8000
  60. """
  61.  
  62. #login
  63. """
  64. clicking on the login click, brings this url in the browser address bar, but loads nothing!!
  65. http://localhost:8000/login/google-oauth2/
  66.  
  67. """
  68.  
  69. #server logs
  70. """
  71. shows page is served!!
  72. [30/Apr/2014 22:54:58] "GET /login/google-oauth2/ HTTP/1.1" 200 3467
  73. """
Add Comment
Please, Sign In to add comment