This guide describes the primary token flows supported by TokenSmith and when to use each one.
TokenSmith supports two main token acquisition paths:
- Upstream OIDC flow (primary): Delegate authentication to an external OIDC provider (e.g., Keycloak, Azure AD, Dex).
- Local user token flow (break-glass): Generate tokens directly for local users when upstream OIDC is unavailable or for administrative access.
This is the standard and recommended flow for production deployments.
- Client initiates login or requests a resource.
- Client is redirected to the upstream OIDC provider (issuer).
- OIDC provider authenticates the user.
- Client receives an authorization code from the upstream OIDC provider.
- Client exchanges the authorization code with TokenSmith using the RFC 8693 token exchange endpoint.
- TokenSmith validates the code with the upstream OIDC provider and returns a TokenSmith JWT.
- Client uses the TokenSmith JWT to access services.
- Upstream OIDC provider must be reachable from TokenSmith.
- TokenSmith must be configured with the OIDC issuer URL, client ID, and client secret.
- The OIDC provider must support standard discovery (
.well-known/openid-configuration).
# Environment variables
export OIDC_ISSUER_URL="https://keycloak.example.com/realms/master"
export OIDC_CLIENT_ID="tokensmith"
export OIDC_CLIENT_SECRET="<secret>"
# Start TokenSmith
tokensmith serveYou can reconfigure the upstream OIDC provider without restarting TokenSmith using the CLI:
tokensmith oidc configure \
--issuer-url "https://new-provider.example.com" \
--client-id "new-client-id" \
--replace-existingThis is useful for:
- Migrating to a new OIDC provider
- Failover scenarios (switch to a backup provider)
- Testing a new provider configuration before full rollout
See CLI reference for the complete oidc configure command.
This flow is designed for emergency access when upstream OIDC is unavailable. It should not be used as the primary authentication method.
- Operator runs the
tokensmith user-token createcommand with a username and scopes. - TokenSmith generates a JWT directly (no upstream provider required).
- Operator provides the JWT to a user or service.
- Client uses the TokenSmith JWT to access services.
- TokenSmith must be started with
--enable-local-user-mint. - Operator must have local access to the TokenSmith instance (or access via local HTTP endpoint).
- Upstream OIDC is down: Temporary break-glass access while OIDC provider is recovering.
- Initial bootstrapping: Set up admin accounts before OIDC is available.
- Testing: Mint test tokens without involving a full OIDC provider.
# Start TokenSmith with local user minting enabled
tokensmith serve --enable-local-user-mint
# In a separate terminal, mint an admin token
tokensmith user-token create \
--subject "admin-breakglass" \
--scopes "admin,audit" \
--enable-local-user-mint# Day 1: Start with local user minting
tokensmith serve --enable-local-user-mint
# Create initial admin account
tokensmith user-token create \
--subject "admin@example.com" \
--scopes "admin" \
--enable-local-user-mint
# Configure the OIDC provider
tokensmith oidc configure \
--issuer-url "https://keycloak.example.com" \
--client-id "tokensmith" \
--replace-existing
# Now stop TokenSmith and restart without --enable-local-user-mint
# (Optional) Disable local user minting in production:
tokensmith serve # no flag = local user minting disabled| Aspect | Upstream OIDC | Local User Token |
|---|---|---|
| Primary use | Standard authentication | Emergency access / bootstrap |
| Provider dependency | Yes (required) | No |
| User identity | From upstream provider | Locally managed |
| Security context | Shared with OIDC ecosystem | Isolated to TokenSmith |
| Auditability | Yes (upstream + TokenSmith logs) | Requires local audit logs |
| Scalability | Suitable for production | Not for production scale |
| Start flag | (None) | --enable-local-user-mint |
-
Do you have an external OIDC provider (Keycloak, Azure AD, Okta, etc.)?
- Yes → Use upstream OIDC flow
- No → Go to step 2
-
Do you need to bootstrap a new TokenSmith instance or handle a temporary outage?
- Yes → Use local user token flow with
--enable-local-user-mint - No → Wait for OIDC provider to be available
- Yes → Use local user token flow with
-
Is the OIDC provider currently unavailable?
- Yes → Temporarily use local user token flow
- No → Return to upstream OIDC flow
- Start TokenSmith with local user minting:
tokensmith serve --enable-local-user-mint - Mint initial admin token:
tokensmith user-token create ... - Configure OIDC provider:
tokensmith oidc configure ... - Restart TokenSmith without
--enable-local-user-mint(or rely on env startup config)
- Verify upstream OIDC is down.
- Start a temporary TokenSmith instance with
--enable-local-user-mint(or use an existing instance if it was started with the flag). - Mint break-glass tokens for critical operations.
- After OIDC recovery, retire the break-glass tokens.
- Configure the new provider:
tokensmith oidc configure --issuer-url <new> --client-id <new> --replace-existing - No restart required; TokenSmith immediately uses the new provider.
- No downtime; existing connections are not interrupted.
- CLI Reference —
oidc configure,oidc status,user-token createcommands - HTTP Endpoints — Local admin endpoints for OIDC configuration
- Environment Reference — OIDC environment variables and startup behavior
- Getting Started — Step-by-step setup guide
- Security Notes — Security considerations for local user minting and admin endpoints