You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.rst
+24-39Lines changed: 24 additions & 39 deletions
Original file line number
Diff line number
Diff line change
@@ -67,58 +67,43 @@ If you need to authenticate a user using their email and password, you can use t
67
67
ID Token validation
68
68
===================
69
69
70
-
As the result of the authentication and among the credentials received, an ``id_token``
71
-
might be present. This artifact contains information associated to the user that has
72
-
just logged in, provided the scope used contained ``openid``. You can read more
73
-
about ID tokens `here <https://auth0.com/docs/tokens/concepts/id-tokens>`_.
74
-
75
-
Before you access their contents, you must first verify the ID token to ensure its
76
-
contents has not been tampered withand that is meant for your application to consume.
77
-
78
-
For that purpose you use the ``TokenVerifier``class, which requires to be passed
79
-
a few options:
80
-
* A ``SignatureVerifier`` instance, in charge of checking the expected algorithm
81
-
and signature.
82
-
* The expected issuer value, typically matches the Auth0 domain prefixed with
83
-
``https://``and suffixed with``/``.
84
-
* The expected audience value, typically matches the Auth0 application client ID.
85
-
86
-
You choose the signature verifier depending on the signing algorithm used by your Auth0 application.
87
-
You can check its value under ``Advanced settings | OAuth | JsonWebToken Signature Algorithm``.
88
-
* For symmetric algorithms like "HS256", use the `SymmetricSignatureVerifier`class passing
89
-
as secret the client secret value for your Auth0 application.
90
-
* For asymmetric algorithms like "RS256", use the `AsymmetricSignatureVerifier`class passing
91
-
the public URL where the certificates for the public keys can be found.
92
-
93
-
Auth0 hosts Public Keys inside the ``.well-known`` directory of your tenant's domain.
94
-
That URL looks like this: ``https://myaccount.auth0.com/.well-known/jwks.json``.
95
-
After replacing `myaccount.auth0.com`with your tenant's domain, you should be able
96
-
to access your tenant's public keys.
97
-
98
-
It is recommended that you make use of asymmetric signing algorithms as their keys are easier
99
-
to rotate in case they need to be revoked.
100
-
101
-
With allin place, the next snippets shows how to verify an RS256 signed ID token:
70
+
Upon successful authentication, the credentials received may include an ``id_token``, if the authentication request contained the ``openid`` scope. The ``id_token`` contains information associated with the authenticated user. You can read more about ID tokens `here <https://auth0.com/docs/tokens/concepts/id-tokens>`_.
102
71
103
-
.. code-block:: python
72
+
Before you access its contents, you must verify that the ID token has not been tampered withand that it is meant for your application to consume. The ``TokenVerifier``class can be used to perform this verification.
104
73
105
-
from auth0.v3.authentication.token_verifier import TokenVerifier, AsymmetricSignatureVerifier
74
+
To create a ``TokenVerifier``, the following arguments are required:
75
+
* A ``SignatureVerifier`` instance, which is responsible for verifying the token's algorithm name and signature.
76
+
* The expected issuer value, which typically matches the Auth0 domain prefixed with``https://``and suffixed with``/``.
77
+
* The expected audience value, which typically matches the Auth0 application client ID.
78
+
79
+
The type of ``SignatureVerifier`` used depends upon the signing algorithm used by your Auth0 application. You can view this value in your application settings under ``Advanced settings | OAuth | JsonWebToken Signature Algorithm``. Auth0 recommends using the RS256 asymmetric signing algorithm. You can read more about signing algorithms `here <https://auth0.com/docs/tokens/signing-algorithms>`_.
80
+
81
+
For asymmetric algorithms like RS256, use the ``AsymmetricSignatureVerifier``class, passing
82
+
the public URL where the certificates for the public keys can be found. This will typically be your Auth0 domain with the ``/.well-known/jwks.json`` path appended to it. For example, ``https://your-domain.auth0.com/.well-known/jwks.json``.
83
+
84
+
For symmetric algorithms like HS256, use the ``SymmetricSignatureVerifier``class, passing the value of the client secret of your Auth0 application.
106
85
86
+
The following example demonstrates the verification of an ID token signed with the RS256 signing algorithm:
87
+
88
+
.. code-block:: python
89
+
90
+
from auth0.v3.authentication.token_verifier import TokenVerifier, AsymmetricSignatureVerifier
If the token verification fails, a ``TokenValidationError`` will be raised. In that scenario, the ID token should be deemed invalid and its contents should not be trusted.
119
106
120
-
Provided something goes wrong, a ``TokenValidationError`` will be raised. In this
121
-
scenario, the ID token should be deemed invalid and its contents not be trusted.
0 commit comments