Skip to content

Commit 483b9ad

Browse files
authored
Merge pull request #14 from lampkicking/release/0-1-0
Release/0-1-0
2 parents a465568 + 3d25dbc commit 483b9ad

Some content is hidden

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

55 files changed

+1921
-0
lines changed

.coveragerc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[run]
2+
omit=yoti/tests/*

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var/
2323
*.egg-info/
2424
.installed.cfg
2525
*.egg
26+
MANIFEST
2627

2728
# PyInstaller
2829
# Usually these files are written by a python script from a template
@@ -87,3 +88,7 @@ ENV/
8788

8889
# Rope project settings
8990
.ropeproject
91+
92+
# IDE
93+
.idea/
94+
*.un~

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Change Log #
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
## [0.1.0] - 2015-10-2X
9+
### Added
10+
- Initial SDK release

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Yoti Ltd
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include yoti/tests/fixtures/*
2+
recursive-include yoti/protobuf/v1/definitions *.proto

README.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Yoti Python SDK #
2+
3+
This package integrates your Python back-end with [Yoti](https://www.yoti.com/) allowing you to
4+
securely verify users' identities.
5+
6+
## Example ##
7+
8+
from yoti import Client
9+
10+
@app.route('/callback')
11+
def callback():
12+
client = Client(YOTI_CLIENT_SDK_ID, YOTI_KEY_FILE_PATH)
13+
activity_details = client.get_activity_details(request.args['token'])
14+
return activity_details.user_profile
15+
16+
For more details and working [Flask](http://flask.pocoo.org/) and [Django](https://www.djangoproject.com/)
17+
applications see [examples/](https://github.com/lampkicking/yoti-sdk-server-python/tree/development/examples).
18+
19+
20+
## The Flow ##
21+
22+
Assuming you created an application and chose `/callback` as your application's callback on [Yoti Dashboard](https://www.yoti.com/dashboard/),
23+
this endpoint will receive a `token` from Yoti API each time user wishes to share information with you (see the example above).
24+
This token, encrypted with the private key from `.PEM` container, will be used to send a request to Yoti
25+
for user's profile details. That's all folks!
26+
27+
For details see [Yoti Developers Docs](https://www.yoti.com/developers/).
28+
29+
## Installation ##
30+
31+
$ pip install yoti
32+
33+
This SDK works with Python 2.6+ and Python 3.3+ .
34+
35+
## Configuration ##
36+
37+
After creating your application on the [Yoti Dashboard](https://www.yoti.com/dashboard/), you need to download
38+
the `.PEM` key and save it *outside* the repo (keep it private).
39+
40+
The following env variables are then required for the SDK to work:
41+
42+
* `YOTI_CLIENT_SDK_ID` - found on the Integrations settings page
43+
* `YOTI_KEY_FILE_PATH` - the full path to your private key downloaded from the Keys settings page (e.g. /home/user/.ssh/access-security.pem)
44+
45+
The following env variables are additionally used to configure your backend:
46+
47+
* `YOTI_APPLICATION_ID` - found on the Integrations settings page, used to configure the [Yoti Login Button](https://www.yoti.com/developers/#login-button-setup)
48+
* `YOTI_VERIFICATION_KEY` - found on the Integrations settings page -> Callback URL -> VERIFY, used to verify your back-end callback
49+
50+
## Examples ##
51+
52+
Both example applications utilise the env variables described above, make sure they are accessible.
53+
* Installing dependencies: `pip install -e .[examples]`
54+
55+
56+
### Flask ###
57+
58+
* Run `python examples/yoti_example_flask/app.py`
59+
60+
### Django ###
61+
62+
1. Apply migrations before the first start by running:<br>
63+
`python examples/yoti_example_django/manage.py migrate`
64+
1. Run: `python examples/yoti_example_django/manage.py runserver 0.0.0.0:5000`
65+
66+
## Executing tests ##
67+
68+
1. Install dependencies: `pip install -r requirements.txt`
69+
1. Install the SDK: `python setup.py develop`
70+
1. Execute in the main project dir: `py.test`
71+
1. To execute integration tests run: `py.test -c pytest_integration.ini`
72+
73+
### Testing on multiple Python versions ###
74+
75+
Tests executed using [py.test](http://doc.pytest.org/en/latest/) use your default/virtualenv's Python interpreter.
76+
Testing multiple versions of Python requires them to be installed and accessible on your system.
77+
One tool to do just this is [pyenv](https://github.com/yyuu/pyenv)
78+
79+
1. Install `pyenv`
80+
1. Install Python interpreters you want to test with, e.g. `pyenv install 2.6.9`
81+
1. Install project dependencies: `pip install -r requirements.txt`
82+
1. Execute in the main project dir: `tox`
83+
1. In order to execute integration tests run: `tox pytest_integration.ini`
84+
85+
You can choose a subset of interpreters to test with by running `tox -e <testenv_version>`.
86+
For a list of `<testenv_versions>` see `tox.ini`. Example: `tox -e py26` would run the
87+
test suite on Python 2.6 (2.6.9 in our case, as installed with `pyenv`).
88+
89+
To install all the Python versions this SDK has been tested against run:
90+
91+
$ for version in 2.6.9 2.7.12 3.3.6 3.4.5 3.5.2 3.6.0b1; do pyenv install $version; done
92+
93+
activate the installed interpreters (execute in this directory):
94+
95+
$ pyenv local 2.6.9 2.7.12 3.3.6 3.4.5 3.5.2 3.6.0b1
96+
97+
run the tests:
98+
99+
$ tox
100+
101+
#### Tox Common Issues ####
102+
103+
Supporting multiple Python versions with dependencies, often requiring compilation, is not without issues.
104+
105+
For Python versions that do not provide binary wheels for `cryptography`, it
106+
will have to be compiled. This will be done automatically, however you may
107+
need to install development headers of `openssl`.
108+
109+
##### On Debian-based systems #####
110+
111+
Install `openssl` headers with `apt-get install openssl-dev`
112+
113+
##### On macOS #####
114+
115+
Install `openssl` headers using [homebrew](http://brew.sh/): `brew install openssl`
116+
117+
Install xcode command line tools so we have access to a C compiler and common libs:
118+
119+
xcode-select --install
120+
121+
See [building cryptography on OS X](https://cryptography.io/en/latest/installation/#building-cryptography-on-os-x)
122+
123+
124+
For Python 2.6 and 2.7 you *might* have to install them via `pyenv` with specific unicode code point settings:
125+
126+
PYTHON_CONFIGURE_OPTS="--enable-unicode=ucs2" pyenv install <python version>
127+
128+
to avoid `cffi` errors related to unicode see: [cffi ucs2 vs ucs4](http://cffi.readthedocs.io/en/latest/installation.html#linux-and-os-x-ucs2-versus-ucs4)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yoti_example.settings")
7+
try:
8+
from django.core.management import execute_from_command_line
9+
except ImportError:
10+
# The above import may fail for some other reason. Ensure that the
11+
# issue is really that Django is missing to avoid masking other
12+
# exceptions on Python 2.
13+
try:
14+
import django
15+
except ImportError:
16+
raise ImportError(
17+
"Couldn't import Django. Are you sure it's installed and "
18+
"available on your PYTHONPATH environment variable? Did you "
19+
"forget to activate a virtual environment?"
20+
)
21+
raise
22+
execute_from_command_line(sys.argv)

examples/yoti_example_django/yoti_example/__init__.py

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from os import environ
2+
3+
YOTI_APPLICATION_ID = environ.get('YOTI_APPLICATION_ID')
4+
YOTI_CLIENT_SDK_ID = environ.get('YOTI_CLIENT_SDK_ID')
5+
YOTI_FULL_KEY_FILE_PATH = environ.get('YOTI_KEY_FILE_PATH')
6+
YOTI_VERIFICATION_KEY = environ.get('YOTI_VERIFICATION_KEY')
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
"""
2+
Django settings for yoti_example project.
3+
4+
Generated by 'django-admin startproject' using Django 1.10.2.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/1.10/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/1.10/ref/settings/
11+
"""
12+
13+
import os
14+
15+
from os.path import join
16+
17+
# Build paths inside the project like this: join(BASE_DIR, ...)
18+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
19+
20+
21+
# Quick-start development settings - unsuitable for production
22+
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
23+
24+
# SECURITY WARNING: keep the secret key used in production secret!
25+
SECRET_KEY = 'p3dh1cx&ey8oesy-nj_md-ouo75xi548m22j^zrv((d1@k%%3!'
26+
27+
# SECURITY WARNING: don't run with debug turned on in production!
28+
DEBUG = True
29+
30+
ALLOWED_HOSTS = []
31+
32+
33+
# Application definition
34+
35+
INSTALLED_APPS = [
36+
'django.contrib.admin',
37+
'django.contrib.auth',
38+
'django.contrib.contenttypes',
39+
'django.contrib.sessions',
40+
'django.contrib.messages',
41+
'django.contrib.staticfiles',
42+
]
43+
44+
MIDDLEWARE = [
45+
'django.middleware.security.SecurityMiddleware',
46+
'django.contrib.sessions.middleware.SessionMiddleware',
47+
'django.middleware.common.CommonMiddleware',
48+
'django.middleware.csrf.CsrfViewMiddleware',
49+
'django.contrib.auth.middleware.AuthenticationMiddleware',
50+
'django.contrib.messages.middleware.MessageMiddleware',
51+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
52+
]
53+
54+
ROOT_URLCONF = 'yoti_example.urls'
55+
56+
TEMPLATES = [
57+
{
58+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
59+
'DIRS': [join(BASE_DIR, 'yoti_example/templates')],
60+
'APP_DIRS': True,
61+
'OPTIONS': {
62+
'context_processors': [
63+
'django.template.context_processors.debug',
64+
'django.template.context_processors.request',
65+
'django.contrib.auth.context_processors.auth',
66+
'django.contrib.messages.context_processors.messages',
67+
],
68+
},
69+
},
70+
]
71+
72+
WSGI_APPLICATION = 'yoti_example.wsgi.application'
73+
74+
75+
# Database
76+
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
77+
78+
DATABASES = {
79+
'default': {
80+
'ENGINE': 'django.db.backends.sqlite3',
81+
'NAME': join(BASE_DIR, 'db.sqlite3'),
82+
}
83+
}
84+
85+
86+
# Password validation
87+
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
88+
89+
AUTH_PASSWORD_VALIDATORS = [
90+
{
91+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
92+
},
93+
{
94+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
95+
},
96+
{
97+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
98+
},
99+
{
100+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
101+
},
102+
]
103+
104+
105+
# Internationalization
106+
# https://docs.djangoproject.com/en/1.10/topics/i18n/
107+
108+
LANGUAGE_CODE = 'en-us'
109+
110+
TIME_ZONE = 'UTC'
111+
112+
USE_I18N = True
113+
114+
USE_L10N = True
115+
116+
USE_TZ = True
117+
118+
119+
# Static files (CSS, JavaScript, Images)
120+
# https://docs.djangoproject.com/en/1.10/howto/static-files/
121+
122+
STATIC_URL = '/static/'

0 commit comments

Comments
 (0)