Skip to content

AhtishamShahid/socialAuth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Social Auth - Django

This app is basic implementation of python-social-auth Python Social Auth is an easy to setup social authentication/registration mechanism with support for several frameworks and auth providers.

Description

In this app basic implementation of social authentication with Google OAuth2 is created

Project documentation is available at http://python-social-auth.readthedocs.org/.

Setup

  1. create basic django applcation.
  2. install python-social-auth package.
$ pip install python-social-auth
  1. Add following in settings.py

To create social auth keys please refer to: https://developers.google.com/identity/sign-in/web/sign-in

    # Add social_django in installed apps settings 
    INSTALLED_APPS = [
    .....
    'social_django',
    .....
    ]

    # add google auth backend and django default backend
    AUTHENTICATION_BACKENDS = (
        'social_core.backends.google.GoogleOAuth2',
        'django.contrib.auth.backends.ModelBackend',
    )
        
    # create app in google console and add api keys
    SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = ''
    SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = ''
    # Add redirect url on which user is redireced after authentication
    SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/login/'
  1. Create new module with any name (sauth in this repo) and do not foget to add it to INSTALLED_APPS
  2. Add path('', include('sauth.urls')) to urls.py file in new created file.
  3. Create view and template file in this module.
  4. Create new view in view.py
from django.views.generic import TemplateView

class LoginView(TemplateView):
    template_name = "login.html"
  1. in templates/login.html add following HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Login</title>
</head>
<body>
    <a href="{% url "social:begin" "google-oauth2" %}">Google+</a>
    <p>{{ user.is_authenticated }} {{ user.username }}</p>
</body>
</html>
  1. In sauth/urls.py add new url poining to the view created above.
path('', include('social_django.urls', namespace='social')),
  1. Include these urls to root app urls.py ie
path('', include('sauth.urls'))

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published