Created
April 16, 2013 02:10
-
-
Save washort/5392811 to your computer and use it in GitHub Desktop.
This file contains 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 sys | |
from logging import StreamHandler | |
from flask_oauth import OAuth | |
from flask import session, Flask, url_for, request | |
app = Flask("oauth_test_app") | |
app.secret_key = "flask secret" | |
app.logger.addHandler(StreamHandler(sys.stdout)) | |
mkt_app = OAuth().remote_app( | |
'marketplace', | |
base_url='https://mycroft.local:8443/api/v1/', | |
request_token_url='https://mycroft.local:8443/oauth/token/', | |
access_token_url='https://mycroft.local:8443/oauth/register/', | |
authorize_url='https://mycroft.local:8443/oauth/authorize/', | |
consumer_key='AWESOMEOAUTHKEYFORTESTING', | |
consumer_secret='SECRETSNEVERHURTANYBODY', | |
) | |
@mkt_app.tokengetter | |
def get_oauthy_token(token=None): | |
return session.get('toakn') | |
@app.route("/login") | |
def login(): | |
return mkt_app.authorize( | |
callback=url_for( | |
'oauth_authorized', | |
next=request.args.get('next') or request.referrer or None)) | |
@app.route('/oauth-authorized') | |
@mkt_app.authorized_handler | |
def oauth_authorized(resp): | |
session['toakn'] = ( | |
resp['oauth_token'], | |
resp['oauth_token_secret'] | |
) | |
x = mkt_app.get('apps/app/').data | |
return "yay" + str(x) | |
@app.route('/example') | |
def app_example(): | |
resp = mkt_app.get('apps/app/') | |
if resp.status == 200: | |
return "result is %r" % (resp.data,) | |
else: | |
return "oh no %r" % (resp.status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment