micropub-flask-gitea/example.py

55 lines
1.2 KiB
Python
Raw Normal View History

from flask import Flask, request, url_for
from flask.ext.micropub import Micropub
app = Flask(__name__)
2015-01-19 17:01:56 +00:00
app.config['SECRET_KEY'] = 'my super secret key'
micropub = Micropub(app)
@app.route('/micropub-callback')
@micropub.authorized_handler
2015-01-19 17:01:56 +00:00
def micropub_callback(resp):
return """
<!DOCTYPE html>
<html>
2015-01-19 17:01:56 +00:00
<body>
<ul>
<li>me: {}</li>
<li>token: {}</li>
<li>next: {}</li>
<li>error: {}</li>
</ul>
</body>
</html>
2015-01-19 17:01:56 +00:00
""".format(resp.me, resp.access_token, resp.next_url, resp.error)
@app.route('/')
def index():
me = request.args.get('me')
if me:
return micropub.authorize(
2015-01-19 17:01:56 +00:00
me, redirect_url=url_for('micropub_callback', _external=True),
scope=request.args.get('scope'))
return """
<!DOCTYPE html>
<html>
2015-01-19 17:01:56 +00:00
<body>
<form action="" method="GET">
<input type="text" name="me" placeholder="your domain.com"/>
<select name="scope">
<option>read</option>
<option>write</option>
<option>comment</option>
</select>
<button type="submit">Authorize</button>
</form>
</body>
</html>
"""
if __name__ == '__main__':
app.run(debug=True)