Skip to content

Instantly share code, notes, and snippets.

@kamotos
Created May 23, 2012 17:34
Show Gist options
  • Save kamotos/2776559 to your computer and use it in GitHub Desktop.
Save kamotos/2776559 to your computer and use it in GitHub Desktop.
Compatibility with Django 1.2
from urllib import urlencode
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext
from fandjango.models import User
from fandjango.settings import (
FACEBOOK_APPLICATION_ID, FACEBOOK_APPLICATION_DOMAIN,
FACEBOOK_APPLICATION_NAMESPACE, FACEBOOK_APPLICATION_SECRET_KEY,
FACEBOOK_APPLICATION_INITIAL_PERMISSIONS
)
def authorize_application(request, redirect_uri='https://%s/%s' % (FACEBOOK_APPLICATION_DOMAIN, FACEBOOK_APPLICATION_NAMESPACE)):
"""
Redirect the user to authorize the application.
Redirection is done by rendering a JavaScript snippet that redirects the parent
window to the authorization URI, since Facebook will not allow this inside an iframe.
"""
query = {
'client_id': FACEBOOK_APPLICATION_ID,
'redirect_uri': redirect_uri
}
if FACEBOOK_APPLICATION_INITIAL_PERMISSIONS:
query['scope'] = ', '.join(FACEBOOK_APPLICATION_INITIAL_PERMISSIONS)
return render_to_response(
context_instance=RequestContext(request),
template_name = 'fandjango/authorize_application.html',
dictionary = {
'url': 'https://graph.facebook.com/oauth/authorize?%s' % urlencode(query)
},
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment