|
| 1 | +Separate Resource Server |
| 2 | +======================== |
| 3 | +Django OAuth Toolkit allows to separate the :term:`Authentication Server` and the :term:`Resource Server.` |
| 4 | +Based one the `RFC 7662 <https://tools.ietf.org/html/rfc7662>`_ Django OAuth Toolkit provides |
| 5 | +a rfc-compliant introspection endpoint. |
| 6 | +As well the Django OAuth Toolkit allows to verify access tokens by the use of an introspection endpoint. |
| 7 | + |
| 8 | + |
| 9 | +Setup the Authentication Server |
| 10 | +------------------------------- |
| 11 | +Setup the :term:`Authentication Server` as described in the :ref:`tutorial`. |
| 12 | +Create a OAuth2 access token for the :term:`Resource Server` and add the |
| 13 | +``introspection``-Scope to the settings. |
| 14 | + |
| 15 | +.. code-block:: python |
| 16 | +
|
| 17 | + 'SCOPES': { |
| 18 | + 'read': 'Read scope', |
| 19 | + 'write': 'Write scope', |
| 20 | + 'introspection': 'Introspect token scope', |
| 21 | + ... |
| 22 | + }, |
| 23 | +
|
| 24 | +The :term:`Authentication Server` will listen for introspection requests. |
| 25 | +The endpoint is located within the ``oauth2_provider.urls`` as ``/introspect/``. |
| 26 | + |
| 27 | +Example Request:: |
| 28 | + |
| 29 | + POST /o/introspect/ HTTP/1.1 |
| 30 | + Host: server.example.com |
| 31 | + Accept: application/json |
| 32 | + Content-Type: application/x-www-form-urlencoded |
| 33 | + Authorization: Bearer 3yUqsWtwKYKHnfivFcJu |
| 34 | + |
| 35 | + token=uH3Po4KXWP4dsY4zgyxH |
| 36 | + |
| 37 | +Example Response:: |
| 38 | + |
| 39 | + HTTP/1.1 200 OK |
| 40 | + Content-Type: application/json |
| 41 | + |
| 42 | + { |
| 43 | + "active": true, |
| 44 | + "client_id": "oUdofn7rfhRtKWbmhyVk", |
| 45 | + "username": "jdoe", |
| 46 | + "scope": "read write dolphin", |
| 47 | + "exp": 1419356238 |
| 48 | + } |
| 49 | + |
| 50 | +Setup the Resource Server |
| 51 | +------------------------- |
| 52 | +Setup the :term:`Resource Server` like the :term:`Authentication Server` as described in the :ref:`tutorial`. |
| 53 | +Add ``RESOURCE_SERVER_INTROSPECTION_URL`` and ``RESOURCE_SERVER_AUTH_TOKEN`` to your settings. |
| 54 | +The :term:`Resource Server` will try to verify its requests on the :term:`Authentication Server`. |
| 55 | + |
| 56 | +.. code-block:: python |
| 57 | +
|
| 58 | + OAUTH2_PROVIDER = { |
| 59 | + ... |
| 60 | + 'RESOURCE_SERVER_INTROSPECTION_URL': 'https://example.org/o/introspect/', |
| 61 | + 'RESOURCE_SERVER_AUTH_TOKEN': '3yUqsWtwKYKHnfivFcJu', |
| 62 | + ... |
| 63 | + } |
| 64 | +
|
| 65 | +``RESOURCE_SERVER_INTROSPECTION_URL`` defines the introspection endpoint and |
| 66 | +``RESOURCE_SERVER_AUTH_TOKEN`` an authentication token to authenticate against the |
| 67 | +:term:`Authentication Server`. |
| 68 | + |
0 commit comments