-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathapp.py
134 lines (112 loc) · 4.36 KB
/
app.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import json, requests
from flask import Flask, Response, request, render_template
from cryptography.fernet import base64
from settings import YOTI_API_URL, YOTI_CLIENT_SDK_ID, YOTI_KEY_FILE_PATH
from yoti_python_sdk.digital_identity import (
DigitalIdentityClient
)
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/sessions")
def sessions():
session_config = {
"policy": {
"wanted": [
{
"name": "date_of_birth",
"derivation": "age_over:18",
"optional": "false"
}
,
{
"name": "full_name"
},
{
"name": "email_address"
},
{
"name": "phone_number"
},
{
"name": "selfie"
},
{
"name": "date_of_birth",
"derivation": "age_over:18"
},
{
"name": "nationality"
},
{
"name": "gender"
},
{
"name": "document_details"
},
{
"name": "document_images"
}],
"wanted_auth_types": [],
"wanted_remember_me": "false",
},
"extensions": [],
"subject": {
"subject_id": "some_subject_id_string"
}, # Optional reference to a user ID
"notification": {
"url": "https://webhook.site/818dc66b-e18b-4767-92c5-47c7af21629c",
"method": "POST",
"headers": {},
"verifyTls": "true"
},
"redirectUri": "/profile" # Mandatory redirect URI but not required for Non-browser flows
}
digital_identity_client = DigitalIdentityClient(YOTI_CLIENT_SDK_ID, YOTI_KEY_FILE_PATH, YOTI_API_URL)
share_session_result = digital_identity_client.create_share_session(session_config)
session_id = share_session_result.id
# create_qr_code_result = create_share_qr_code(share_session_result.id)
# get_share_session_result = get_share_session(share_session_result.id)
# get_qr_code_result = get_share_qr_code(create_qr_code_result.id)
# Return Session ID JSON
return json.dumps({"session_id": session_id})
@app.route("/create-qr-code")
def create_qr_code():
# Get query params - sessionId
session_id = request.args.get('sessionId')
digital_identity_client = DigitalIdentityClient(YOTI_CLIENT_SDK_ID, YOTI_KEY_FILE_PATH, YOTI_API_URL)
# Create QR Code
create_qr_code_result = digital_identity_client.create_share_qr_code(session_id)
# Return QR Code ID and URI JSON
return json.dumps({"qr_code_id": create_qr_code_result.id, "qr_code_uri": create_qr_code_result.uri})
@app.route("/render-qr-code")
def render_qr_code():
# Get query params - qrCodeUri
qr_code_uri = request.args.get('qrCodeUri')
# Make a POST request to the API to create a QR Code image
url = "https://api.yoti.com/api/v1/qrcodes/image"
payload = { "url": str(qr_code_uri) }
headers = {
"Accept": "image/png",
"Content-Type": "application/json"
}
response = requests.request("POST", url, json=payload, headers=headers)
# Return QR Code Image as PNG
return Response(response.content, mimetype='image/png')
@app.route("/profile")
def profile():
# Get query params - receiptId
receipt_id = request.args.get('receiptId')
digital_identity_client = DigitalIdentityClient(YOTI_CLIENT_SDK_ID, YOTI_KEY_FILE_PATH, YOTI_API_URL)
share_receipt = digital_identity_client.get_share_receipt(receipt_id)
age_over_verification = share_receipt.userContent.profile.find_age_over_verification(18)
selfie = share_receipt.userContent.profile.selfie.value
attribute_list = share_receipt.userContent.profile.attributes
full_name = share_receipt.userContent.profile.full_name.value
data = base64.b64encode(selfie).decode("utf-8")
selfie_image = "data:{0};base64,{1}".format("image/jpeg", data)
age_verified = age_over_verification.result
return render_template("profile.html", age_verified=age_verified, selfie=selfie, full_name=full_name, selfie_image=selfie_image, attribute_list = attribute_list)
if __name__ == "__main__":
app.run(host="0.0.0.0", ssl_context="adhoc")