Skip to content

Commit

Permalink
Add Handlers. And fix some bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Nov 20, 2013
1 parent 88dee80 commit 55664c4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
37 changes: 36 additions & 1 deletion app.py
Expand Up @@ -153,6 +153,7 @@ def client():
item = Client( item = Client(
client_key=gen_salt(40), client_key=gen_salt(40),
client_secret=gen_salt(50), client_secret=gen_salt(50),
_redirect_uris='http://localhost:8000/authorized',
user_id=user.id, user_id=user.id,
) )
db.session.add(item) db.session.add(item)
Expand All @@ -175,7 +176,7 @@ def load_request_token(token):


@oauth.grantsetter @oauth.grantsetter
def save_request_token(token, request): def save_request_token(token, request):
if oauth.realms: if hasattr(oauth, 'realms') and oauth.realms:
realms = ' '.join(request.realms) realms = ' '.join(request.realms)
else: else:
realms = None realms = None
Expand Down Expand Up @@ -250,6 +251,40 @@ def save_access_token(token, request):
db.session.commit() db.session.commit()




@app.route('/oauth/request_token')
@oauth.request_token_handler
def request_token():
return {}


@app.route('/oauth/access_token')
@oauth.access_token_handler
def access_token():
return {}


@app.route('/oauth/authorize', methods=['GET', 'POST'])
@oauth.authorize_handler
def authorize(*args, **kwargs):
user = current_user()
if not user:
return redirect('/')
if request.method == 'GET':
client_key = kwargs.get('resource_owner_key')
client = Client.query.filter_by(client_key=client_key).first()
kwargs['client'] = client
kwargs['user'] = user
return render_template('authorize.html', **kwargs)
confirm = request.form.get('confirm', 'no')
return confirm == 'yes'


import logging
logger = logging.getLogger('flask_oauthlib')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)


if __name__ == '__main__': if __name__ == '__main__':
db.create_all() db.create_all()
app.run() app.run()
17 changes: 17 additions & 0 deletions templates/authorize.html
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Authorization</title>
</head>
<body>
<p>Client: {{ client.client_key }}</p>
<p>User: {{ user.username }}</p>
<form action="/oauth/authorize" method="post">
<p>Allow access?</p>
<input type="hidden" name="oauth_token" value="{{ resource_owner_key }}">
<input type="submit" name="confirm" value="yes">
<input type="submit" name="confirm" value="no">
</form>
</body>
</html>

0 comments on commit 55664c4

Please sign in to comment.