|
|
- # -*- coding: utf-8 -*-
-
- from flask import Flask, request, redirect, make_response, send_from_directory
- from mastodon import Mastodon
- from config import C
-
- app = Flask(__name__)
- app.config.from_object('config.C')
-
- MAST_LOGIN_URL = Mastodon(api_base_url=C.mast_base_uri).auth_request_url(
- client_id=C.mast_client_id,
- redirect_uris=C.mast_redirect_uri, scopes=['read', 'write']
- )
-
-
- @app.route('/static/<path:path>')
- def send_static(path):
- return send_from_directory('static/', path)
-
-
- @app.route('/')
- def main():
- return app.send_static_file('index.html')
-
-
- @app.route('/auth')
- def mast_login_auth():
- code = request.args.get('code')
- client = Mastodon(
- client_id=C.mast_client_id,
- client_secret=C.mast_client_sec,
- api_base_url=C.mast_base_uri
- )
- token = client.log_in(code=code, redirect_uri=C.mast_redirect_uri,
- scopes=['read', 'write'])
- resp = make_response(redirect('.'))
- resp.set_cookie('mast_token', token)
- return resp
-
-
- if __name__ == '__main__':
- app.run(debug=True)
|