Skip to content

Instantly share code, notes, and snippets.

def verify(request):
# Twitter will direct with oauth_token and oauth_verifier in the URL
# ?oauth_token=EoSsg1...&oauth_verifier=NB3bvAkb...
# did the user deny the request
if 'denied' in request.GET:
return False
# ensure we have a session state and the state value is the same as what twitter returned
if 'twitter_request_token_key' not in request.session \
import json
import tweepy
from django.conf import settings
from app.lib import RawJsonParser
def get_user_data(request):
data = {}
from tweepy.parsers import Parser
class RawJsonParser(Parser):
def parse(self, method, payload):
return payload
# https://code.google.com/apis/console/
GOOGLE_OAUTH2_CLIENT_ID = 'YOUR-APP-ID'
GOOGLE_OAUTH2_CLIENT_SECRET = 'YOUR-APP-SECRET'
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'))
def verify(request):
# Google will direct with state and code in the URL
# ?state=zNHRjuYO...&code=4/zK5F93g2we...
# ensure we have a session state and the state value is the same as what google returned
if 'google_state' not in request.session \
or 'state' not in request.GET \
or 'code' not in request.GET \
or request.session['google_state'] != request.GET['state']:
return False
import urllib2
import json
import re
from django.conf import settings
from django.core.urlresolvers import reverse
def get_user_data(request):
data = {}
class NotFound(Exception):
def __init__(self, template):
# call the base class constructor
Exception.__init__(self, 'Record not found')
# set the template
self.template = template
from django.shortcuts import render
from app.exceptions.custom import NotFound
class ExceptionMiddleware(object):
def process_exception(self, request, exception):
if type(exception) == NotFound:
return render(request, exception.template)
return None