django-onfido


Namedjango-onfido JSON
Version 0.11.2 PyPI version JSON
download
home_pagehttps://github.com/yunojuno/django-onfido
SummaryDjango app for integration with Onfido.
upload_time2017-05-09 08:56:23
maintainer
docs_urlNone
authorYunoJuno
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
Coveralis test coverage No Coveralis.
            .. image:: https://travis-ci.org/yunojuno/django-onfido.svg?branch=master
    :target: https://travis-ci.org/yunojuno/django-onfido

.. image:: https://badge.fury.io/py/django-onfido.svg
    :target: https://badge.fury.io/py/django-onfido

Django Onfido
==============

Django app for integration with the Onfido API (v2)

Background
----------

Onfido is an online identity verification service. It provides API access to a
range of tests (identity, right to work, criminal history, credit report). It
is assumed that you are only interested in this project because you are
already aware of what Onfido does, and so I won't repeat it here. If you want
to find out more, head over to their website.

If you *are* using Onfido, and you are using Django, then this project can be
used to manage Onfido checks against your existing Django users. It handles
the API interactions, as well as providing the callback webhooks required to
support live status updates.

Installation
------------

The project is available through PyPI as ``django-onfido``:

.. code::

    $ pip install django-onfido

And the main package itself is just ``onfido``:

.. code:: python

    >>> from onfido import api, models, views, urls, admin, signals, helpers, decorators

Usage
-----

The main use case is as follows:

1. Create an Onfido **Applicant** from your Django user:

.. code:: python

    >>> from django.contrib.auth import get_user_model
    >>> from onfido.helpers import create_applicant
    >>> user = get_user_model().objects.last()  # any old one will do
    >>> applicant = create_applicant(user)
    DEBUG Making POST request to https://api.onfido.com/v2/applicants
    DEBUG <Response [201]>
    DEBUG {u'first_name': u'hugo', u'last_name': u'rb', u'middle_name': None, ...}
    DEBUG Creating new Onfido applicant from JSON: {u'first_name': u'hugo', u'last_name': u'rb', ...}
    <Applicant id=a2c98eae-XXX user='hugo'>

2. Create your check + reports for the applicant:

.. code:: python

    >>> from onfido.helpers import create_check
    >>> create_check(applicant, 'standard', ['identity', 'right_to_work'])
    >>> assert Check.objects.count() == 1
    >>> assert Report.objects.count() == 2

This will create the **Check** and **Report** objects on Onfido, and store them locally as Django model objects.

3. Wait for callback events to update the status of reports and checks:

.. code:: shell

    DEBUG Received Onfido callback: {"payload":{...}}
    DEBUG Processing 'check.completed' action on check.bd8232c4-...

NB If you are using the callback functionality, you **must** set the ``ONFIDO_WEBHOOK_TOKEN``
property (see settings section below). The callback handler will force verification of the
X-Signature request header as specified in the `webhooks documentation <https://documentation.onfido.com/#webhooks>`_.

The raw JSON returned from the API for a given entity (``Applicant``,
``Check``, ``Report``) is stored on the model as the ``raw`` attribute, and
this can be parsed into the relevant model attributes. (Yes this does mean
duplication of data.) The core pattern for interaction with the API on a per-
object basis is a read-only fetch / pull pattern (analagous to git operations
of the same name). If you call the ``fetch`` method on an object, it will use
the ``href`` value in the raw JSON to fetch the latest data from the API and
parse it, but without saving the changes. If you want to update the object,
use the ``pull`` method instead.

The ``Report`` object is a special case, where the raw data from the API often
contains sensitive information that you may not wish to store locally
(passport numbers, Visa information, personal data). In order to get around
this, there is a ``scrub_report_data`` function that will remove certain
attributes of the raw data before it is parsed. By default this will remove
the ``breakdown`` and ``properties`` elements.

.. code:: python

    >>> check = Check.objects.last()
    >>> check.raw
    {
        "id": "c26f22d5-4903-401f-8a48-7b0211d03c1f",
        "created_at": "2016-10-15T19:05:50Z",
        "status": "awaiting_applicant",
        "type": "standard",
        "result": "clear",
        "href": "applicants/123/checks/456"
    }
    >>> check.fetch()  # fetch and parse the latest raw data
    >>> check.pull()  # calls fetch and then saves the object

There is a management command ``onfido_sync`` which can be used to ``pull`` all the objects
in a queryset. It takes a single positional arg - 'applicant', check' or 'report', and has two
options - ``--filter`` and ``--exclude`` - both of which take multiple space-separated
args which can be used to manage the queryset that is used.

Examples:

.. code:: bash

    $ ./manage.py onfido_sync check
    $ ./manage.py onfido_sync report
    $ ./manage.py onfido_sync check --filter complete
    $ ./manage.py onfido_sync check --exclude complete

Settings
--------

The following settings can be specified as environment settings or within the Django settings.

* ``ONFIDO_API_KEY``: your API key, found under **setting** in your Onfido account.
* ``ONFIDO_WEBHOOK_TOKEN``: (optional) the Onfido webhook callback token - required if using webhooks.

The following settings can be specified in the Django settings:

* ``ONFIDO_LOG_EVENTS``: (optional) if True then callback events from the API will also be recorded as ``Event`` objects. Defaults to False.
* ``ONFIDO_REPORT_SCRUBBER``: (optional) a function that is used to scrub sensitive data from ``Report`` objects. The default implementation will remove **breakdown** and **properties**.

Tests
-----

The project has pretty good test coverage (>90%) and the tests themselves run through ``tox``.

.. code::

    $ pip install tox
    $ tox

If you want to run the tests manually, make sure you install the requirements, and Django.

.. code::

    $ pip install -r requirements.txt
    $ pip install django==1.8  # your version goes here
    $ python manage.py test onfido.tests

If you are hacking on the project, please keep coverage up.

Contributing
------------

Standard GH rules apply: clone the repo to your own account, create a branch,
make sure you update the tests, and submit a pull request.

Status
------

This project is very early in its development. We are using it at YunoJuno,
but 'caveat emptor'. It currently only supports 'standard' checks, and has
very patchy support for the full API. It does what we need it to do right now,
and we will extend it as we evolve. If you need or want additional features,
get involved :-).

            

Raw data

            {
    "maintainer": "", 
    "docs_url": null, 
    "requires_python": "", 
    "maintainer_email": "", 
    "cheesecake_code_kwalitee_id": null, 
    "coveralis": false, 
    "keywords": "", 
    "upload_time": "2017-05-09 08:56:23", 
    "author": "YunoJuno", 
    "home_page": "https://github.com/yunojuno/django-onfido", 
    "github_user": "yunojuno", 
    "download_url": "https://pypi.python.org/packages/77/11/6a98cc79763227c97710f917125e8d97a89438169975d7278bc072479088/django-onfido-0.11.2.tar.gz", 
    "platform": "", 
    "version": "0.11.2", 
    "cheesecake_documentation_id": null, 
    "description": ".. image:: https://travis-ci.org/yunojuno/django-onfido.svg?branch=master\n    :target: https://travis-ci.org/yunojuno/django-onfido\n\n.. image:: https://badge.fury.io/py/django-onfido.svg\n    :target: https://badge.fury.io/py/django-onfido\n\nDjango Onfido\n==============\n\nDjango app for integration with the Onfido API (v2)\n\nBackground\n----------\n\nOnfido is an online identity verification service. It provides API access to a\nrange of tests (identity, right to work, criminal history, credit report). It\nis assumed that you are only interested in this project because you are\nalready aware of what Onfido does, and so I won't repeat it here. If you want\nto find out more, head over to their website.\n\nIf you *are* using Onfido, and you are using Django, then this project can be\nused to manage Onfido checks against your existing Django users. It handles\nthe API interactions, as well as providing the callback webhooks required to\nsupport live status updates.\n\nInstallation\n------------\n\nThe project is available through PyPI as ``django-onfido``:\n\n.. code::\n\n    $ pip install django-onfido\n\nAnd the main package itself is just ``onfido``:\n\n.. code:: python\n\n    >>> from onfido import api, models, views, urls, admin, signals, helpers, decorators\n\nUsage\n-----\n\nThe main use case is as follows:\n\n1. Create an Onfido **Applicant** from your Django user:\n\n.. code:: python\n\n    >>> from django.contrib.auth import get_user_model\n    >>> from onfido.helpers import create_applicant\n    >>> user = get_user_model().objects.last()  # any old one will do\n    >>> applicant = create_applicant(user)\n    DEBUG Making POST request to https://api.onfido.com/v2/applicants\n    DEBUG <Response [201]>\n    DEBUG {u'first_name': u'hugo', u'last_name': u'rb', u'middle_name': None, ...}\n    DEBUG Creating new Onfido applicant from JSON: {u'first_name': u'hugo', u'last_name': u'rb', ...}\n    <Applicant id=a2c98eae-XXX user='hugo'>\n\n2. Create your check + reports for the applicant:\n\n.. code:: python\n\n    >>> from onfido.helpers import create_check\n    >>> create_check(applicant, 'standard', ['identity', 'right_to_work'])\n    >>> assert Check.objects.count() == 1\n    >>> assert Report.objects.count() == 2\n\nThis will create the **Check** and **Report** objects on Onfido, and store them locally as Django model objects.\n\n3. Wait for callback events to update the status of reports and checks:\n\n.. code:: shell\n\n    DEBUG Received Onfido callback: {\"payload\":{...}}\n    DEBUG Processing 'check.completed' action on check.bd8232c4-...\n\nNB If you are using the callback functionality, you **must** set the ``ONFIDO_WEBHOOK_TOKEN``\nproperty (see settings section below). The callback handler will force verification of the\nX-Signature request header as specified in the `webhooks documentation <https://documentation.onfido.com/#webhooks>`_.\n\nThe raw JSON returned from the API for a given entity (``Applicant``,\n``Check``, ``Report``) is stored on the model as the ``raw`` attribute, and\nthis can be parsed into the relevant model attributes. (Yes this does mean\nduplication of data.) The core pattern for interaction with the API on a per-\nobject basis is a read-only fetch / pull pattern (analagous to git operations\nof the same name). If you call the ``fetch`` method on an object, it will use\nthe ``href`` value in the raw JSON to fetch the latest data from the API and\nparse it, but without saving the changes. If you want to update the object,\nuse the ``pull`` method instead.\n\nThe ``Report`` object is a special case, where the raw data from the API often\ncontains sensitive information that you may not wish to store locally\n(passport numbers, Visa information, personal data). In order to get around\nthis, there is a ``scrub_report_data`` function that will remove certain\nattributes of the raw data before it is parsed. By default this will remove\nthe ``breakdown`` and ``properties`` elements.\n\n.. code:: python\n\n    >>> check = Check.objects.last()\n    >>> check.raw\n    {\n        \"id\": \"c26f22d5-4903-401f-8a48-7b0211d03c1f\",\n        \"created_at\": \"2016-10-15T19:05:50Z\",\n        \"status\": \"awaiting_applicant\",\n        \"type\": \"standard\",\n        \"result\": \"clear\",\n        \"href\": \"applicants/123/checks/456\"\n    }\n    >>> check.fetch()  # fetch and parse the latest raw data\n    >>> check.pull()  # calls fetch and then saves the object\n\nThere is a management command ``onfido_sync`` which can be used to ``pull`` all the objects\nin a queryset. It takes a single positional arg - 'applicant', check' or 'report', and has two\noptions - ``--filter`` and ``--exclude`` - both of which take multiple space-separated\nargs which can be used to manage the queryset that is used.\n\nExamples:\n\n.. code:: bash\n\n    $ ./manage.py onfido_sync check\n    $ ./manage.py onfido_sync report\n    $ ./manage.py onfido_sync check --filter complete\n    $ ./manage.py onfido_sync check --exclude complete\n\nSettings\n--------\n\nThe following settings can be specified as environment settings or within the Django settings.\n\n* ``ONFIDO_API_KEY``: your API key, found under **setting** in your Onfido account.\n* ``ONFIDO_WEBHOOK_TOKEN``: (optional) the Onfido webhook callback token - required if using webhooks.\n\nThe following settings can be specified in the Django settings:\n\n* ``ONFIDO_LOG_EVENTS``: (optional) if True then callback events from the API will also be recorded as ``Event`` objects. Defaults to False.\n* ``ONFIDO_REPORT_SCRUBBER``: (optional) a function that is used to scrub sensitive data from ``Report`` objects. The default implementation will remove **breakdown** and **properties**.\n\nTests\n-----\n\nThe project has pretty good test coverage (>90%) and the tests themselves run through ``tox``.\n\n.. code::\n\n    $ pip install tox\n    $ tox\n\nIf you want to run the tests manually, make sure you install the requirements, and Django.\n\n.. code::\n\n    $ pip install -r requirements.txt\n    $ pip install django==1.8  # your version goes here\n    $ python manage.py test onfido.tests\n\nIf you are hacking on the project, please keep coverage up.\n\nContributing\n------------\n\nStandard GH rules apply: clone the repo to your own account, create a branch,\nmake sure you update the tests, and submit a pull request.\n\nStatus\n------\n\nThis project is very early in its development. We are using it at YunoJuno,\nbut 'caveat emptor'. It currently only supports 'standard' checks, and has\nvery patchy support for the full API. It does what we need it to do right now,\nand we will extend it as we evolve. If you need or want additional features,\nget involved :-).\n", 
    "tox": true, 
    "lcname": "django-onfido", 
    "bugtrack_url": null, 
    "github": true, 
    "name": "django-onfido", 
    "license": "MIT", 
    "travis_ci": true, 
    "github_project": "django-onfido", 
    "summary": "Django app for integration with Onfido.", 
    "split_keywords": [], 
    "author_email": "code@yunojuno.com", 
    "urls": [
        {
            "has_sig": false, 
            "upload_time": "2017-05-09T08:56:23", 
            "comment_text": "", 
            "python_version": "source", 
            "url": "https://pypi.python.org/packages/77/11/6a98cc79763227c97710f917125e8d97a89438169975d7278bc072479088/django-onfido-0.11.2.tar.gz", 
            "md5_digest": "27cbc66a6d7e4fd243ec788ca52c720c", 
            "downloads": 0, 
            "filename": "django-onfido-0.11.2.tar.gz", 
            "packagetype": "sdist", 
            "path": "77/11/6a98cc79763227c97710f917125e8d97a89438169975d7278bc072479088/django-onfido-0.11.2.tar.gz", 
            "size": 30116
        }, 
        {
            "has_sig": false, 
            "upload_time": "2017-05-09T08:56:26", 
            "comment_text": "", 
            "python_version": "2.7", 
            "url": "https://pypi.python.org/packages/23/06/ed23bd8bb4ec0cb4b59700d0e2b99eb01640f69a1dd4b53dba51aac355cc/django_onfido-0.11.2-py2-none-any.whl", 
            "md5_digest": "d12e2600e35a016d88fb7bd8dc5bd59e", 
            "downloads": 0, 
            "filename": "django_onfido-0.11.2-py2-none-any.whl", 
            "packagetype": "bdist_wheel", 
            "path": "23/06/ed23bd8bb4ec0cb4b59700d0e2b99eb01640f69a1dd4b53dba51aac355cc/django_onfido-0.11.2-py2-none-any.whl", 
            "size": 42811
        }
    ], 
    "_id": null, 
    "cheesecake_installability_id": null
}