Skip to content

Django application to manage Google OAuth with flexibility in json data of google.

Notifications You must be signed in to change notification settings

anupy/google-oauth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Read below link to understand Google AOuth

https://developers.google.com/identity/protocols/OpenIDConnect

Login to create and create APPLICATION and get Client ID and SECRET

https://console.developers.google.com/

Put following constansts into settings.py
Change values of constants as per your need
Put following namespaces into url
Viewput your view name
  • url(r'^authlogin/$', View.google_login, name='authlogin'), #authlogin the link you have passed for Google Auth Login.
  • url(r'^auth/complete/google-oauth2/$', View.site_authentication, name='googleauthenticate'), #redirect uri which you have given in Google console.
Put following code into your View.google_login method
Consider project as your django project
from project.GoogleOAuth.Google import GoogleOAuth
from project import settings
from django.contrib import messages

def google_login(request):
    try:
        url = GoogleOAuth.google_redirect(settings,request)
        if url:
            return HttpResponseRedirect(url)
        else:
            messages.add_message(request, messages.ERROR, 'Could not login through google, please contact site administrator.')
            return HttpResponseRedirect('{loginfailed}'.format(loginfailed = settings.LOGIN_FAILED_URL))
    except Exception as e:
        return HttpResponseRedirect(settings.LOGIN_URL)
Put following code into your View.site_authentication method
Consider project as your django project
from project.GoogleOAuth.Google import GoogleOAuth
from project import settings
from django.contrib import messages

def site_authentication(request):
    token_data = GoogleOAuth.google_authenticate(request,settings)
    google_profile = GoogleOAuth.get_google_profile(token_data,settings)
NOW process to google_profile json we got from google. :simple_smile:

About

Django application to manage Google OAuth with flexibility in json data of google.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages