Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sdk 2242 digital identity share v2 #415

Open
wants to merge 12 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- run: pip install -U setuptools
- run: pip install -U setuptools wheel

- run: pip install -r requirements.txt

Expand All @@ -48,7 +48,7 @@ jobs:

- run: pushd examples/aml && pip install -r requirements.txt && popd

- run: pushd examples/yoti_example_django && pip install --upgrade pip && pip install -r requirements.txt && popd
- run: pushd examples/yoti_example_django && pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt && popd

- run: pushd examples/yoti_example_flask && pip install -r requirements.txt && popd

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ examples/yoti_example_flask/static/YotiSelfie.jpg
#.pem files for examples
examples/yoti_example_django/*.pem
examples/yoti_example_flask/*.pem
examples/digitalidentity/*.pem

.scannerwork
.venv/
3 changes: 3 additions & 0 deletions examples/digitalidentity/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Required Keys
YOTI_CLIENT_SDK_ID=yourClientSdkId
YOTI_KEY_FILE_PATH=yourKeyFilePath
1 change: 1 addition & 0 deletions examples/digitalidentity/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pem
11 changes: 11 additions & 0 deletions examples/digitalidentity/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Yoti Share v2 Python Example

## Running the example project

1. Rename the [.env.example](.env.example) file to `.env` and fill in the required configuration values
2. Add your SDK ID to the [templates/index.html](templates/index.html) file
3. Create a virtual environment with `python3 -m venv .venv`
4. Active the environment `. .venv/bin/activate`
5. Install the dependencies with `pip install -r requirements.txt`
6. Start the server `flask run --port 8000`
7. Visit `http://127.0.0.1:8000`
Empty file.
134 changes: 134 additions & 0 deletions examples/digitalidentity/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to change URL to https://example.com/webhook-url.

"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")
1 change: 1 addition & 0 deletions examples/digitalidentity/keys/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pem
3 changes: 3 additions & 0 deletions examples/digitalidentity/requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
flask>=3.0.1
python-dotenv>=1.0.1
yoti>=2.15
60 changes: 60 additions & 0 deletions examples/digitalidentity/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --output-file=requirements.txt requirements.in
#
asn1==2.2.0
# via yoti
blinker==1.7.0
# via flask
certifi==2023.11.17
# via requests
cffi==1.16.0
# via cryptography
charset-normalizer==3.3.2
# via requests
click==8.1.7
# via flask
cryptography==42.0.1
# via
# pyopenssl
# yoti
deprecated==1.2.10
# via yoti
flask==3.0.1
# via -r requirements.in
future==0.18.3
# via yoti
idna==3.6
# via requests
iso8601==0.1.13
# via yoti
itsdangerous==2.1.2
# via flask
jinja2==3.1.3
# via flask
markupsafe==2.1.4
# via
# jinja2
# werkzeug
protobuf==3.20.1
# via yoti
pycparser==2.21
# via cffi
pyopenssl==24.0.0
# via yoti
python-dotenv==1.0.1
# via -r requirements.in
pytz==2022.1
# via yoti
requests==2.31.0
# via yoti
urllib3==2.1.0
# via requests
werkzeug==3.0.1
# via flask
wrapt==1.16.0
# via deprecated
yoti==2.15
# via -r requirements.in
16 changes: 16 additions & 0 deletions examples/digitalidentity/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from os import environ
from os.path import dirname, join

from dotenv import load_dotenv

dotenv_path = join(dirname(__file__), ".env")
load_dotenv(dotenv_path)

YOTI_CLIENT_SDK_ID = environ.get("YOTI_CLIENT_SDK_ID", None)
YOTI_KEY_FILE_PATH = environ.get("YOTI_KEY_FILE_PATH", None)
YOTI_API_URL = environ.get("YOTI_API_URL", "https://api.yoti.com/share")

if YOTI_CLIENT_SDK_ID is None or YOTI_KEY_FILE_PATH is None:
raise ValueError("YOTI_CLIENT_SDK_ID or YOTI_KEY_FILE_PATH is None")

YOTI_APP_BASE_URL = environ.get("YOTI_APP_BASE_URL", "https://127.0.0.1:8000")
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/digitalidentity/static/assets/icons/address.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions examples/digitalidentity/static/assets/icons/calendar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/digitalidentity/static/assets/icons/document.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions examples/digitalidentity/static/assets/icons/email.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions examples/digitalidentity/static/assets/icons/gender.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/digitalidentity/static/assets/icons/nationality.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/digitalidentity/static/assets/icons/phone.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/digitalidentity/static/assets/icons/profile.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions examples/digitalidentity/static/assets/icons/verified.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/digitalidentity/static/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading