Skip to content

Commit e9a8b18

Browse files
committed
SDK-2242 added, create session, qrcode, and retrive session,receipt
1 parent 6fe15da commit e9a8b18

File tree

96 files changed

+3623
-17
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+3623
-17
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Required Keys
2+
YOTI_CLIENT_SDK_ID=yourClientSdkId
3+
YOTI_KEY_FILE_PATH=yourKeyFilePath

examples/digitalidentity/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Yoti Share v2 Python Example
2+
3+
## Running the example project
4+
5+
1. Rename the [.env.example](.env.example) file to `.env` and fill in the required configuration values
6+
2. Add your SDK ID to the [templates/index.html](templates/index.html) file
7+
3. Create a virtual environment with `python3 -m venv .venv`
8+
4. Active the environment `. .venv/bin/activate`
9+
5. Install the dependencies with `pip install -r requirements.txt`
10+
6. Start the server `flask run --port 8000`
11+
7. Visit `http://127.0.0.1:8000`

examples/digitalidentity/__init__.py

Whitespace-only changes.

examples/digitalidentity/app.py

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import json, requests
2+
from flask import Flask, Response, request, render_template
3+
4+
5+
from cryptography.fernet import base64
6+
7+
from settings import YOTI_API_URL, YOTI_CLIENT_SDK_ID, YOTI_KEY_FILE_PATH
8+
9+
from yoti_python_sdk.digital_identity import (
10+
DigitalIdentityClient
11+
)
12+
13+
app = Flask(__name__)
14+
15+
@app.route("/")
16+
def index():
17+
return render_template("index.html")
18+
19+
@app.route("/sessions")
20+
def sessions():
21+
session_config = {
22+
"policy": {
23+
"wanted": [
24+
{
25+
"name": "date_of_birth",
26+
"derivation": "age_over:18",
27+
"optional": "false"
28+
}
29+
,
30+
{
31+
"name": "full_name"
32+
},
33+
{
34+
"name": "email_address"
35+
},
36+
{
37+
"name": "phone_number"
38+
},
39+
{
40+
"name": "selfie"
41+
},
42+
{
43+
"name": "date_of_birth",
44+
"derivation": "age_over:18"
45+
},
46+
{
47+
"name": "nationality"
48+
},
49+
{
50+
"name": "gender"
51+
},
52+
{
53+
"name": "document_details"
54+
},
55+
{
56+
"name": "document_images"
57+
}],
58+
"wanted_auth_types": [],
59+
"wanted_remember_me": "false",
60+
},
61+
"extensions": [],
62+
"subject": {
63+
"subject_id": "some_subject_id_string"
64+
}, # Optional reference to a user ID
65+
"notification": {
66+
"url": "https://webhook.site/818dc66b-e18b-4767-92c5-47c7af21629c",
67+
"method": "POST",
68+
"headers": {},
69+
"verifyTls": "true"
70+
},
71+
"redirectUri": "/profile" # Mandatory redirect URI but not required for Non-browser flows
72+
}
73+
74+
digital_identity_client = DigitalIdentityClient(YOTI_CLIENT_SDK_ID, YOTI_KEY_FILE_PATH, YOTI_API_URL)
75+
76+
share_session_result = digital_identity_client.create_share_session(session_config)
77+
78+
session_id = share_session_result.id
79+
80+
# create_qr_code_result = create_share_qr_code(share_session_result.id)
81+
# get_share_session_result = get_share_session(share_session_result.id)
82+
# get_qr_code_result = get_share_qr_code(create_qr_code_result.id)
83+
84+
# Return Session ID JSON
85+
return json.dumps({"session_id": session_id})
86+
87+
@app.route("/create-qr-code")
88+
def create_qr_code():
89+
# Get query params - sessionId
90+
session_id = request.args.get('sessionId')
91+
digital_identity_client = DigitalIdentityClient(YOTI_CLIENT_SDK_ID, YOTI_KEY_FILE_PATH, YOTI_API_URL)
92+
93+
# Create QR Code
94+
create_qr_code_result = digital_identity_client.create_share_qr_code(session_id)
95+
96+
# Return QR Code ID and URI JSON
97+
return json.dumps({"qr_code_id": create_qr_code_result.id, "qr_code_uri": create_qr_code_result.uri})
98+
99+
@app.route("/render-qr-code")
100+
def render_qr_code():
101+
# Get query params - qrCodeUri
102+
qr_code_uri = request.args.get('qrCodeUri')
103+
# Make a POST request to the API to create a QR Code image
104+
url = "https://api.yoti.com/api/v1/qrcodes/image"
105+
payload = { "url": str(qr_code_uri) }
106+
headers = {
107+
"Accept": "image/png",
108+
"Content-Type": "application/json"
109+
}
110+
111+
response = requests.request("POST", url, json=payload, headers=headers)
112+
113+
# Return QR Code Image as PNG
114+
return Response(response.content, mimetype='image/png')
115+
116+
@app.route("/profile")
117+
def profile():
118+
# Get query params - receiptId
119+
receipt_id = request.args.get('receiptId')
120+
digital_identity_client = DigitalIdentityClient(YOTI_CLIENT_SDK_ID, YOTI_KEY_FILE_PATH, YOTI_API_URL)
121+
122+
share_receipt = digital_identity_client.get_share_receipt(receipt_id)
123+
age_over_verification = share_receipt.userContent.profile.find_age_over_verification(18)
124+
selfie = share_receipt.userContent.profile.selfie.value
125+
attribute_list = share_receipt.userContent.profile.attributes
126+
full_name = share_receipt.userContent.profile.full_name.value
127+
data = base64.b64encode(selfie).decode("utf-8")
128+
selfie_image = "data:{0};base64,{1}".format("image/jpeg", data)
129+
age_verified = age_over_verification.result
130+
131+
return render_template("profile.html", age_verified=age_verified, selfie=selfie, full_name=full_name, selfie_image=selfie_image, attribute_list = attribute_list)
132+
133+
if __name__ == "__main__":
134+
app.run(host="0.0.0.0", ssl_context="adhoc")
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
MIIEowIBAAKCAQEAxtXhHY0ZxiTWSGjC8Y0EHsXpmV3FPJo6Dne1skP9e7pe2i0I
3+
5tmvPVcQsOckrBjVP/H4G+Lzqtu7JfbD5BHZeqrec6PEITGBsrTAhcLjVQzUefN/
4+
mFkOinlOXBuPxMP5hZttFrNjqPjRhhlYrtQV2uOh/F/UGpqupgtJPKgF6mquDEGA
5+
lHAxCDMwwl+NtZgg1N5w7pDUJYc/cNwI8X0afTTLneCqTSD+t9dARVgcXpnJm1WK
6+
0XyJ4u6ENgN1fUcKPC3MP2isbTZe895dAVlvUH2ADD8qYfP8Nz8tcQ3DbXfjJC73
7+
hvuawmZIzotHqj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oRMU9kxuPkxRDMGe12QIBjZ3IQLzRV1yO0IFO0alvI+D2F17io+REasio
24+
pTaxAoGBANSMXb+sAnXgyu1hK/fOI5QlKNqBfK/PcwrI0nYwHzIqs5Xs5/k5NLH9
25+
yZyIcDrrk5DJDWJ63gA0WjSL5oHzo5IOHSAkcMc/H7L/4rNFdYNmjkMaTK3Ms4In
26+
xZcz7HaJ1Rxvh/y/lyDn27hsm30WpNfi6lcawBFHCTYdfyWIXj8P
27+
-----END RSA PRIVATE KEY-----
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
flask>=3.0.1
2+
python-dotenv>=1.0.1
3+
yoti>=2.15
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.11
3+
# by the following command:
4+
#
5+
# pip-compile --output-file=requirements.txt requirements.in
6+
#
7+
asn1==2.2.0
8+
# via yoti
9+
blinker==1.7.0
10+
# via flask
11+
certifi==2023.11.17
12+
# via requests
13+
cffi==1.16.0
14+
# via cryptography
15+
charset-normalizer==3.3.2
16+
# via requests
17+
click==8.1.7
18+
# via flask
19+
cryptography==42.0.1
20+
# via
21+
# pyopenssl
22+
# yoti
23+
deprecated==1.2.10
24+
# via yoti
25+
flask==3.0.1
26+
# via -r requirements.in
27+
future==0.18.3
28+
# via yoti
29+
idna==3.6
30+
# via requests
31+
iso8601==0.1.13
32+
# via yoti
33+
itsdangerous==2.1.2
34+
# via flask
35+
jinja2==3.1.3
36+
# via flask
37+
markupsafe==2.1.4
38+
# via
39+
# jinja2
40+
# werkzeug
41+
protobuf==3.20.1
42+
# via yoti
43+
pycparser==2.21
44+
# via cffi
45+
pyopenssl==24.0.0
46+
# via yoti
47+
python-dotenv==1.0.1
48+
# via -r requirements.in
49+
pytz==2022.1
50+
# via yoti
51+
requests==2.31.0
52+
# via yoti
53+
urllib3==2.1.0
54+
# via requests
55+
werkzeug==3.0.1
56+
# via flask
57+
wrapt==1.16.0
58+
# via deprecated
59+
yoti==2.14.2
60+
# via -r requirements.in
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from os import environ
2+
from os.path import dirname, join
3+
4+
from dotenv import load_dotenv
5+
6+
dotenv_path = join(dirname(__file__), ".env")
7+
load_dotenv(dotenv_path)
8+
9+
YOTI_CLIENT_SDK_ID = environ.get("YOTI_CLIENT_SDK_ID", None)
10+
YOTI_KEY_FILE_PATH = environ.get("YOTI_KEY_FILE_PATH", None)
11+
YOTI_API_URL = environ.get("YOTI_API_URL", "https://api.yoti.com/share")
12+
13+
if YOTI_CLIENT_SDK_ID is None or YOTI_KEY_FILE_PATH is None:
14+
raise ValueError("YOTI_CLIENT_SDK_ID or YOTI_KEY_FILE_PATH is None")
15+
16+
YOTI_APP_BASE_URL = environ.get("YOTI_APP_BASE_URL", "https://127.0.0.1:8000")
3.98 KB
Loading
8.61 KB
Loading

0 commit comments

Comments
 (0)