Created
February 15, 2019 07:10
-
-
Save gonzafirewall/7c56c00b079d09e0602f11581557bae3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.oauth2 import id_token | |
from google.auth.transport import requests | |
from allauth.socialaccount.providers.oauth2.views import ( | |
OAuth2Adapter, | |
OAuth2CallbackView, | |
OAuth2LoginView, | |
) | |
from allauth.socialaccount.providers.google.views import GoogleOAuth2Adapter | |
from allauth.socialaccount.providers.google.provider import GoogleProvider | |
class GoogleOAuth2AdapterIdToken(GoogleOAuth2Adapter): | |
def complete_login(self, request, app, token, **kwargs): | |
idinfo = id_token.verify_oauth2_token(token.token, requests.Request(), app.client_id) | |
if idinfo['iss'] not in ['accounts.google.com', 'https://accounts.google.com']: | |
raise ValueError('Wrong issuer.') | |
extra_data = idinfo | |
login = self.get_provider() \ | |
.sociallogin_from_response(request, | |
extra_data) | |
return login | |
oauth2_login = OAuth2LoginView.adapter_view(GoogleOAuth2AdapterIdToken) | |
oauth2_callback = OAuth2CallbackView.adapter_view(GoogleOAuth2AdapterIdToken) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is the role of
oauth2_login
andoauth2_callback
variables at the end? Are they used somewhere?