1- .. image :: https://odoo-community.org/readme-banner-image
2- :target: https://odoo-community.org/get-involved?utm_source=readme
3- :alt: Odoo Community Association
4-
51========
62Auth JWT
73========
@@ -17,7 +13,7 @@ Auth JWT
1713.. |badge1 | image :: https://img.shields.io/badge/maturity-Beta-yellow.png
1814 :target: https://odoo-community.org/page/development-status
1915 :alt: Beta
20- .. |badge2 | image :: https://img.shields.io/badge/license -LGPL--3-blue.png
16+ .. |badge2 | image :: https://img.shields.io/badge/licence -LGPL--3-blue.png
2117 :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
2218 :alt: License: LGPL-3
2319.. |badge3 | image :: https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github
@@ -65,14 +61,54 @@ The JWT validator can be configured with the following properties:
6561
6662- ``name ``: the validator name, to match the
6763 ``auth="jwt_{validator-name}" `` route property.
68- - ``audience ``: a comma-separated list of allowed audiences, used to
69- validate the ``aud `` claim.
64+ - ``audience ``: a comma-separated list of values that must intersect
65+ with the JWT claim selected by ``audience_type `` (by default the
66+ standard ``aud `` claim — see "Audience type" below for matching
67+ against other claims like ``groups `` or ``scope ``).
68+ - ``audience_type ``: selects which JWT payload claim the ``audience ``
69+ list is matched against — ``Audience `` (default, validates ``aud ``),
70+ ``Group ``, ``Scope ``, or ``Custom ``. See "Audience type" below.
71+ - ``audience_type_custom ``: when ``audience_type `` is ``Custom ``, the
72+ JWT payload key to validate against the ``audience `` list (e.g.
73+ ``cognito:groups ``, ``permissions ``).
7074- ``issuer ``: used to validate the ``iss `` claim.
7175- Signature type (secret or public key), algorithm, secret and JWK URI
7276 are used to validate the token signature.
7377
7478In addition, the ``exp `` claim is validated to reject expired tokens.
7579
80+ **Audience type — matching non-standard JWT claims. ** The ``audience ``
81+ setting is matched against the standard JWT ``aud `` claim by default
82+ (RFC 7519). Some identity providers — notably AWS Cognito and several
83+ OAuth2-only IdPs — issue access tokens without an ``aud `` claim but
84+ expose authorization information under other claims (``cognito:groups ``,
85+ ``scope ``, ``roles ``). The ``audience_type `` field controls which claim
86+ the ``audience `` list is matched against:
87+
88+ - **Audience ** (default): standard ``aud `` claim validation; at least
89+ one configured value must be present in the token's ``aud `` claim.
90+ - **Group **: validates against the ``groups `` claim (array or
91+ space-separated string).
92+ - **Scope **: validates against the ``scope `` claim (space-separated per
93+ OAuth2 RFC 6749 §3.3, or an array).
94+ - **Custom **: validates against the arbitrary payload key configured in
95+ *Custom Audience Type Key * (e.g. ``cognito:groups ``, ``permissions ``,
96+ ``https://example.com/claims/roles ``).
97+
98+ For all non-``aud `` types the JWT library's built-in ``aud ``
99+ verification is skipped (the token has no ``aud ``) and the match is a
100+ set intersection: any one of the configured ``audience `` values
101+ appearing in the token's claim authorizes the request.
102+
103+ **Example — AWS Cognito access token. ** Cognito access tokens carry no
104+ ``aud `` claim but include ``cognito:groups `` (e.g.
105+ ``["odoo-admin", "odoo-portal"] ``) and ``scope `` (e.g.
106+ ``"openid profile odoo/read" ``). To restrict a route to clients in the
107+ ``odoo-admin `` Cognito group, configure the validator with
108+ ``audience_type = Custom ``, ``audience_type_custom = cognito:groups ``,
109+ and ``audience = odoo-admin ``. To restrict by OAuth scope instead,
110+ configure ``audience_type = Scope `` and ``audience = odoo/read ``.
111+
76112If the ``Authorization `` HTTP header is missing, malformed, or contains
77113an invalid token, the request is rejected with a 401 (Unauthorized)
78114code, unless the cookie mode is enabled (see below).
@@ -141,6 +177,7 @@ Contributors
141177
142178- Stéphane Bidoul <stephane.bidoul@acsone.eu>
143179- Mohamed Alkobrosli <malkobrosly@kencove.com>
180+ - Don Kendall <kendall@donkendall.com>
144181
145182Maintainers
146183-----------
0 commit comments