Permalink
Browse files

Implement handlers.

  • Loading branch information...
lepture committed Nov 21, 2013
1 parent ba1fd40 commit cbc3e12a3123f4bbc9d68eb8438247357f213583
Showing with 45 additions and 0 deletions.
  1. +23 −0 app.py
  2. +22 −0 templates/authorize.html
View
23 app.py
@@ -214,6 +214,29 @@ def save_token(token, request, *args, **kwargs):
return tok
@app.route('/oauth/token')
@oauth.token_handler
def access_token():
return None
@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_id = kwargs.get('client_id')
client = Client.query.filter_by(client_id=client_id).first()
kwargs['client'] = client
kwargs['user'] = user
return render_template('authorize.html', **kwargs)
confirm = request.form.get('confirm', 'no')
return confirm == 'yes'
if __name__ == '__main__':
db.create_all()
app.run()
View
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Authorization</title>
</head>
<body>
<p>Client: {{ client.client_id }}</p>
<p>User: {{ user.username }}</p>
<form action="/oauth/authorize" method="post">
<p>Allow access?</p>
<input type="hidden" name="client_id" value="{{ client.client_id }}">
<input type="hidden" name="scope" value="{{ scopes|join(' ') }}">
<input type="hidden" name="response_type" value="{{ response_type }}">
{% if state %}
<input type="hidden" name="state" value="{{ state }}">
{% endif %}
<input type="submit" name="confirm" value="yes">
<input type="submit" name="confirm" value="no">
</form>
</body>
</html>

0 comments on commit cbc3e12

Please sign in to comment.