Skip to content

Instantly share code, notes, and snippets.

@hirochachacha
Created October 23, 2011 18:00
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 hirochachacha/1307647 to your computer and use it in GitHub Desktop.
Save hirochachacha/1307647 to your computer and use it in GitHub Desktop.
example of hybrid auth
!/usr/bin/env python
#coding: utf-8
from flask import Flask, session, request, redirect
from openid.extensions import oauth as openid_oauth
from openid.consumer.consumer import Consumer
from urlparse import urlparse, urlunparse
app = Flask(__name__)
app.secret_key = "test"
@app.route('/')
def index():
return """
<a href="/auth/google">sign in with openid-oauth hybrid</a>
"""
@app.route('/auth/google')
def auth():
scheme, host, path, p, q, f = urlparse(request.base_url)
consumer = Consumer(session, None)
req = consumer.begin("https://www.google.com/accounts/o8/id")
oauth_scope = "https://www.google.com/m8/feeds/"
oauth_request = openid_oauth.OAuthRequest(host, oauth_scope)
print oauth_request
req.addExtension(oauth_request)
realm = urlunparse([scheme, host, "", "", "", ""])
return_to = urlunparse([scheme, host, "/auth/google/callback", "", "", ""])
return redirect(req.redirectURL(realm, return_to))
@app.route('/auth/google/callback')
def callback():
consumer = Consumer(session, None)
res = consumer.complete(request.args, request.url)
oauth_response = openid_oauth.OAuthResponse.fromSuccessResponse(res)
return "your request token is %s" % oauth_response.request_token
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment