Agent skill
jwt-auth
Configure JWT Bearer authentication with Keycloak for affolterNET.Web.Api. Use when setting up token validation, Keycloak integration, or API authentication.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/security/jwt-auth-mcafee123-affolternet-web
SKILL.md
JWT Bearer Authentication
Configure JWT Bearer authentication with Keycloak integration.
For complete reference, see Library Guide.
Quick Start
appsettings.json
{
"affolterNET": {
"Web": {
"Auth": {
"Provider": {
"Authority": "https://keycloak.example.com/realms/myrealm",
"ClientId": "my-api-client",
"ClientSecret": "your-client-secret"
}
}
}
}
}
Program.cs
var options = builder.Services.AddApiServices(isDev, builder.Configuration, opts => {
opts.ConfigureApi = api => {
api.AuthMode = AuthenticationMode.Authenticate;
};
});
Authentication Modes
| Mode | Description |
|---|---|
None |
No authentication required |
Authenticate |
Valid JWT required, no permission checks |
Authorize |
Valid JWT + Keycloak RPT permissions required |
Configuration Options
AuthProviderOptions
| Property | Description |
|---|---|
Authority |
Keycloak realm URL |
ClientId |
OIDC client identifier |
ClientSecret |
OIDC client secret |
Audience |
Expected JWT audience (optional) |
Permission-Based Authorization
When using AuthenticationMode.Authorize:
[Authorize(Policy = "admin-resource")]
[HttpGet("admin")]
public IActionResult AdminOnly() { ... }
// Multiple permissions (comma-separated, any match)
[Authorize(Policy = "resource1,resource2")]
[HttpGet("multi")]
public IActionResult MultiPermission() { ... }
Claims Enrichment
The API automatically enriches claims with:
- Standard JWT claims
- Aggregated roles from
ClaimTypes.Roleand"roles"claims - Permissions from RPT tokens (when AuthMode is Authorize)
Troubleshooting
Token validation fails
- Verify
AuthorityURL is correct and accessible - Check that
ClientIdmatches the Keycloak client - Ensure the JWT audience matches if configured
Permissions not recognized
- Confirm
AuthModeis set toAuthorize - Verify Keycloak client has authorization services enabled
- Check that resources and policies are configured in Keycloak
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?