Skip to content

Commit

Permalink
Merge pull request #193 from getyoti/release-2.12.0
Browse files Browse the repository at this point in the history
Release 2.12.0
  • Loading branch information
MrBurtyyy authored May 18, 2020
2 parents c98bf4c + c7dff81 commit d4ed035
Show file tree
Hide file tree
Showing 65 changed files with 1,839 additions and 43 deletions.
29 changes: 5 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,31 +247,12 @@ To run the Flask or Django container:

### Running Locally

1. Both example applications utilise the env variables described in [Configuration](#configuration), make sure they are accessible.
1. Ensure pip is up to date: `easy_install --upgrade pip`
1. Ensure setuptools and wheel are up to date: `python -m pip install --upgrade setuptools wheel`
#### Follow instructions in the README for each example:

#### Flask

1. Change directories to the Flask project: `cd examples/yoti_example_flask`
1. Install dependencies: `pip install -r requirements.txt`
1. Run `python app.py`
1. Navigate to https://localhost:5000

#### Django

1. You will need Python 3+ to run the Django example
1. Change directories to the Django project: `cd examples/yoti_example_django`
1. Install dependencies: `pip install -r requirements.txt`
1. Apply migrations before the first start by running: `python manage.py migrate`
1. Run: `python manage.py runsslserver 0.0.0.0:5000`
1. Navigate to https://localhost:5000

#### AML Example

1. Change directories to the AML folder: `cd examples/aml`
1. Install requirements with `pip install -r requirements.txt`
1. Run: `python app.py`
* [Profile - Django](examples/yoti_example_django)
* [Profile - Flask](examples/yoti_example_flask)
* [AML](examples/aml)
* [Doc Scan](examples/doc_scan)

## Running the Tests

Expand Down
5 changes: 5 additions & 0 deletions examples/aml/README.md
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`
3 changes: 3 additions & 0 deletions examples/doc_scan/.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/doc_scan/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pem
8 changes: 8 additions & 0 deletions examples/doc_scan/README.md
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 added examples/doc_scan/__init__.py
Empty file.
153 changes: 153 additions & 0 deletions examples/doc_scan/app.py
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()
5 changes: 5 additions & 0 deletions examples/doc_scan/requirements.in
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
34 changes: 34 additions & 0 deletions examples/doc_scan/requirements.txt
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
15 changes: 15 additions & 0 deletions examples/doc_scan/settings.py
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")
Binary file added examples/doc_scan/static/images/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/doc_scan/static/images/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions examples/doc_scan/static/style.css
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%;
}
9 changes: 9 additions & 0 deletions examples/doc_scan/templates/error.html
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" %}
3 changes: 3 additions & 0 deletions examples/doc_scan/templates/index.html
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" %}
12 changes: 12 additions & 0 deletions examples/doc_scan/templates/layout/footer.html
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>
18 changes: 18 additions & 0 deletions examples/doc_scan/templates/layout/header.html
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>
Loading

0 comments on commit d4ed035

Please sign in to comment.