Libraries
Nod speaks standard OpenID Connect and OAuth 2.0, so your language's usual library works unchanged. These are the ones tested against a real Nod on every change to the interop run (scripts/interop, see development), at exactly these versions, each used the way its own docs say:
| Language | Library | Version tested | Checked |
|---|---|---|---|
| Node | openid-client, with jose for APIs | 6.9.0, 6.2.17 | discovery, code flow with PKCE, RS256 and EdDSA ID tokens, RFC 9207 iss, userinfo, refresh with reuse refused, introspection, revocation, client credentials, PAR, DPoP, access tokens checked by an API |
| Python | Authlib | 1.6.12 | code flow with PKCE, ID tokens (CodeIDToken, RS256 and EdDSA, at_hash), userinfo, refresh with reuse refused, introspection, revocation, client credentials |
| Go | go-oidc with golang.org/x/oauth2 | 3.14.1, 0.30.0 | discovery, code flow with PKCE, RS256 and EdDSA ID tokens, RFC 9207 iss, userinfo, refresh, client credentials |
| Rust | openidconnect | 4.0.1 | discovery, code flow with PKCE, RS256 and EdDSA ID tokens, at_hash, RFC 9207 iss, userinfo, refresh, client credentials |
| Java | Nimbus OAuth 2.0 SDK (what Spring Security builds on) | 11.26 | discovery, code flow with PKCE, RS256 ID tokens (IDTokenValidator) and at_hash, RFC 9207 iss, userinfo, refresh with reuse refused, client credentials |
| .NET | Duende OidcClient with IdentityModel | 7.1.1, 8.1.0 | code flow with PKCE, ID tokens validated by OidcClient, RFC 9207 iss, discovery's issuer check, userinfo, refresh with reuse refused, client credentials with resource, a wrong secret refused |
Frameworks built on these (Spring Security on Nimbus, Authlib's Django and Flask integrations) talk to Nod through the same code, though they aren't tested here themselves.
What every library needs
- The issuer,
https://auth.example.com/<realm>. Libraries discover everything else from<issuer>/.well-known/openid-configurationand check that the issuer in it matches. - PKCE with S256. Nod requires it for public clients and accepts it from confidential ones;
plainis refused. Every library above does this when asked (most by default). - Store the new refresh token every time. Refresh tokens rotate on use, and using an old one revokes the whole grant (it is how a stolen token is caught). Libraries hand you the new one with the new access token.
- For an API's access token, name the API: pass
resource=<the API's identifier>(RFC 8707). Without it, the access token is for userinfo only. - EdDSA: a client registered with
--eddsagets Ed25519-signed ID tokens. openid-client, Authlib, go-oidc and openidconnect verify them; Nimbus does only with Google Tink added. Use the default (RS256) with any library you aren't sure of. - **The
isson the way back** (RFC 9207) protects against mix-up between providers. Libraries that check it (all of the above) need nothing set.
Snippets
Each is cut from the tested driver; the drivers in scripts/interop show the whole flow, refresh and client credentials included. The Node and Python ones are in the quickstart.
Go (go-oidc and x/oauth2):
provider, err := oidc.NewProvider(ctx, "https://auth.example.com/acme")
conf := &oauth2.Config{ClientID: "web", ClientSecret: secret, Endpoint: provider.Endpoint(),
RedirectURL: "https://app.example.com/cb", Scopes: []string{oidc.ScopeOpenID, "profile", "email"}}
verifier := oauth2.GenerateVerifier()
url := conf.AuthCodeURL(state, oidc.Nonce(nonce), oauth2.S256ChallengeOption(verifier))
// … the callback:
tok, err := conf.Exchange(ctx, code, oauth2.VerifierOption(verifier))
idt, err := provider.Verifier(&oidc.Config{ClientID: "web"}).Verify(ctx, tok.Extra("id_token").(string))
// check idt.Nonce == nonce, and idt.VerifyAccessToken(tok.AccessToken) when at_hash is present
Rust (openidconnect):
let meta = CoreProviderMetadata::discover_async(IssuerUrl::new(issuer)?, &http).await?;
let client = CoreClient::from_provider_metadata(meta, ClientId::new("web".into()), Some(ClientSecret::new(secret)))
.set_redirect_uri(RedirectUrl::new("https://app.example.com/cb".into())?);
let (challenge, verifier) = PkceCodeChallenge::new_random_sha256();
let (url, state, nonce) = client
.authorize_url(CoreAuthenticationFlow::AuthorizationCode, CsrfToken::new_random, Nonce::new_random)
.add_scope(Scope::new("email".into()))
.set_pkce_challenge(challenge)
.url();
// … the callback:
let tokens = client.exchange_code(AuthorizationCode::new(code))?.set_pkce_verifier(verifier).request_async(&http).await?;
let claims = tokens.id_token().unwrap().claims(&client.id_token_verifier(), &nonce)?;
Build the HTTP client without following redirects, as the crate's docs advise (against SSRF).
Java (Nimbus):
var op = OIDCProviderMetadata.resolve(new Issuer("https://auth.example.com/acme"));
var request = new AuthenticationRequest.Builder(new ResponseType(ResponseType.Value.CODE),
new Scope("openid", "profile", "email"), new ClientID("web"), callback)
.endpointURI(op.getAuthorizationEndpointURI()).state(state).nonce(nonce)
.codeChallenge(verifier, CodeChallengeMethod.S256).build();
// … the callback:
var ok = AuthorizationResponse.parse(callbackUri).toSuccessResponse(); // check ok.getState() and ok.getIssuer()
var tokenRequest = new TokenRequest.Builder(op.getTokenEndpointURI(),
new ClientSecretBasic(new ClientID("web"), new Secret(secret)),
new AuthorizationCodeGrant(ok.getAuthorizationCode(), callback, verifier)).build();
var tokens = ((OIDCTokenResponse) OIDCTokenResponseParser.parse(tokenRequest.toHTTPRequest().send())
.toSuccessResponse()).getOIDCTokens();
var claims = new IDTokenValidator(op.getIssuer(), new ClientID("web"), JWSAlgorithm.RS256, op.getJWKSetURI().toURL())
.validate(tokens.getIDToken(), nonce);
Spring Boot apps should get the same (Spring itself isn't in the run; Nimbus, which it uses, is) with spring-boot-starter-oauth2-client and spring.security.oauth2.client.provider.harpora.issuer-uri=https://auth.example.com/acme.
.NET (Duende OidcClient):
var client = new OidcClient(new OidcClientOptions {
Authority = "https://auth.example.com/acme", ClientId = "web", ClientSecret = secret,
RedirectUri = "https://app.example.com/cb", Scope = "openid profile email offline_access" });
var state = await client.PrepareLoginAsync(); // PKCE, state and nonce: send the browser to state.StartUrl
// … the callback:
var result = await client.ProcessResponseAsync(callbackUrl, state); // the ID token validated; result.User
var refreshed = await client.RefreshTokenAsync(result.RefreshToken); // store refreshed.RefreshToken: it rotated
An API's token, for a service: RequestClientCredentialsTokenAsync with Resource = { "https://api.example.com" }. Nod answers a wrong secret sent with Basic authentication with 401 and invalid_client, as RFC 6749 §5.2 requires; IdentityModel then reports the HTTP error, and the body is in response.Json.
Not here yet
Libraries for PHP, Ruby, Swift and Kotlin aren't in the interop run yet. Any certified OpenID Connect relying-party library should work; if one doesn't, it is a bug in Nod we want to hear about.