ASP.NET Core (API, Blazor and MVC) + Keycloak — Part 1

Luy Lucas
3 min readJan 28, 2024

--

This series delves into the integration of ASP.NET Core apps with Keycloak SSO (running in Docker), explaining how to authenticate and authorize an user.

Part 2;

Part 3;

Part 4;

Bonus;

We’ll start configuring the Keycloak instance on Docker running this command on powershell:

docker run -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:latest start-dev

This will start an instance on develop mode. Open the admin UI http://localhost:8080, option “Administration Console”, login with admin/admin credentials:

A print of the administration console option after open the localhost url

Lets create a new realm, name it aspnet (or any name do you want):

A print of realm options in the sidebar menu of keycloak UI

The realm needs just the name:

A print of the realm register page

After create a realm, create a client:

Client type: OpenId;

ClientId: You can use a plain text or a uuid;

Give a name and description to the client;

Client Authentication: off;

Enable Implicit Flow (It’ll used by Swagger);

Root URL: API Url;

Valid Redirects URIs: are URIs that Keycloak can redirect after login;

Web Origins: are URIs that Keycloak can accept requests, set it ‘+’ to accept requests from Valid Redirect URIs;

Save. Now, create an user in the realm:

In the credentials tab, create a password (make it simple, like 123456):

For now, We have a Keycloak instance configured to use. In the next part, We’ll configure an API to use this client.

--

--