express-oauth2-jwt-bearer
package.If you have not created an API in your Auth0 dashboard yet, use the interactive selector to create a new Auth0 API or select an existing project API.To set up your first API through the Auth0 dashboard, review our getting started guide. Each Auth0 API uses the API Identifier, which your application needs to validate the access token.messages
resource if users have the manager access level, and a 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.read:messages
scope.npm
.express-oauth2-jwt-bearer
with your Domain and API Identifier.The checkJwt
middleware shown to the right checks if the user’s access token included in the request is valid. If the token is not valid, the user gets a 401 Authorization error when they try to access the endpoints.The middleware does not check if the token has sufficient scope to access the requested resources.To protect an individual route by requiring a valid JWT, configure the route with the checkJwt
middleware constructed from express-oauth2-jwt-bearer
.You can configure individual routes to look for a particular scope. To achieve that, set up another middleware with the requiresScope
method. Provide the required scopes and apply the middleware to any routes you want to add authorization to.Pass the checkJwt
and requiredScopes
middlewares to the route you want to protect.In this configuration, only access tokens with the read:messages
scope can access the endpoint.Authorization
header in your requests.GET /api/public
is available for non-authenticated requests.GET /api/private
is available for authenticated requests.GET /api/private-scoped
is available for authenticated requests containing an access token with the read:messages
scope.messages
resource if users have the manager access level, and a 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.read:messages
scope.npm
.express-oauth2-jwt-bearer
with your Domain and API Identifier.The checkJwt
middleware shown to the right checks if the user’s access token included in the request is valid. If the token is not valid, the user gets a 401 Authorization error when they try to access the endpoints.The middleware does not check if the token has sufficient scope to access the requested resources.checkJwt
middleware constructed from express-oauth2-jwt-bearer
.You can configure individual routes to look for a particular scope. To achieve that, set up another middleware with the requiresScope
method. Provide the required scopes and apply the middleware to any routes you want to add authorization to.Pass the checkJwt
and requiredScopes
middlewares to the route you want to protect.In this configuration, only access tokens with the read:messages
scope can access the endpoint.Authorization
header in your requests.GET /api/public
is available for non-authenticated requests.GET /api/private
is available for authenticated requests.GET /api/private-scoped
is available for authenticated requests containing an access token with the read:messages
scope.