http://localhost:3000/callback
.http://localhost:3000
.Auth0.AspNetCore.Authentication
Nuget package to your application.Program.cs
file and call builder.Services.AddAuth0WebAppAuthentication()
to register the
SDK’s middleware.Ensure to configure the Domain
and ClientId
, these are required fields to ensure the
SDK knows which Auth0 tenant and application it should use.Make sure you have enabled authentication and authorization in your Program.cs
file.LoginModel
to your
Pages
directory.Inside the LoginModel
’s OnGet
method, call HttpContext.ChallengeAsync()
and pass Auth0Constants.AuthenticationScheme
as the authentication scheme. This will invoke the OIDC
authentication handler that our SDK registers internally. Be sure to also specify the corresponding
authenticationProperties
, which you can construct using the
LoginAuthenticationPropertiesBuilder
.After successfully calling HttpContext.ChallengeAsync()
, the user will be redirected to Auth0 and
signed in to both the OIDC middleware and the cookie middleware upon being redirected back to your application.
This will allow the users to be authenticated on subsequent requests.Login
page will redirect to Auth0AuthenticationState
, which you can add
as a CascadingParameter
.You can create a custom user profile page for displaying the user’s name, as well as additional claims (such as
email and picture), by retrieving the corresponding information from the AuthenticationState
’s
User
property and passing it to the view from inside Blazor code.HttpContext.SignOutAsync
with
the CookieAuthenticationDefaults.AuthenticationScheme
authentication scheme from inside a
LogoutModel
’s OnGet
method.Additionally, if you also want to log the user out from Auth0 (this might also log them out of other applications
that rely on Single Sign On), call HttpContext.SignOutAsync
with the
Auth0Constants.AuthenticationScheme
authentication scheme as well as the appropriate
authenticationProperties
that can be constructed using the
LogoutAuthenticationPropertiesBuilder
.Logout
page will ensure the user is logged out.