messages
resource if users have the manager access level, and grant write access to that resource if they have the administrator access level.You can define allowed permissions in the Permissions view of the Auth0 Dashboard’s APIs section. The following example uses the read:messages
scope.requirements.txt
:pip install -r requirements.txt
JWTBearerTokenValidator
validator with a few tweaks to make sure it conforms to our requirements for validating Access Tokens.To create your Auth0JWTBearerTokenValidator
, you need to pass it to your domain
and audience
(API Identifier). It will then get the public key required to verify the token’s signature and pass it to the JWTBearerTokenValidator
class.You’ll then override the class’s claims_options
to make sure the token’s expiry
, audience
, and issue
claims are validated according to our requirements.Create the file apiexample/validator.py
using the code from the interactive panel.Next, you’ll create three API views in apiexample/views.py
:/api/public
: A public endpoint that requires no authentication./api/private
: A private endpoint that requires a valid Access Token JWT./api/private-scoped
: A private endpoint that requires a valid Access Token JWT containing the given scope
.require_auth
decorator, which is a ResourceProtector
that uses the Auth0JWTBearerTokenValidator
you created earlier.To create the Auth0JWTBearerTokenValidator
, you’ll pass it to your tenant’s domain and the API Identifier of the API you created earlier.The require_auth
decorator on the private_scoped
route accepts an additional argument "read:messages"
, which checks the Access Token for the Permission (Scope) you created earlier.In previous steps, you added methods to the views.py
file. Next, map those methods to URLs using Django’s URL dispatcher, which lets you map URL patterns to views.Add the URL patterns to your apiexample/urls.py
file.Authorization
header in your requests.messages
resource if users have the manager access level, and grant write access to that resource if they have the administrator access level.You can define allowed permissions in the Permissions view of the Auth0 Dashboard’s APIs section. The following example uses the read:messages
scope.JWTBearerTokenValidator
validator with a few tweaks to make sure it conforms to our requirements for validating Access Tokens.To create your Auth0JWTBearerTokenValidator
, you need to pass it to your domain
and audience
(API Identifier). It will then get the public key required to verify the token’s signature and pass it to the JWTBearerTokenValidator
class.You’ll then override the class’s claims_options
to make sure the token’s expiry
, audience
, and issue
claims are validated according to our requirements.Create the file apiexample/validator.py
using the code from the interactive panel.apiexample/views.py
:/api/public
: A public endpoint that requires no authentication./api/private
: A private endpoint that requires a valid Access Token JWT./api/private-scoped
: A private endpoint that requires a valid Access Token JWT containing the given scope
.require_auth
decorator, which is a ResourceProtector
that uses the Auth0JWTBearerTokenValidator
you created earlier.To create the Auth0JWTBearerTokenValidator
, you’ll pass it to your tenant’s domain and the API Identifier of the API you created earlier.The require_auth
decorator on the private_scoped
route accepts an additional argument "read:messages"
, which checks the Access Token for the Permission (Scope) you created earlier.views.py
file. Next, map those methods to URLs using Django’s URL dispatcher, which lets you map URL patterns to views.Add the URL patterns to your apiexample/urls.py
file.Authorization
header in your requests.