Katalyst.App.Auth
1.2.1
dotnet add package Katalyst.App.Auth --version 1.2.1
NuGet\Install-Package Katalyst.App.Auth -Version 1.2.1
<PackageReference Include="Katalyst.App.Auth" Version="1.2.1" />
<PackageVersion Include="Katalyst.App.Auth" Version="1.2.1" />
<PackageReference Include="Katalyst.App.Auth" />
paket add Katalyst.App.Auth --version 1.2.1
#r "nuget: Katalyst.App.Auth, 1.2.1"
#:package Katalyst.App.Auth@1.2.1
#addin nuget:?package=Katalyst.App.Auth&version=1.2.1
#tool nuget:?package=Katalyst.App.Auth&version=1.2.1
App.Auth
Reusable authentication and authorization services for .NET applications with provider-based wiring.
This package exposes vendor-agnostic service contracts:
IUserServicefor user CRUD and paginated listing.IRoleServicefor role CRUD and paginated listing.ISessionServicefor user session listing and revocation/logout.IGroupServicefor group CRUD, group role mappings, and group membership.
The first provider is Keycloak.
Pagination uses App.Core.PagedQuery and App.Core.PagedResult<T> from the Katalyst.App.Core NuGet package (1-based Page / PageSize, with Skip/Take for providers; default page size is 10). Search text for list endpoints is passed as a separate string? search parameter (not on PagedQuery).
Registration
Use AddAppAuth and choose one provider.
using App.Auth;
using App.Auth.DependencyInjection;
using App.Auth.Models;
using App.Core;
builder.Services.AddAppAuth(builder.Configuration, auth =>
{
auth.UseKeycloak(builder.Configuration.GetSection("Auth:Keycloak"));
});
Example appsettings.json
{
"Auth": {
"Keycloak": {
"BaseUrl": "http://localhost:8080",
"Realm": "my-realm",
"ClientId": "my-app-client",
"ClientSecret": "base64-cipher-text",
"ManagementClientId": "admin-cli",
"ManagementUsername": "admin",
"ManagementPassword": "base64-cipher-text",
"ManagementAuthRealm": "master"
}
}
}
Role scope is passed directly per role operation and defaults to Client:
await roleService.CreateAsync(
new AuthRole { Name = "auditor", Description = "Auditor role" },
roleScope: RoleScope.Realm,
cancellationToken: ct);
IUserService also supports explicit user status operations:
await userService.DisableAsync(userId, ct);
await userService.EnableAsync(userId, ct);
Role membership and mappings are also available:
await roleService.MapRoleToUserAsync(userId, "auditor", RoleScope.Client, ct);
await roleService.UnmapRoleFromUserAsync(userId, "auditor", RoleScope.Client, ct);
var members = await roleService.ListUsersInRoleAsync(
"auditor",
new PagedQuery { Page = 1, PageSize = 50 },
RoleScope.Client,
ct);
Session operations are also available:
var sessions = await sessionService.ListUserSessionsAsync(
userId,
new PagedQuery { Page = 1, PageSize = 50 },
ct);
await sessionService.LogoutUserAsync(userId, ct);
await sessionService.RevokeUserSessionsAsync(userId, ct);
Group operations are also available:
var group = await groupService.CreateAsync(new AuthGroup { Name = "finance" }, ct);
await groupService.AssignRoleAsync(group.Id!, "auditor", RoleScope.Client, ct);
await groupService.AddUserAsync(group.Id!, userId, ct);
Service capabilities
IUserService
CreateAsync- create userGetByIdAsync- get user by idGetByUsernameExactAsync- get user by exact usernameGetByEmailExactAsync- get user by exact emailUpdateAsync- update userDeleteAsync- delete userListAsync- list users with paginationSearchAsync- search users by username/email/free text with paginationCountAsync- count users (optionally filtered)EnableAsync- enable userDisableAsync- disable userLockAsync- lock user (provider-specific behavior; Keycloak maps this to disable)UnlockAsync- unlock/re-enable user sessions and stateResetPasswordAsync- set/reset user password (temporary or permanent)SetTemporaryPasswordAsync- set temporary passwordRemoveCredentialAsync- remove user credential by credential idSetRequiredActionsAsync- set required actions (for exampleUPDATE_PASSWORD,VERIFY_EMAIL,CONFIGURE_TOTP)SendVerifyEmailAsync- send verification emailSendExecuteActionsEmailAsync- send execute-actions emailSetEmailVerifiedAsync- setemailVerifiedflag
IRoleService
CreateAsync- create realm/client roleGetByNameAsync- get role by nameUpdateAsync- update roleDeleteAsync- delete roleListAsync- list roles with pagination/searchListUsersInRoleAsync- list users in roleMapRoleToUserAsync- assign role to userUnmapRoleFromUserAsync- remove role from userMapRoleToGroupAsync- assign role to groupUnmapRoleFromGroupAsync- remove role from groupMapRoleToServiceAccountAsync- assign role to service account userUnmapRoleFromServiceAccountAsync- remove role from service account user
ISessionService
ListUserSessionsAsync- list user sessionsLogoutUserAsync- logout user/revoke active sessionsRevokeUserSessionsAsync- revoke user sessions (provider alias of logout when applicable)
IGroupService
CreateAsync- create groupGetByIdAsync- get group by idUpdateAsync- update groupDeleteAsync- delete groupListAsync- list groups with pagination/searchAssignRoleAsync- assign realm/client role to groupUnassignRoleAsync- unassign realm/client role from groupAddUserAsync- add user to groupRemoveUserAsync- remove user from group
Logging
App.Auth uses standard ASP.NET Core logging (ILogger<T>) in provider services.
No package-specific logging settings are defined; logging level/output is controlled by your host application's normal logging configuration.
Tests
App.Auth.Tests includes baseline coverage for:
- DI registration and validation behavior for
AddAppAuthand Keycloak configuration requirements - cryptography round-trip for
AuthCryptography.Encrypt/Decrypt - live Keycloak integration tests for
IUserService,IRoleService,ISessionService, andIGroupService
Run tests with:
dotnet test WebTemplate/App.Auth.Tests/App.Auth.Tests.csproj
Live integration tests load credentials from WebTemplate/App.Auth.Tests/appsettings.json (no environment variable fallback):
{
"Integration": {
"Keycloak": {
"BaseUrl": "http://localhost:8180",
"Realm": "cbsua",
"ClientId": "your-client-id",
"ClientSecret": "your-client-secret",
"ManagementClientId": "admin-cli",
"ManagementUsername": "your-management-user",
"ManagementPassword": "your-management-password",
"ManagementAuthRealm": "master"
}
}
}
If required values are empty, integration tests are skipped.
Encrypted secrets in appsettings
Keycloak secrets support encrypted values and are decrypted inside service classes:
Auth:Keycloak:ClientSecretAuth:Keycloak:ManagementClientSecretAuth:Keycloak:ManagementPassword
Store encrypted values as raw cipher text produced by your shared key-based Cryptography.Encrypt(...) mechanism.
For backward compatibility, plain-text values are also accepted.
Keycloak UI setup for management credentials
ManagementClientId, ManagementUsername, and ManagementPassword are used to request an access token for Keycloak Admin API calls.
1) Configure ManagementClientId
- Open Keycloak Admin Console.
- Switch to the realm configured in
ManagementAuthRealm(commonlymaster). - Go to Clients and verify the client exists:
- default:
admin-cli - or your own confidential admin client
- default:
If you use the default client, keep:
"ManagementClientId": "admin-cli"
2) Configure ManagementUsername and ManagementPassword
- In the same
ManagementAuthRealm, go to Users. - Create (or select) an admin/service user.
- Set credentials in Credentials and disable Temporary.
Use those values in appsettings:
"ManagementUsername": "admin-user",
"ManagementPassword": "encrypted-or-plain-password"
3) Grant required permissions
The admin user must be allowed to manage users/roles in the target realm (Auth:Keycloak:Realm).
In the admin user Role mapping, assign appropriate admin roles (names vary by Keycloak version), typically equivalents of:
manage-users,view-users,query-usersmanage-realm,view-realmquery-clients,manage-clients(for client-role operations)
4) Realm alignment checks
ManagementAuthRealm: where management client/user is defined (oftenmaster)Realm: where users/roles are created and managedClientId: target application client for client-role operations
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Katalyst.App.Core (>= 1.2.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.5)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.5)
- Microsoft.Extensions.Http (>= 10.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.5)
- Microsoft.Extensions.Options (>= 10.0.5)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.