Skip to content

Instantly share code, notes, and snippets.

@chriskief
Created October 24, 2013 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriskief/7131179 to your computer and use it in GitHub Desktop.
Save chriskief/7131179 to your computer and use it in GitHub Desktop.
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):
# encode the url
redirect_url = urllib.quote_plus(settings.SITE_URL + reverse('register_microsoft'))
# create a unique state value for CSRF validation
request.session['microsoft_state'] = unicode(csrf(request)['csrf_token'])
# redirect to microsoft for approval
url = 'https://login.live.com/oauth20_authorize.srf?' \
+ 'client_id=' + settings.MICROSOFT_CLIENT_ID \
+ '&redirect_uri=' + redirect_url \
+ '&scope=wl.signin%20wl.basic%20wl.emails' \
+ '&state=' + request.session['microsoft_state'] \
+ '&response_type=code'
return url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment