Microsoft.Owin.Security.Jwt
package.If you have not created an API in your Auth0 dashboard yet, you can use the interactive selector to create a new Auth0 API or select an existing API for your project.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. The following example uses the read:messages
scope.Install the Microsoft.Owin.Security.Jwt
NuGetPackage. This package contains the OWIN JWT Middleware necessary to use Auth0 access tokens in the ASP.NET Owin Web API.Configuration
method of your Startup
class and add a call to UseJwtBearerAuthentication
passing in the configured JwtBearerAuthenticationOptions
.The JwtBearerAuthenticationOptions
needs to specify your Auth0 API Identifier in the ValidAudience
property, and the full path to your Auth0 domain as the ValidIssuer
. You will need to configure the IssuerSigningKeyResolver
to use the instance of OpenIdConnectSigningKeyResolver
to resolve the signing key.ValidIssuer
contains a trailing forward slash (/
). This must match exactly with the JWT issuer claim. API calls will not authenticate correctly if you misconfigured this value.IssuerSigningKeyResolver
.Create the OpenIdConnectSigningKeyResolver
class and ensure to return the correct SecurityKey
by implementing GetSigningKey
. This class is then used as TokenValidationParameters.IssuerSigningKeyResolver
while configuring the middleware in Startup.cs
.ScopeAuthorizeAttribute
which inherits from System.Web.Http.AuthorizeAttribute
. This attribute will check that the scope
claim issued by your Auth0 tenant is present, and if so, it will ensure that the scope
claim contains the requested scope.The routes shown below are available for the following requests:GET /api/public
: Available for non-authenticated requests.GET /api/private
: Available for authenticated requests containing an access token with no additional scopes.GET /api/private-scoped
: Available for authenticated requests containing an access token with the read:messages
scope granted.[Authorize]
attribute to secure an endpoint.Update the action with the ScopeAuthorize
attribute and pass the name of the required scope
in the scope
parameter. This ensures the correct scope is available to call a specific API endpoint.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. The following example uses the read:messages
scope.Microsoft.Owin.Security.Jwt
NuGetPackage. This package contains the OWIN JWT Middleware necessary to use Auth0 access tokens in the ASP.NET Owin Web API.Configuration
method of your Startup
class and add a call to UseJwtBearerAuthentication
passing in the configured JwtBearerAuthenticationOptions
.The JwtBearerAuthenticationOptions
needs to specify your Auth0 API Identifier in the ValidAudience
property, and the full path to your Auth0 domain as the ValidIssuer
. You will need to configure the IssuerSigningKeyResolver
to use the instance of OpenIdConnectSigningKeyResolver
to resolve the signing key.ValidIssuer
contains a trailing forward slash (/
). This must match exactly with the JWT issuer claim. API calls will not authenticate correctly if you misconfigured this value.IssuerSigningKeyResolver
.Create the OpenIdConnectSigningKeyResolver
class and ensure to return the correct SecurityKey
by implementing GetSigningKey
. This class is then used as TokenValidationParameters.IssuerSigningKeyResolver
while configuring the middleware in Startup.cs
.ScopeAuthorizeAttribute
which inherits from System.Web.Http.AuthorizeAttribute
. This attribute will check that the scope
claim issued by your Auth0 tenant is present, and if so, it will ensure that the scope
claim contains the requested scope.GET /api/public
: Available for non-authenticated requests.GET /api/private
: Available for authenticated requests containing an access token with no additional scopes.GET /api/private-scoped
: Available for authenticated requests containing an access token with the read:messages
scope granted.[Authorize]
attribute to secure an endpoint.Update the action with the ScopeAuthorize
attribute and pass the name of the required scope
in the scope
parameter. This ensures the correct scope is available to call a specific API endpoint.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.