|
| 1 | +# Django Yoti # |
| 2 | + |
| 3 | +Description |
| 4 | + |
| 5 | +## Plugin configuration ## |
| 6 | +### General settings ### |
| 7 | + |
| 8 | +* First you need to add `django_yoti` plugin to your INSTALLED_APPS setting like this: |
| 9 | +```python |
| 10 | +# your_django_project/settings.py |
| 11 | + |
| 12 | +... |
| 13 | + |
| 14 | +INSTALLED_APPS = [ |
| 15 | + ... |
| 16 | + 'django_yoti', |
| 17 | +] |
| 18 | +``` |
| 19 | + |
| 20 | +* In order to use context tags inside your template (`{{ yoti_site_verification }}`, `{{ yoti_login_button_*}}`), |
| 21 | +you should include `django_yoti`'s context processors into your templates configuration like this: |
| 22 | +```python |
| 23 | +# your_django_project/settings.py |
| 24 | + |
| 25 | +... |
| 26 | + |
| 27 | +TEMPLATES = [ |
| 28 | + { |
| 29 | + ... |
| 30 | + 'OPTIONS': { |
| 31 | + 'context_processors': [ |
| 32 | + ... |
| 33 | + 'django_yoti.context_processors.yoti_context', |
| 34 | + ], |
| 35 | + }, |
| 36 | + }, |
| 37 | +] |
| 38 | +``` |
| 39 | + |
| 40 | +* And then use the following settings to configure the plugin: |
| 41 | + |
| 42 | + |
| 43 | +```python |
| 44 | +# your_django_project/settings.py |
| 45 | + |
| 46 | +... |
| 47 | + |
| 48 | +YOTI = { |
| 49 | + 'YOTI_APPLICATION_ID': '...', |
| 50 | + 'YOTI_CLIENT_SDK_ID': '...', |
| 51 | + 'YOTI_KEY_FILE_PATH': '...', |
| 52 | + 'YOTI_VERIFICATION_KEY': '...', |
| 53 | + ... |
| 54 | +} |
| 55 | +``` |
| 56 | +* **`YOTI_APPLICATION_ID`** - **required**, *can be also set by env variable with the same name*<br> |
| 57 | +Your Yoti application's ID, found under the `INTEGRATIONS` tab of your |
| 58 | +Yoti application's settings page ([Yoti Dashboard](https://www.yoti.com/dashboard/)).<br> |
| 59 | +It is used to configure the [Yoti Login Button](https://www.yoti.com/developers/#login-button-setup).<br> |
| 60 | +Example: `ca84f68b-1b48-458b-96bf-963868edc8b6` |
| 61 | + |
| 62 | +* **`YOTI_CLIENT_SDK_ID`** - **required**, *can be also set by env variable with the same name*<br> |
| 63 | +Your Yoti application's SDK ID, found under the `INTEGRATIONS` tab of your |
| 64 | +Yoti application's settings page ([Yoti Dashboard](https://www.yoti.com/dashboard/)).<br> |
| 65 | +Example: `39aef70a-89d6-4644-a687-b3e891613da6` |
| 66 | + |
| 67 | +* **`YOTI_KEY_FILE_PATH`** - **required**, *can be also set by env variable with the same name*<br> |
| 68 | +The full path to your private key downloaded from your Yoti application's |
| 69 | +settings page under the `KEYS` tab ([Yoti Dashboard](https://www.yoti.com/dashboard/)).<br> |
| 70 | +Example: `/home/user/.ssh/access-security.pem` |
| 71 | + |
| 72 | +* **`YOTI_VERIFICATION_KEY`** - *can be also set by env variable with the same name*<br> |
| 73 | +A key, used to verify your callback URL. Can be found under the |
| 74 | +`INTEGRATIONS` tab of your Yoti application's settings page (Callback URL -> VERIFY).<br> |
| 75 | +Example: `b14886f972d0c717` |
| 76 | + |
| 77 | + |
| 78 | +### Endpoints configuration ### |
| 79 | + |
| 80 | +`django_yoti` plugin provides some default endpoints: |
| 81 | +```python |
| 82 | +# django_yoti/urls.py |
| 83 | + |
| 84 | +urlpatterns = [ |
| 85 | + url(r'^auth/', views.auth, name='yoti_auth'), |
| 86 | + url(r'^login/', views.login, name='yoti_login'), |
| 87 | + url(r'^profile/', views.profile, name='yoti_profile') |
| 88 | +] |
| 89 | +``` |
| 90 | +`yoti_auth` url is used for receiving token via callback and should'nt be changed.<br> |
| 91 | +The last two URLs are examples and can be overridden by the following settings: |
| 92 | + |
| 93 | +```python |
| 94 | +# your_django_project/settings.py |
| 95 | + |
| 96 | +... |
| 97 | + |
| 98 | +YOTI = { |
| 99 | + ... |
| 100 | + 'YOTI_LOGIN_VIEW': '...', |
| 101 | + 'YOTI_REDIRECT_TO': '...', |
| 102 | + 'YOTI_LOGIN_BUTTON_LABEL': '...', |
| 103 | +} |
| 104 | +``` |
| 105 | +* **`YOTI_LOGIN_VIEW`**<br> |
| 106 | +If *not* authenticated user is trying to access a view with |
| 107 | +`@yoti_authenticated` decorator, he/she will be redirected to this view. |
| 108 | +Example: `login`<br> |
| 109 | +In this case you should have something like this in your project's `urls.py` file: |
| 110 | +```python |
| 111 | +urlpatterns = [ |
| 112 | + ... |
| 113 | + url(r'^login/', views.login, name='login'), |
| 114 | + ... |
| 115 | +] |
| 116 | +``` |
| 117 | +Default value: `yoti_login` (with `/yoti/login/` URL) |
| 118 | + |
| 119 | +* **`YOTI_REDIRECT_TO`**<br> |
| 120 | +View name to which user is redirected after successful authentication.<br> |
| 121 | +Example: `profile`<br> |
| 122 | +In this case you should have something like this in your project's `urls.py` file: |
| 123 | +```python |
| 124 | +urlpatterns = [ |
| 125 | + ... |
| 126 | + url(r'^profile/', views.profile, name='profile'), |
| 127 | + ... |
| 128 | +] |
| 129 | +``` |
| 130 | +Default value: `yoti_profile` (with `/yoti/profile/` URL |
| 131 | + |
| 132 | +<br> |
| 133 | + |
| 134 | +In order to use `django_yoti` plugin in your project, you should include |
| 135 | +the plugin's endpoints in your project's `urls.py` file: |
| 136 | +```python |
| 137 | +# your_django_project/urls.py |
| 138 | + |
| 139 | + ... |
| 140 | + |
| 141 | +urlpatterns = [ |
| 142 | + ... |
| 143 | + url(r'^yoti/', include('django_yoti.urls')), |
| 144 | + ... |
| 145 | +] |
| 146 | +``` |
| 147 | + |
| 148 | +### Yoti application configuration ### |
| 149 | + |
| 150 | +Your Yoti application's callback URL should point to `your_site.com/yoti/auth`.<br> |
| 151 | +If you want to add a verification tag into any page (other than `/yoti/auth/`), |
| 152 | +you can use a `{{ yoti_site_verification }}` tag inside 'head' tag of that page. |
| 153 | + |
| 154 | +## Using plugin ## |
| 155 | + |
| 156 | +1. First you need to add a login button to some of your view's templates. |
| 157 | +- You can do it by using one of the predefined login buttons: |
| 158 | +``` |
| 159 | +{{ yoti_login_button_sm }} |
| 160 | +{{ yoti_login_button_md }} |
| 161 | +{{ yoti_login_button_lg }} |
| 162 | +``` |
| 163 | +- or with a default one `{{ yoti_login_button }}`, in case you're using DTL |
| 164 | +as a template language) |
| 165 | +- or with `{{ yoti_login_button(size='small', text='Log In with Yoti')`, in |
| 166 | +case you're using Jinja2 as your template language<br> |
| 167 | +Available button sizes: `small`, `medium`, `large` |
| 168 | + |
| 169 | +By clicking this button, user will be redirected to the Yoti Authentication page. |
| 170 | + |
| 171 | +*Remember to add an appropriate script to your page with login |
| 172 | +button in order for it to work. See: [Yoti Developers Documentation](https://www.yoti.com/developers/#login-button-setup)* |
| 173 | + |
| 174 | +2. After successful authentication, user will be redirected to a view, |
| 175 | +provided by the `YOTI_REDIRECT_TO` setting. |
| 176 | +3. In order to have an access to an authenticated user's information inside a view, |
| 177 | +you should use a `@yoti_authenticated` decorator. |
| 178 | +Example: |
| 179 | +```python |
| 180 | +from django_yoti import yoti_authenticated |
| 181 | + |
| 182 | +@yoti_authenticated |
| 183 | +def profile_view(request): |
| 184 | + user_id = request.yoti_user_id |
| 185 | + user_profile = request.yoti_user_profile |
| 186 | + return render(request, 'profile.html', user_profile) |
| 187 | +``` |
| 188 | + |
| 189 | +4. All *not authenticated* users trying to access endpoint with this decorator, |
| 190 | +will be redirected to an endpoint, provided by the `YOTI_LOGIN_VIEW` setting. |
| 191 | + |
| 192 | +## Tests ## |
| 193 | + |
| 194 | +To run unit tests just type: `python django_yoti/runtests.py` |
0 commit comments