Created
October 24, 2013 03:41
-
-
Save chriskief/7130950 to your computer and use it in GitHub Desktop.
This file contains 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
import urllib | |
from django.conf import settings | |
from django.core.urlresolvers import reverse | |
from django.core.context_processors import csrf | |
def get_authorization_url(request): | |
# URL to where we will redirect to | |
redirect_url = urllib.quote_plus(settings.SITE_URL + reverse('register_google')) | |
# create a unique state value for CSRF validation | |
request.session['google_state'] = unicode(csrf(request)['csrf_token']) | |
scope = urllib.quote_plus('https://www.googleapis.com/auth/userinfo.email') + '+' + \ | |
urllib.quote_plus('https://www.googleapis.com/auth/userinfo.profile') | |
# redirect to google for approval | |
url = 'https://accounts.google.com/o/oauth2/auth?' \ | |
+ 'scope=' + scope \ | |
+ '&state=' + request.session['google_state'] \ | |
+ '&redirect_uri=' + redirect_url \ | |
+ '&response_type=code' \ | |
+ '&client_id=' + settings.GOOGLE_OAUTH2_CLIENT_ID \ | |
+ '&access_type=offline' \ | |
+ '&approval_prompt=auto' | |
return url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment