flask.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Wed Nov 20 16:17:30 2019
  4. @author: Honza
  5. """
  6. from flask import Flask, request, jsonify
  7. import requests
  8. import json
  9. import tempfile
  10. import os
  11. app = Flask(__name__)
  12. def writeCode(value):
  13. path = tempfile.gettempdir() + os.sep + "atlas" + os.sep + "auth.txt"
  14. #path = r'C:\Users\Honza\AppData\Local\Temp\test.txt'
  15. f = open(path, "w")
  16. f.write(value)
  17. f.close()
  18. @app.route('/')
  19. def hello():
  20. return "Hello World!"
  21. @app.route('/<name>')
  22. def hello_name(name):
  23. return "Hello {}!".format(name)
  24. @app.route("/client/authn/oauth2-liferay/callback", methods=['POST', 'GET', 'HEAD', 'OPTIONS'])
  25. def form_to_json():
  26. data = request.form.to_dict(flat=False)
  27. code = request.args.get('code')
  28. writeCode(code)
  29. #return (code)
  30. return "Authorize code optained. Please continue with QGIS plugin."
  31. #@app.route("/client/authn/oauth2-liferay/code", methods=['POST', 'GET', 'HEAD', 'OPTIONS'])
  32. #def sendCode():
  33. # API_ENDPOINT = "http://localhost:3000/client/authn/oauth2-liferay/callback"
  34. # return (authCode)
  35. # # return jsonify(c)
  36. if __name__ == '__main__':
  37. app.run(host='0.0.0.0', port=3000)