|
| 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) |
0 commit comments