简化版的mastodon web client
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.0 KiB

  1. # -*- coding: utf-8 -*-
  2. from flask import Flask, request, redirect, make_response, send_from_directory
  3. from mastodon import Mastodon
  4. from config import C
  5. app = Flask(__name__)
  6. app.config.from_object('config.C')
  7. MAST_LOGIN_URL = Mastodon(api_base_url=C.mast_base_uri).auth_request_url(
  8. client_id=C.mast_client_id,
  9. redirect_uris=C.mast_redirect_uri, scopes=['read', 'write']
  10. )
  11. @app.route('/static/<path:path>')
  12. def send_static(path):
  13. return send_from_directory('static/', path)
  14. @app.route('/')
  15. def main():
  16. return app.send_static_file('index.html')
  17. @app.route('/auth')
  18. def mast_login_auth():
  19. code = request.args.get('code')
  20. client = Mastodon(
  21. client_id=C.mast_client_id,
  22. client_secret=C.mast_client_sec,
  23. api_base_url=C.mast_base_uri
  24. )
  25. token = client.log_in(code=code, redirect_uri=C.mast_redirect_uri,
  26. scopes=['read', 'write'])
  27. resp = make_response(redirect('.'))
  28. resp.set_cookie('mast_token', token)
  29. return resp
  30. if __name__ == '__main__':
  31. app.run(debug=True)