Last active
          December 26, 2015 09:39 
        
      - 
      
 - 
        
Save chriskief/7130851 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
    
  
  
    
  | 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 Facebook will redirect to | |
| redirect_url = urllib.quote_plus(settings.SITE_URL + reverse('register_facebook')) | |
| # create a unique state value for CSRF validation | |
| request.session['facebook_state'] = unicode(csrf(request)['csrf_token']) | |
| # redirect to facebook for approval | |
| url = 'https://www.facebook.com/dialog/oauth?' \ | |
| + 'client_id=' + settings.FACEBOOK_APP_ID \ | |
| + '&redirect_uri=' + redirect_url \ | |
| + '&scope=email' \ | |
| + '&state=' + request.session['facebook_state'] | |
| return url | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment