Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #settings.py
- '''#authentication using social media and google using social auth extension'''
- #First setup your base-line login urls
- LOGIN_URL = '/login/'
- LOGIN_REDIRECT_URL = '/members/'
- LOGIN_ERROR_URL = '/login-error/'
- #Add social_auth to your INSTALLED_APPS
- INSTALLED_APPS += (
- 'social_auth',
- )
- #Add a new config setting which will define the authentication types you wish to support
- AUTHENTICATION_BACKENDS = (
- 'social_auth.backends.google.GoogleOAuth2Backend',
- 'social_auth.backends.contrib.github.GithubBackend',
- 'django.contrib.auth.backends.ModelBackend',
- )
- #Add social_auth as a template processor
- TEMPLATE_CONTEXT_PROCESSORS += (
- "social_auth.context_processors.social_auth_by_type_backends",
- )
- #Some social_auth specific settings
- SOCIAL_AUTH_DEFAULT_USERNAME = 'new_social_auth_user'
- SOCIAL_AUTH_UID_LENGTH = 16
- SOCIAL_AUTH_ASSOCIATION_HANDLE_LENGTH = 16
- SOCIAL_AUTH_NONCE_SERVER_URL_LENGTH = 16
- SOCIAL_AUTH_ASSOCIATION_SERVER_URL_LENGTH = 16
- SOCIAL_AUTH_ASSOCIATION_HANDLE_LENGTH = 16
- #social_auth backends
- SOCIAL_AUTH_ENABLED_BACKENDS = ('google', 'github')
- #Add your respective social API information.
- GITHUB_API_KEY = ''
- GITHUB_API_SECRET = ''
- GOOGLE_OAUTH2_CLIENT_ID = 'some client id from google developer console.apps.googleusercontent.com'
- GOOGLE_OAUTH2_CLIENT_SECRET = 'some client key from google developer console'
- #url.py
- #social login
- urlpatterns += patterns('',
- url(r'', include('social_auth.urls')),
- )
- #html
- """
- <li><a href="{% url 'socialauth_begin' 'google-oauth2' %}">Login with Google</a></li>
- """
- #developer console configs
- """
- Redirect URIs https://127.0.0.1:8000/oauth2callback
- Javascript Origins https://127.0.0.1:8000
- """
- #login
- """
- clicking on the login click, brings this url in the browser address bar, but loads nothing!!
- http://localhost:8000/login/google-oauth2/
- """
- #server logs
- """
- shows page is served!!
- [30/Apr/2014 22:54:58] "GET /login/google-oauth2/ HTTP/1.1" 200 3467
- """
Add Comment
Please, Sign In to add comment