Skip to content

Feat/audience - #10

Closed
SebastienLaurent-CF wants to merge 6 commits into
mainfrom
feat/audience
Closed

SebastienLaurent-CF wants to merge 6 commits into
mainfrom
feat/audience

Conversation

@SebastienLaurent-CF

Copy link
Copy Markdown
Contributor

✨ Add optional audience parameter for token requests

Why

Some providers need an audience (or API identifier) on the token request to issue an access token for a given API. Without it, Auth0 returns an opaque token instead of a JWT, or rejects the Client Credentials request. Okta custom authorization servers and some Keycloak setups also rely on it. authk had no way to send this parameter.

What

  • Config: new optional oidc.audience field (CUE schema + OIDCConfig).
  • Client Credentials flow: the audience is sent through clientcredentials.Config.EndpointParams.
  • Password flow: oauth2.Config.PasswordCredentialsToken does not accept extra parameters, so a dedicated passwordCredentialsToken sends the request when an audience is set. It:
    • supports basic, post and none (public client) auth methods
    • keeps refresh_token, expiry and id_token (token extras)
    • returns *oauth2.RetrieveError on error, like the library
  • Refresh: unchanged; providers keep the audience of the original grant.
  • Docs: audience added to the README config example, plus a new Auth0 example.

Configs without audience keep using the library code path, so their behaviour is unchanged.

Example

oidc: {
        issuerUrl:    "https://my-tenant.eu.auth0.com/"
        clientId:     "my-client"
        clientSecret: "my-secret"
        audience:     "https://api.example.com"
}

Tests

- TestClient_GetToken_Audience: Client Credentials, and Password with basic, post and public client auth; checks the audience is sent, client credentials, scopes, expiry, id_token extra, and an error response mapped to RetrieveError.
- TestLoad_Audience: the field is loaded from the CUE config.
- go test ./... passes.

Notes

- Based on feat/public-client: merge that one first, or retarget this PR to main once it is merged.
- Out of scope: the CUE schema still rejects client_secret_basic and client_secret_post for authMethod, although the Go code accepts them

- Update configuration schema and Go structs to include idTokenKey
- Support saving ID tokens to .env files when configured
- Add --id-token flag to get command for direct output
- Add --id-token flag to inspect command for decoding
- Make ID token verification non-fatal to increase robustness
- Add unit tests for config loading and OIDC token handling
- Update README.md with new configuration options and flags
- Refactor `targets` schema to use `type` field instead of `idTokenKey`
- Update `inspect` command to intelligently resolve files and keys from the targets list
- Improve documentation for multiple target files and fix invalid examples in README
- Maintain backward compatibility for simple configuration via `tokenKey` and `idTokenKey`
- Make clientSecret optional and add "none" authMethod
- Send client_id in request body without secret for public clients
- Reject client_credentials flow when no secret is configured
- Add config and OIDC tests for public client behaviour
- Document Keycloak public client setup in README
- Add optional `oidc.audience` to config schema and OIDCConfig
- Send audience in Client Credentials flow via endpoint params
- Implement Password grant with audience (unsupported by x/oauth2)
- Add tests for all auth methods, error response and config loading
- Document audience option with an Auth0 example in README
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant