| 1 |
OAuth2 Handler |
| 2 |
============== |
| 3 |
|
| 4 |
|image0| |
| 5 |
|
| 6 |
Presentation |
| 7 |
------------ |
| 8 |
|
| 9 |
This Handler is able to check an OAuth2 access token to retrieve the |
| 10 |
user real session and protect a virtual host like a standard Handler |
| 11 |
(access control and HTTP headers transmission). |
| 12 |
|
| 13 |
This requires to get an OAuth2 access token through LL::NG Portal (OpenID |
| 14 |
Connect server). This access token can then be used in the |
| 15 |
``Authorization`` header to authenticate to the Web Service / API |
| 16 |
protected by the OAuth2 Handler. |
| 17 |
|
| 18 |
|image1| |
| 19 |
|
| 20 |
|
| 21 |
.. tip:: |
| 22 |
|
| 23 |
In the above schema, the OpenID Connect process is simplified. |
| 24 |
How the front application receives the Access Token depends on the |
| 25 |
requested flow (Authorization code, Implicit or Hybrid). In all cases, |
| 26 |
the application will have an Access Token and will be able to use it to |
| 27 |
request a Web Service. |
| 28 |
|
| 29 |
Example: |
| 30 |
|
| 31 |
:: |
| 32 |
|
| 33 |
curl -H "Authorization: Bearer de853461341e88e9def8fcb9db2a81c4" https://oauth2.example.com/api/test | json_pp |
| 34 |
|
| 35 |
.. code-block:: javascript |
| 36 |
|
| 37 |
{ |
| 38 |
check: true, |
| 39 |
user: "dwho" |
| 40 |
} |
| 41 |
|
| 42 |
Additional variables |
| 43 |
-------------------- |
| 44 |
|
| 45 |
The OAuth2 handler defines a few extra variables that you can use in |
| 46 |
:doc:`rules and headers<writingrulesand_headers>`. |
| 47 |
|
| 48 |
* ``$_clientId``: client ID of the application which requested the Access Token |
| 49 |
* ``$_clientConfKey``: configuration key of the application which requested the |
| 50 |
Access Token |
| 51 |
* ``$_oidc_grant_type`` (since *2.0.14*): the grant type used to generate the Access Token. If |
| 52 |
Refresh Tokens are used, this is the grant type of the first emitted Access |
| 53 |
Token. Possible values: ``authorizationcode``, ``implicit``, ``hybrid``, |
| 54 |
``clientcredentials``, ``password`` |
| 55 |
* ``$_scope``: list of space-separated scopes granted by the Access Token |
| 56 |
* ``$_accessToken``: value of the access token, in case your application needs it as well |
| 57 |
* ``$_audiences`` (since *2.23.0*): list of audiences allowed for this token. You can use :ref:`listMatch($_audiences, "my.audience.com")<listMatch>` to check for the expected value. Audiences can be added to a token using the **Additional audiences** :doc:`OIDC relying party configuration parameter <idpopenidconnect>`. |
| 58 |
|
| 59 |
For example, to grant access to access tokens containing the ``write`` scope, |
| 60 |
use :: |
| 61 |
|
| 62 |
$_scope =~ /(?<!\S)write(?!\S)/ |
| 63 |
|
| 64 |
|
| 65 |
Configuration |
| 66 |
------------- |
| 67 |
|
| 68 |
Protect you virtual host like any other virtual host with the standard Handler. |
| 69 |
|
| 70 |
Define access rules and headers. Then in ``Options`` > ``Type``, choose ``OAuth2``. |
| 71 |
|
| 72 |
.. note:: |
| 73 |
|
| 74 |
OAuth2 handler inherits from Main handler. So it is able to manage both SSO cookie and OAuth2 Access Token. |
| 75 |
|
| 76 |
Reference |
| 77 |
--------- |
| 78 |
|
| 79 |
:rfc:`6750` |
| 80 |
|
| 81 |
.. |image0| image:: /documentation/oauth-retina-preview.jpg |
| 82 |
:class: align-center |
| 83 |
.. |image1| image:: /documentation/oauth2_handler.png |
| 84 |
:class: align-center |
| 85 |
|