Nedo.AspNet.Authentication.Keycloak
2.0.9
dotnet add package Nedo.AspNet.Authentication.Keycloak --version 2.0.9
NuGet\Install-Package Nedo.AspNet.Authentication.Keycloak -Version 2.0.9
<PackageReference Include="Nedo.AspNet.Authentication.Keycloak" Version="2.0.9" />
<PackageVersion Include="Nedo.AspNet.Authentication.Keycloak" Version="2.0.9" />
<PackageReference Include="Nedo.AspNet.Authentication.Keycloak" />
paket add Nedo.AspNet.Authentication.Keycloak --version 2.0.9
#r "nuget: Nedo.AspNet.Authentication.Keycloak, 2.0.9"
#:package Nedo.AspNet.Authentication.Keycloak@2.0.9
#addin nuget:?package=Nedo.AspNet.Authentication.Keycloak&version=2.0.9
#tool nuget:?package=Nedo.AspNet.Authentication.Keycloak&version=2.0.9
Nedo.AspNet.Authentication.Keycloak
Keycloak as the canonical token issuer (JWT-bearer pattern). Your API trusts Keycloak's JWTs, validates them, and uses the result for authorization. Keycloak's realm_access.roles and resource_access.<client>.roles are auto-mapped to ASP.NET Core's ClaimTypes.Role so [Authorize(Roles = "admin")] just works.
Looking for Keycloak as a sign-in option that mints your own JWTs? That's
AddKeycloakSignInin this same package — see docs/providers/social/keycloak.md. The two patterns coexist.
Install
dotnet add package Nedo.AspNet.Authentication.Keycloak
Quickstart — JWT bearer (resource server)
using Nedo.AspNet.Authentication.Keycloak;
builder.Services.AddKeycloak(opts =>
{
opts.ServerUrl = "https://keycloak.example.com";
opts.Realm = "my-realm";
opts.Audience = "my-api";
});
builder.Services.AddAuthorization();
builder.Services.AddHttpContextAccessor();
builder.Services.AddScoped<IAuthContext, AuthContext>();
var app = builder.Build();
app.UseAuthentication();
app.UseNedoAuthContext();
app.UseAuthorization();
app.MapGet("/admin", (IAuthContext auth) => auth.UserId)
.RequireAuthorization(p => p.RequireRole("admin"));
Quickstart — Keycloak as a sign-in option
builder.Services.AddKeycloakSignIn(opts =>
{
opts.ServerUrl = "https://keycloak.example.com";
opts.Realm = "my-realm";
opts.ClientId = "my-spa";
opts.ClientSecret = builder.Configuration["Keycloak:Secret"];
opts.FrontendOrigin = "https://app.example.com";
});
app.MapKeycloakAuth(); // /auth/keycloak/start, /auth/keycloak/callback (popup + postMessage)
The popup flow exchanges the Keycloak code for a Nedo session via ExternalSignInService — your app issues its own JWTs, with Keycloak link metadata stored in nedo_external_logins. Pair with Nedo.AspNet.Authentication.Local.
Claims auto-mapping
| Keycloak claim shape | Mapped to |
|---|---|
realm_access.roles: ["admin", "manager"] |
ClaimTypes.Role (one per value) |
resource_access.<client>.roles: ["editor"] |
ClaimTypes.Role (one per value) |
preferred_username |
ClaimTypes.Name |
email |
ClaimTypes.Email |
Customize via INedoClaimsTransformer from Nedo.AspNet.Authentication.Claims.
Docs
- docs/04-identity-providers.md — JWT-bearer pattern walkthrough.
- docs/providers/social/keycloak.md — sign-in flow.
- docs/integration-react.md — React + Keycloak end-to-end.
License
MIT — see LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- Nedo.AspNet.Authentication (>= 2.0.9)
- Nedo.AspNet.Authentication.Claims (>= 2.0.9)
- Nedo.AspNet.Authentication.Local (>= 2.0.9)
- Nedo.AspNet.Authentication.Oidc (>= 2.0.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.