Creating an MVC web application project
In this section, we will create a simple MVC web application project that uses the authorization server to authenticate users and protect some action methods on controllers to see how authorization works. You can create an empty web application project and enable MVC by calling AddMvc
in the ConfigureServices
method and UseMvcDefaultRoute
in the Configure method in the Startup
class.
Adding OIDC and cookie middleware in HTTP pipeline
To use OpenID Connect Provider (OP), we need to add the middleware to our application's HTTP pipeline, so that unauthorized requests can be forwarded to the authorization server for user authentication.
Add cookie middleware and OIDC middleware as follows:
app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationScheme = "Cookies" }); app.UseOpenIdConnectAuthentication( new OpenIdConnectOptions { AuthenticationScheme = "oidc", ClientId = "client...