-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from getyoti/release-2.12.0
Release 2.12.0
- Loading branch information
Showing
65 changed files
with
1,839 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
### AML Example Project | ||
|
||
1. Rename the [.env.example](.env.example) file to `.env` and fill in the required configuration values | ||
1. Install requirements with `pip install -r requirements.txt` | ||
1. Run: `python app.py` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Doc Scan Example | ||
|
||
## Running the example | ||
|
||
1. Rename the [.env.example](.env.example) file to `.env` and fill in the required configuration values | ||
1. Install the dependencies with `pip install -r requirements.txt` | ||
1. Start the server `flask run --cert=adhoc` | ||
1. Visit `https://localhost:5000` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import base64 | ||
from io import BytesIO | ||
|
||
import yoti_python_sdk | ||
from filetype import filetype | ||
from flask import Flask, Response, render_template, request, send_file, session | ||
from yoti_python_sdk.doc_scan import ( | ||
DocScanClient, | ||
RequestedDocumentAuthenticityCheckBuilder, | ||
RequestedFaceMatchCheckBuilder, | ||
RequestedLivenessCheckBuilder, | ||
RequestedTextExtractionTaskBuilder, | ||
SdkConfigBuilder, | ||
SessionSpecBuilder, | ||
) | ||
from yoti_python_sdk.doc_scan.exception import DocScanException | ||
|
||
from .settings import YOTI_APP_BASE_URL, YOTI_CLIENT_SDK_ID, YOTI_KEY_FILE_PATH | ||
|
||
app = Flask(__name__) | ||
app.secret_key = "someSecretKey" | ||
|
||
|
||
def create_session(): | ||
""" | ||
Creates a Doc Scan session | ||
:return: the create session result | ||
:rtype: CreateSessionResult | ||
""" | ||
doc_scan_client = DocScanClient(YOTI_CLIENT_SDK_ID, YOTI_KEY_FILE_PATH) | ||
|
||
sdk_config = ( | ||
SdkConfigBuilder() | ||
.with_allows_camera_and_upload() | ||
.with_primary_colour("#2d9fff") | ||
.with_secondary_colour("#FFFFFF") | ||
.with_font_colour("#FFFFFF") | ||
.with_locale("en-GB") | ||
.with_preset_issuing_country("GBR") | ||
.with_success_url("{url}/success".format(url=YOTI_APP_BASE_URL)) | ||
.with_error_url("{url}/error".format(url=YOTI_APP_BASE_URL)) | ||
.build() | ||
) | ||
|
||
session_spec = ( | ||
SessionSpecBuilder() | ||
.with_client_session_token_ttl(600) | ||
.with_resources_ttl(90000) | ||
.with_user_tracking_id("some-user-tracking-id") | ||
.with_requested_check(RequestedDocumentAuthenticityCheckBuilder().build()) | ||
.with_requested_check( | ||
RequestedLivenessCheckBuilder() | ||
.for_zoom_liveness() | ||
.with_max_retries(1) | ||
.build() | ||
) | ||
.with_requested_check( | ||
RequestedFaceMatchCheckBuilder().with_manual_check_fallback().build() | ||
) | ||
.with_requested_task( | ||
RequestedTextExtractionTaskBuilder().with_manual_check_always().build() | ||
) | ||
.with_sdk_config(sdk_config) | ||
.build() | ||
) | ||
|
||
return doc_scan_client.create_session(session_spec) | ||
|
||
|
||
@app.route("/") | ||
def index(): | ||
try: | ||
result = create_session() | ||
except DocScanException as e: | ||
return render_template("error.html", error=e.text) | ||
|
||
session["doc_scan_session_id"] = result.session_id | ||
|
||
iframe_url = "{base_url}/web/index.html?sessionID={session_id}&sessionToken={session_token}".format( | ||
base_url=yoti_python_sdk.YOTI_DOC_SCAN_API_URL, | ||
session_id=result.session_id, | ||
session_token=result.client_session_token, | ||
) | ||
|
||
return render_template("index.html", iframe_url=iframe_url) | ||
|
||
|
||
@app.route("/success") | ||
def success(): | ||
doc_scan_client = DocScanClient(YOTI_CLIENT_SDK_ID, YOTI_KEY_FILE_PATH) | ||
|
||
session_id = session.get("doc_scan_session_id", None) | ||
|
||
try: | ||
session_result = doc_scan_client.get_session(session_id) | ||
except DocScanException as e: | ||
return render_template("error.html", error=e.text) | ||
|
||
return render_template("success.html", session_result=session_result) | ||
|
||
|
||
@app.route("/error") | ||
def error(): | ||
error_message = "An unknown error occurred" | ||
|
||
if request.args.get("yotiErrorCode", None) is not None: | ||
error_message = "Error Code: {}".format(request.args.get("yotiErrorCode")) | ||
|
||
return render_template("error.html", error=error_message) | ||
|
||
|
||
@app.route("/media") | ||
def media(): | ||
media_id = request.args.get("mediaId", None) | ||
if media_id is None: | ||
return Response(status=404) | ||
|
||
doc_scan_client = DocScanClient(YOTI_CLIENT_SDK_ID, YOTI_KEY_FILE_PATH) | ||
|
||
base64_req = request.args.get("base64", "0") | ||
|
||
session_id = session.get("doc_scan_session_id", None) | ||
if session_id is None: | ||
return Response("No session ID available", status=404) | ||
|
||
try: | ||
retrieved_media = doc_scan_client.get_media_content(session_id, media_id) | ||
except DocScanException as e: | ||
return render_template("error.html", error=e.text) | ||
|
||
if base64_req == "1" and retrieved_media.mime_type == "application/octet-stream": | ||
decoded = base64.b64decode(retrieved_media.content) | ||
info = filetype.guess(decoded) | ||
|
||
buffer = BytesIO() | ||
buffer.write(decoded) | ||
buffer.seek(0) | ||
|
||
return send_file( | ||
buffer, | ||
attachment_filename="media." + info.extension, | ||
mimetype=info.mime, | ||
as_attachment=True, | ||
) | ||
|
||
return Response( | ||
retrieved_media.content, content_type=retrieved_media.mime_type, status=200 | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
flask>=1.1.2 | ||
python-dotenv>=0.13.0 | ||
yoti>=2.11.2 | ||
filetype>=1.0.7 | ||
pyopenssl>=19.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# | ||
# This file is autogenerated by pip-compile | ||
# To update, run: | ||
# | ||
# pip-compile --output-file=requirements.txt requirements.in | ||
# | ||
asn1==2.2.0 # via yoti | ||
certifi==2020.4.5.1 # via requests | ||
cffi==1.14.0 # via cryptography | ||
chardet==3.0.4 # via requests | ||
click==7.1.2 # via flask | ||
cryptography==2.9.2 # via pyopenssl, yoti | ||
deprecated==1.2.6 # via yoti | ||
filetype==1.0.7 # via -r requirements.in | ||
flask==1.1.2 # via -r requirements.in | ||
future==0.18.2 # via yoti | ||
idna==2.9 # via requests | ||
iso8601==0.1.12 # via yoti | ||
itsdangerous==1.1.0 # via flask | ||
jinja2==2.11.2 # via flask | ||
markupsafe==1.1.1 # via jinja2 | ||
protobuf==3.11.3 # via yoti | ||
pycparser==2.20 # via cffi | ||
pyopenssl==19.1.0 # via -r requirements.in, yoti | ||
python-dotenv==0.13.0 # via -r requirements.in | ||
requests==2.23.0 # via yoti | ||
six==1.14.0 # via cryptography, protobuf, pyopenssl | ||
urllib3==1.25.9 # via requests | ||
werkzeug==1.0.1 # via flask | ||
wrapt==1.12.1 # via deprecated | ||
yoti==2.11.2 # via -r requirements.in | ||
|
||
# The following packages are considered to be unsafe in a requirements file: | ||
# setuptools |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
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) | ||
|
||
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://localhost:5000") |
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
body { | ||
padding-top: 4.5rem; | ||
} | ||
|
||
table td:first-child { | ||
width: 30%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{% include "layout/header.html" %} | ||
<div class="container"> | ||
<div class="row pt-4"> | ||
<div class="col"> | ||
<p class="alert alert-danger">{{ error }}</p> | ||
</div> | ||
</div> | ||
</div> | ||
{% include "layout/footer.html" %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% include "layout/header.html" %} | ||
<iframe style="border:none;" width="100%" height="750" allow="camera" src="{{ iframe_url }}"></iframe> | ||
{% include "layout/footer.html" %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" | ||
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" | ||
crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" | ||
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" | ||
crossorigin="anonymous"></script> | ||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" | ||
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" | ||
crossorigin="anonymous"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>Yoti Doc Scan</title> | ||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" | ||
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> | ||
<link rel="stylesheet" href="/static/style.css"> | ||
<link rel="icon" type="image/png" href="/static/images/favicon.png" /> | ||
</head> | ||
|
||
<body> | ||
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top"> | ||
<a href="/" class="navbar-brand"> | ||
<img src="/static/images/logo.svg" height="30" class="d-inline-block align-top mr-2"> | ||
Doc Scan | ||
</a> | ||
</nav> |
Oops, something went wrong.