Guides OAuth2, OpenID Connect, JWT implementation and token management for securing APIs and web apps. Helps select the correct flow (Authorization Code + PKCE, Client Credentials, Device Code) and harden configuration.
Ships in claude-skills-collection. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
| Flow | Quand l'utiliser | Type client |
|---|---|---|
| Authorization Code + PKCE | App web, SPA, mobile — utilisateur présent | Public ou confidentiel |
| Client Credentials | Service-to-service, daemon, batch | Confidentiel uniquement |
| Device Code | IoT, CLI, smart TV — pas de navigateur | Public |
| Refresh Token | Renouvellement silencieux de l'access token | Tous |
Règle décisive : y a-t-il un utilisateur humain qui s'authentifie ?
Flows à bannir définitivement
// Program.cs
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.Authority = "https://auth.company.com"; // Auto-découverte OIDC
options.Audience = "payment-api";
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ClockSkew = TimeSpan.FromSeconds(30), // Tolérance horaire minimale
ValidIssuers = ["https://auth.company.com"] // Whitelist explicite
};
// Événement de débogage pratique
options.Events = new JwtBearerEvents
{
OnAuthenticationFailed = ctx =>
{
ctx.Response.Headers.Append("WWW-Authenticate-Detail", ctx.Exception.Message);
return Task.CompletedTask;
}
};
});
builder.Services.AddAuthorization(options =>
{
options.AddPolicy("PaymentAdmin", p => p.RequireClaim("role", "payment-admin"));
options.AddPolicy("ReadPayments", p => p.RequireClaim("scope", "payments:read"));
});
// Avec Duende.AccessTokenManagement ou Microsoft.Extensions.Http.OAuth2
builder.Services.AddClientCredentialsTokenManagement()
.AddClient("payment-api", client =>
{
client.TokenEndpoint = "https://auth.company.com/connect/token";
client.ClientId = "order-service";
client.ClientSecret = config["Auth:ClientSecret"]; // Depuis Key Vault, pas appsettings
client.Scope = "payments:write";
});
builder.Services.AddHttpClient<IPaymentClient, PaymentClient>()
.AddClientCredentialsTokenHandler("payment-api");
[Authorize(Policy = "PaymentAdmin")]
[HttpPost("payments")]
public IActionResult CreatePayment(CreatePaymentRequest request)
{
var sub = User.FindFirstValue(ClaimTypes.NameIdentifier); // "sub"
var roles = User.FindAll(ClaimTypes.Role).Select(c => c.Value);
var tenantId = User.FindFirstValue("tenant_id"); // Claim custom
var scopes = User.FindFirstValue("scope")?.Split(' ') ?? [];
// ...
}
eyJhbGciOiJSUzI1NiIsImtpZCI6ImtleS0xMjMifQ ← Header (Base64url)
.eyJpc3MiOiJodHRwczovL2F1dGguY29tcGFueS5jb20iLCAic3ViIjoidXNlci0xMjMiLCAiYXVkIjoicGF5bWVudC1hcGkiLCAiZXhwIjoxNzAwMDAwMDAwLCAiaWF0IjoxNjk5OTk2NDAwLCAic2NvcGUiOiJwYXltZW50czpyZWFkIiwicm9sZSI6InBheW1lbnQtYWRtaW4iLCJ0ZW5hbnRfaWQiOiJ0ZW5hbnQtYWJjIn0= ← Payload
.SIGNATURE ← Signature RS256 (vérifiée avec la clé publique de l'IdP via JWKS)
Claims obligatoires à valider : iss, aud, exp, iat, nbf (si présent).
kid permet la rotation de clés sans downtime (JWKS endpoint).
| Token | Durée recommandée | Stockage côté client |
|---|---|---|
| Access Token | 5–15 min | Mémoire JS (SPA) ou cookie HttpOnly Secure SameSite=Strict |
| Refresh Token | 7–30 jours | Cookie HttpOnly Secure SameSite=Strict uniquement |
| ID Token | 5–15 min | Mémoire — jamais envoyé à une API tierce |
Flux : Client → POST /token (grant_type=refresh_token, token=RT1)
← { access_token, refresh_token: RT2, expires_in }
RT1 est immédiatement invalidé.
Si RT1 est réutilisé → détection de vol → révocation de toute la famille de tokens.
Activer dans Keycloak : Realm Settings → Tokens → Revoke Refresh Token = ON.
kcadm.sh create clients -r myrealm \
-s clientId=order-service \
-s 'protocol=openid-connect' \
-s 'publicClient=false' \
-s 'serviceAccountsEnabled=true' \
-s 'standardFlowEnabled=false' \
-s 'directAccessGrantsEnabled=false'
curl -X POST https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token \
-d "grant_type=client_credentials" \
-d "client_id={clientId}" \
-d "client_secret={secret}" \
-d "scope=https://api.company.com/.default"
# Décoder sans vérifier la signature (debug uniquement)
echo "{JWT}" | cut -d. -f2 | base64 -d 2>/dev/null | jq .
# Vérifier la signature via JWKS
jwt decode --jwks https://auth.company.com/.well-known/jwks.json {JWT}
| Piège | Symptôme | Correction |
|---|---|---|
ClockSkew trop large (> 5 min) | Tokens expirés acceptés | Garder ≤ 30 secondes |
| Audience non validée | N'importe quelle API accepte le token | ValidateAudience = true + Audience explicite |
| Secret partagé entre envs | Compromis prod via dev | Secrets distincts par environnement, rotation trimestrielle |
| Token dans localStorage | Exfiltrable via XSS | Cookie HttpOnly obligatoire |
| Données sensibles dans le payload | PII exposée (Base64 ≠ chiffrement) | Ne mettre que des identifiants opaques dans le JWT |
| RS256 → HS256 downgrade | Validation contournée si secret devinable | Forcer l'algorithme côté serveur, refuser alg:none |
| Access token de longue durée | Surface d'attaque élevée | Max 15 min, refresh token pour la durée de session |
| Pas de révocation | Token volé valide jusqu'à expiration | Implémenter token introspection ou liste de révocation |
state et nonce validés (protection CSRF/replay)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
oauth2, openid-connect, jwt, authentication, identity-provider, token-management
/claude-skills-collection:dev-oauth2-oidc-advisorfrom claude-skills-collection
npx claudepluginhub vantaflow/claude-skills-collection --plugin claude-skills-collection348 skills in this plugin
/agent-a2a-protocol-guideGuide du protocole Agent-to-Agent (A2A) de Google pour l'interopérabilité entre agents IA — découverte, communication et collaboration inter-agents, avec exemples de code, critères de décision et pièges à éviter. Se déclenche avec "A2A", "agent-to-agent", "protocole A2A", "Google A2A", "interopérabilité agents". Also triggers on "agent-to-agent protocol", "agent interoperability", "connect two agents"./agent-agent-observabilityInstrumentation technique d'un agent IA — tracing distribué des appels LLM et outils, spans, métriques custom, corrélation de logs et dashboards de supervision. Pour les alertes et garde-fous de production, voir agent-monitoring-setup. Se déclenche avec "observabilité agent", "tracing agent", "LangSmith", "Langfuse", "OpenTelemetry agent", "spans LLM", "corréler les logs agent". Also triggers on "trace my agent", "LLM tracing", "agent spans"./agent-api-caller-subagentSous-agent spécialisé dans les appels API REST/GraphQL avec retry, auth et transformation de données. Se déclenche avec "sous-agent API", "API caller agent", "agent qui appelle une API", "REST agent", "HTTP agent", "API integration subagent", "external API agent". Also triggers on "subagent that calls an API", "API calling agent", "agent HTTP requests".Other plugins' skills for the same job