kc token
Overview
The kc token command obtains OIDC tokens using the authorization code flow. It opens a browser for user authentication and returns access, refresh, and ID tokens.
- The ID token signature is checked against the server key.
- If Access Token is in JWT form, its signature is checked against the server key.
- If Access Token is in opaque form, it is checked against server introspection endpoint.
Syntax
Flags
--issuerURL
The Kubauth OIDC issuer URL.
Example: --issuerURL https://kubauth.example.com
Value may also be fetched from KC_ISSUER_URL environment variable, or Kubernetes kubeconfig if kc init .... has been used.
--clientId
The OIDC client ID to use for authentication.
Example: --clientId public
Value may also be fetched from KC_CLIENT_ID environment variable, or Kubernetes kubeconfig if kc init .... has been used.
--clientSecret
The client secret (for confidential clients).
Example: --clientSecret mysecret123
Value may also be fetched from KC_CLIENT_SECRET environment variable, or Kubernetes kubeconfig if kc init .... has been used.
--insecureSkipVerify
Skip TLS certificate verification. Use only for testing with self-signed certificates.
Example: --insecureSkipVerify
--caFile
Provide a CA file for TLS certificate verification of ìssuerURL
Example: --caFile ./CA.crt
--onlyIdToken
Output only the ID token (base64-encoded JWT). Useful for piping to other commands or scripts.
Example: --onlyIdToken
--onlyAccessToken
Output only the access token (base64-encoded). Useful for piping to other commands or scripts.
Example: --onlyAccessToken
-d, --detailIdToken
Decode and display the JWT OIDC token payload. This is equivalent to kc token .... --onlyIdToken | kc jwt.
Example: -d
-a, --detailAccessToken
Decode and display the JWT Access token payload. This is equivalent to kc token .... --onlyAccessToken | kc jwt.
Example: -a
The Kubauth server must be configured to generate AccessToken in JWT form.
--scope
List of OAuth2 scopes to request.
Default: openid profile groups offline
Example: --scope "openid" --scope "profile" --scope "email" --scope "groups"
Warning
In its current version, Kubauth does not manage scopes. All claims are included in the JWT token.
-p, bindPort
Local web server bind port.
Default: 9921
--pkce
Use PKCE (Proof Key for Code Exchange) for enhanced security.
--browser
Override default browser. Possible values:
chromefirefoxsafari
Examples
Basic Usage
output:
Output: (After successful login)
Access token: ory_at_xLUfAhEGpFVWpMLdNEDZAj94hHFrHWjgOYB5g0Leh_k...
Refresh token: ory_rt_nU9NBZs4NtKTxVYVko1aqlJkAMF5MLBYjfiZbhVt9aE...
ID token: eyJhbGciOiJSUzI1NiIsImtpZCI6ImY0Y2NkNDU0LWYzYTgtNDQ3Zi1hN2MzLTY...
Expire in: 59m59s
With Decoded Token
Output:
Access token: ory_at_...
Refresh token: ory_rt_...
ID token: eyJhbG...
Expire in: 59m59s
JWT Payload:
{
"aud": ["public"],
"auth_time": 1763573723,
"auth_time_human": "2025-11-19 17:35:23 UTC",
"azp": "public",
"email": "john@example.com",
"emails": ["john@example.com"],
"exp": 1763577323,
"exp_human": "2025-11-19 18:35:23 UTC",
"groups": ["developers", "ops"],
"iat": 1763573723,
"iat_human": "2025-11-19 17:35:23 UTC",
"iss": "https://kubauth.example.com",
"name": "John DOE",
"sub": "john"
}
Only ID Token (for Piping)
Output:
eyJhbGciOiJSUzI1NiIsImtpZCI6ImY0Y2NkNDU0LWYzYTgtNDQ3Zi1hN2MzLTY3ZmY5MzUxMzZiMSIsInR5cCI6IkpXVCJ9.eyJhdF9oYXNoIjoiaGNBY2dtdmdBekJlSGgyODlkWHF3USIsImF1ZCI6WyJwdWJsaWMiXSwi...
Pipe to JWT Decoder
Behavior
Browser Flow
- Local Server Started -
kcstarts a local HTTP server on a localhost port - Browser Opens - Your default browser opens to the Kubauth login page
- User Authenticates - You log in with your credentials
- Callback Received - Kubauth redirects back to the local server with an authorization code
- Token Exchange -
kcexchanges the code for tokens - Display Results - Tokens are displayed in the terminal
Token Storage
Tokens are displayed but not automatically stored. If you need to save them:
# Save ID token to variable
ID_TOKEN=$(kc token --issuerURL https://kubauth.example.com --clientId public --onlyIdToken)
# Save to file
kc token --issuerURL https://kubauth.example.com --clientId public --onlyIdToken > token.txt
SSO Session
If you previously checked "Remember me" on the login page, subsequent kc token commands will complete automatically without requiring you to log in again (SSO session active).
To clear the SSO session:
Troubleshooting
Browser Doesn't Open
If the browser doesn't open automatically:
- Check the terminal output for the URL
- Manually copy and paste it into your browser
- Or use
kc token-nuifor terminal-based authentication
Example:
TLS Certificate Errors
Error:
Solutions:
- Use
--insecureSkipVerifyfor testing (not recommended for production) - Use
--caFile ./ca.crt. To extract the CA: - Add this CA certificate to system trust store.
Security Considerations
- Don't Expose Tokens - Be careful when displaying or logging tokens
- Use HTTPS - Always use HTTPS for the issuer URL in production
- Verify Certificates - Only use
--insecureSkipVerifyfor testing - Token Lifetime - Tokens expire quickly by design; request new ones as needed
- Client Secrets - Never commit client secrets to version control
Related Commands
kc token-nui- Non-interactive authentication (no browser)kc jwt- Decode JWT tokenskc logout- Clear SSO sessionkc whoami- Display current user information