In this part, we’ll integrate a MVC app with Keycloak
For the MVC app, we do almost the same thing like on API before.
We have to install this package:
Install-Package Microsoft.AspNetCore.Authentication.OpenIdConnect
Copy the keycloak section from the API appsettings, we can use the same client:
Copy the applicationUrl from launchSettings and input as Valid Redirect URI in the Keycloak client:
In the program.cs file we write these configurations:
Don’t forget to activate the Auth and Authz middlewares.
In the HomeController.cs We can use the [Authorize] attribute in the Privacy action.
Run this and click on the privacy link, You’ll be redirected to Keycloak login page, use the usertest1 credentials. Create a breakpoint in the Index or Privacy action and see the User:
Well that’s all for now!
Next, I’ll share Blazor WASM solution to this.
Cya.