-
Notifications
You must be signed in to change notification settings - Fork 0
/
REST-Api.py
45 lines (37 loc) · 1.51 KB
/
REST-Api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import json
import flask
from flask import Flask, request, jsonify
from etheronauth import chainhandler
from etheronauth import web3login
app = Flask(__name__)
@app.route('/token/request/', methods=['POST'])
def create_request():
permission_id = handle_raw_input(request.get_json(force=True))
pending_url = "/token/request/" + str(permission_id)
response = json.dumps({'generated': {"href" : pending_url, "id" : permission_id}})
return response, 200
@app.route('/token/request/<string:permission_id>', methods=['GET'])
def check_request(permission_id):
token = chainhandler.request_token(account, permission_id)
jwt = token["token"]
pending_url = "/token/request/" + str(permission_id)
job = {"job": {"@uri" : pending_url, "id" : str(permission_id), "status": "PENDING"}, "token": "NULL"}
if jwt != "0":
job["job"]["status"] = "COMPLETED"
job["token"] = jwt
json_job = json.dumps(job)
return json_job, 202
else:
json_job = json.dumps(job)
return json_job
def handle_raw_input(json_payload):
aud = json_payload['payload']['aud']
#exp = json_payload['payload']['exp']
#nbf = json_payload['payload']['nbf']
#iat = json_payload['payload']['iat']
#sub = json_payload['payload']['sub']
permission_id = chainhandler.submit_request(account, aud=aud)
return permission_id
if __name__ == '__main__':
account = web3login.web3_silent_login("0x4F6b4c67eEE111497Ef2b85FC1d133D3Ca3FD51B", "TestTestTest")
app.run(debug=True)