Created
October 23, 2011 18:00
-
-
Save hirochachacha/1307647 to your computer and use it in GitHub Desktop.
example of hybrid auth
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
!/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