Exemple #1
0
def oauth_callback(request):

    # get the credentials from the Google redirect
    flow = CredentialsFlowWrapper(settings.UI_CLIENT,
                                  redirect_uri=settings.CONST_URL +
                                  '/oauth_callback/')
    flow.code_verifier = request.session.get('code_verifier')
    flow.fetch_token(code=request.GET['code'])

    # get or create the account
    account = Account.objects.get_or_create_user(flow.credentials)

    # log the account in ( set cookie )
    django_login(request, account, backend=settings.AUTHENTICATION_BACKENDS[0])

    messages.success(request, 'Welcome To StarThinker')

    return HttpResponseRedirect('/')
Exemple #2
0
def oauth_callback(request):

  # get the credentials from the Google redirect
  flow = CredentialsFlowWrapper(settings.UI_CLIENT, redirect_uri=settings.CONST_URL + '/oauth_callback/')
  flow.code_verifier = request.session.get('code_verifier')
  flow.fetch_token(code=request.GET['code'])

  # pull user information for account lookup or creation
  service = discovery.build('oauth2', 'v2', credentials=flow.credentials)
  profile = service.userinfo().get().execute()

  # get or create the account
  account = Account.objects.get_or_create_user(profile, flow.credentials)
  #authenticate(username = username, password = password)

  # log the account in ( set cookie )
  django_login(request, account, backend=settings.AUTHENTICATION_BACKENDS[0])

  messages.success(request, 'Welcome To StarThinker')

  return HttpResponseRedirect('/')