Skip to content

Commit 34247b9

Browse files
committed
move authentication before management API
1 parent e604c97 commit 34247b9

1 file changed

Lines changed: 85 additions & 86 deletions

File tree

README.rst

Lines changed: 85 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,79 @@ For python3, use the following command
4848
4949
Python 3.2 and 3.3 have reached `EOL <https://en.wikipedia.org/wiki/CPython#Version_history>`_ and support will be removed in the near future.
5050

51+
========================
52+
Authentication SDK Usage
53+
========================
54+
55+
The Authentication SDK is divided into components mimicking the structure of the
56+
`API's documentation <https://auth0.com/docs/auth-api>`_.
57+
For example:
58+
59+
.. code-block:: python
60+
61+
from auth0.v3.authentication import Social
62+
63+
social = Social('myaccount.auth0.com')
64+
65+
s.login(client_id='...', access_token='...', connection='facebook')
66+
67+
===================
68+
ID Token validation
69+
===================
70+
71+
As the result of the authentication and among the credentials received, an ``id_token``
72+
might be present. This artifact contains information associated to the user that has
73+
just logged in, provided the scope used contained ``openid``. You can read more
74+
about ID tokens `here <https://auth0.com/docs/tokens/concepts/id-tokens>`_.
75+
76+
Before you access their contents, you must first verify the ID token to ensure its
77+
contents has not been tampered with and that is meant for your application to consume.
78+
79+
For that purpose you use the ``TokenVerifier`` class, which requires to be passed
80+
a few options:
81+
* A ``SignatureVerifier`` instance, in charge of checking the expected algorithm
82+
and signature.
83+
* The expected issuer value, typically matches the Auth0 domain prefixed with
84+
``https://`` and suffixed with ``/``.
85+
* The expected audience value, typically matches the Auth0 application client ID.
86+
87+
You choose the signature verifier depending on the signing algorithm used by your Auth0 application.
88+
You can check its value under ``Advanced settings | OAuth | JsonWebToken Signature Algorithm``.
89+
* For symmetric algorithms like "HS256", use the `SymmetricSignatureVerifier` class passing
90+
as secret the client secret value for your Auth0 application.
91+
* For asymmetric algorithms like "RS256", use the `AsymmetricSignatureVerifier` class passing
92+
the public URL where the certificates for the public keys can be found.
93+
94+
Auth0 hosts Public Keys inside the ``.well-known`` directory of your tenant's domain.
95+
That URL looks like this: ``https://myaccount.auth0.com/.well-known/jwks.json``.
96+
After replacing `myaccount.auth0.com` with your tenant's domain, you should be able
97+
to access your tenant's public keys.
98+
99+
It is recommended that you make use of asymmetric signing algorithms as their keys are easier
100+
to rotate in case they need to be revoked.
101+
102+
With all in place, the next snippets shows how to verify an RS256 signed ID token:
103+
104+
.. code-block:: python
105+
106+
from auth0.v3.authentication.token_verifier import TokenVerifier, AsymmetricSignatureVerifier
107+
108+
domain = 'myaccount.auth0.com'
109+
client_id = 'exampleid'
110+
111+
# After authenticating
112+
id_token = auth_result['id_token']
113+
114+
jwks_url = 'https://{}/.well-known/jwks.json'.format(domain)
115+
issuer = 'https://{}/'.format(domain)
116+
117+
sv = AsymmetricSignatureVerifier(jwks_url) # Reusable instance
118+
tv = TokenVerifier(signature_verifier=sv, issuer=issuer, audience=client_id)
119+
tv.verify(id_token)
120+
121+
Provided something goes wrong, a ``TokenValidationError`` will be raised. In this
122+
scenario, the ID token should be deemed invalid and its contents not be trusted.
123+
51124
====================
52125
Management SDK Usage
53126
====================
@@ -140,79 +213,6 @@ Success!
140213
All endpoints follow a similar structure to ``connections``, and try to follow as
141214
closely as possible the `API documentation <https://auth0.com/docs/api/v2>`_.
142215

143-
========================
144-
Authentication SDK Usage
145-
========================
146-
147-
The Authentication SDK is divided into components mimicking the structure of the
148-
`API's documentation <https://auth0.com/docs/auth-api>`_.
149-
For example:
150-
151-
.. code-block:: python
152-
153-
from auth0.v3.authentication import Social
154-
155-
social = Social('myaccount.auth0.com')
156-
157-
s.login(client_id='...', access_token='...', connection='facebook')
158-
159-
===================
160-
ID Token validation
161-
===================
162-
163-
As the result of the authentication and among the credentials received, an ``id_token``
164-
might be present. This artifact contains information associated to the user that has
165-
just logged in, provided the scope used contained ``openid``. You can read more
166-
about ID tokens `here <https://auth0.com/docs/tokens/concepts/id-tokens>`_.
167-
168-
Before you access their contents, you must first verify the ID token to ensure its
169-
contents has not been tampered with and that is meant for your application to consume.
170-
171-
For that purpose you use the ``TokenVerifier`` class, which requires to be passed
172-
a few options:
173-
* A ``SignatureVerifier`` instance, in charge of checking the expected algorithm
174-
and signature.
175-
* The expected issuer value, typically matches the Auth0 domain prefixed with
176-
``https://`` and suffixed with ``/``.
177-
* The expected audience value, typically matches the Auth0 application client ID.
178-
179-
You choose the signature verifier depending on the signing algorithm used by your Auth0 application.
180-
You can check its value under ``Advanced settings | OAuth | JsonWebToken Signature Algorithm``.
181-
* For symmetric algorithms like "HS256", use the `SymmetricSignatureVerifier` class passing
182-
as secret the client secret value for your Auth0 application.
183-
* For asymmetric algorithms like "RS256", use the `AsymmetricSignatureVerifier` class passing
184-
the public URL where the certificates for the public keys can be found.
185-
186-
Auth0 hosts Public Keys inside the ``.well-known`` directory of your tenant's domain.
187-
That URL looks like this: ``https://myaccount.auth0.com/.well-known/jwks.json``.
188-
After replacing `myaccount.auth0.com` with your tenant's domain, you should be able
189-
to access your tenant's public keys.
190-
191-
It is recommended that you make use of asymmetric signing algorithms as their keys are easier
192-
to rotate in case they need to be revoked.
193-
194-
With all in place, the next snippets shows how to verify an RS256 signed ID token:
195-
196-
.. code-block:: python
197-
198-
from auth0.v3.authentication.token_verifier import TokenVerifier, AsymmetricSignatureVerifier
199-
200-
domain = 'myaccount.auth0.com'
201-
client_id = 'exampleid'
202-
203-
# After authenticating
204-
id_token = auth_result['id_token']
205-
206-
jwks_url = 'https://{}/.well-known/jwks.json'.format(domain)
207-
issuer = 'https://{}/'.format(domain)
208-
209-
sv = AsymmetricSignatureVerifier(jwks_url) # Reusable instance
210-
tv = TokenVerifier(signature_verifier=sv, issuer=issuer, audience=client_id)
211-
tv.verify(id_token)
212-
213-
Provided something goes wrong, a ``TokenValidationError`` will be raised. In this
214-
scenario, the ID token should be deemed invalid and its contents not be trusted.
215-
216216
==============
217217
Error Handling
218218
==============
@@ -223,6 +223,18 @@ When consuming methods from the API clients, the requests could fail for a numbe
223223
resets is exposed in the ``reset_at`` property. When the header is unset, this value will be ``-1``.
224224
- Network timeouts: Adjustable by passing a ``timeout`` argument to the client. See the `rate limit docs <https://auth0.com/docs/policies/rate-limits>`_ for details.
225225

226+
Available Authentication Endpoints
227+
==================================
228+
229+
- Users ( ``authentication.Users`` )
230+
- Database ( ``authentication.Database`` )
231+
- Delegated ( ``authentication.Delegated`` )
232+
- Enterprise ( ``authentication.Enterprise`` )
233+
- Passwordless ( ``authentication.Passwordless`` )
234+
- Social ( ``authentication.Social`` )
235+
- API Authorization - Get Token ( ``authentication.GetToken``)
236+
- API Authorization - Authorization Code Grant (``authentication.AuthorizeClient``)
237+
   
226238
Available Management Endpoints
227239
==============================
228240

@@ -250,19 +262,6 @@ Available Management Endpoints
250262
- Users() ( ``Auth0().users`` )
251263
- UsersByEmail() ( ``Auth0().users_by_email`` )
252264

253-
Available Authentication Endpoints
254-
==================================
255-
256-
- Users ( ``authentication.Users`` )
257-
- Database ( ``authentication.Database`` )
258-
- Delegated ( ``authentication.Delegated`` )
259-
- Enterprise ( ``authentication.Enterprise`` )
260-
- Passwordless ( ``authentication.Passwordless`` )
261-
- Social ( ``authentication.Social`` )
262-
- API Authorization - Get Token ( ``authentication.GetToken``)
263-
- API Authorization - Authorization Code Grant (``authentication.AuthorizeClient``)
264-
   
265-
266265
==========
267266
Change Log
268267
==========

0 commit comments

Comments
 (0)