-
Notifications
You must be signed in to change notification settings - Fork 968
docs: add more specific steps and information about oidc refresh tokens #18336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
56158b8
add offline_access scope
EdwardAngert 566fe99
md fixes and lots of offline_access notes
EdwardAngert 2f07f99
Merge branch 'main' into 18307-refresh-tokens
EdwardAngert e69afa5
move external auth to own directory
EdwardAngert 1030bd6
Merge branch 'main' into 18307-refresh-tokens
EdwardAngert 7a92bde
relative link
EdwardAngert 290b8ab
new refresh tokens doc
EdwardAngert 2a816e6
Merge branch 'main' into 18307-refresh-tokens
EdwardAngert a92ad17
put the comma back
EdwardAngert cc0e46f
move refresh tokens to oidc
EdwardAngert d951736
add azure and pf, reorg doc
EdwardAngert 0438aad
token config troubleshooting clarify
EdwardAngert bbbd751
md lint ignore heading levels
EdwardAngert 2618ffa
remove from idp-sync
EdwardAngert 4dedaf1
add configure section to oidc-auth
EdwardAngert 5d863cc
Merge branch 'main' into 18307-refresh-tokens
EdwardAngert 2ef836d
relative links
EdwardAngert f737eb5
remove note because it doesn't like being nested
EdwardAngert 6ad5822
Merge branch 'main' into 18307-refresh-tokens
EdwardAngert 1984341
separate general/google in troubleshooting
EdwardAngert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
# Configure OIDC refresh tokens | ||
|
||
OIDC refresh tokens allow your Coder deployment to maintain user sessions beyond the initial access token expiration. | ||
Without properly configured refresh tokens, users will be automatically logged out when their access token expires. | ||
This is typically after one hour, but varies by provider, and can disrupt the user's workflow. | ||
|
||
> [!IMPORTANT] | ||
> Misconfigured refresh tokens can lead to frequent user authentication prompts. | ||
> | ||
> After the admin enables refresh tokens, all existing users must log out and back in again to obtain a refresh token. | ||
|
||
<div class="tabs"> | ||
|
||
### Azure AD | ||
|
||
Go to the Azure Portal > **Azure Active Directory** > **App registrations** > Your Coder app and make the following changes: | ||
|
||
1. In the **Authentication** tab: | ||
|
||
- **Platform configuration** > Web | ||
- Ensure **Allow public client flows** is `No` (Coder is confidential) | ||
- **Implicit grant / hybrid flows** can stay unchecked | ||
|
||
1. In the **API permissions** tab: | ||
|
||
- Add the built-in permission `offline_access` under **Microsoft Graph** > **Delegated permissions** | ||
- Keep `openid`, `profile`, and `email` | ||
|
||
1. In the **Certificates & secrets** tab: | ||
|
||
- Verify a Client secret (or certificate) is valid. | ||
Coder uses it to redeem refresh tokens. | ||
|
||
1. In your [Coder configuration](../../../reference/cli/server.md#--oidc-auth-url-params), request the same scopes: | ||
|
||
```env | ||
CODER_OIDC_SCOPES=openid,profile,email,offline_access | ||
``` | ||
|
||
1. Restart Coder and have users log out and back again for the changes to take effect. | ||
|
||
Alternatively, you can force a sign-out for all users with the | ||
[sign-out request process](https://learn.microsoft.com/en-us/entra/identity-platform/v2-protocols-oidc#send-a-sign-out-request). | ||
|
||
1. Azure issues rolling refresh tokens with a default absolute expiration of 90 days and inactivity expiration of 24 hours. | ||
|
||
You can adjust these settings under **Authentication methods** > **Token lifetime** (or use Conditional-Access policies in Entra ID). | ||
|
||
> [!NOTE] | ||
> You don't need to configure the 'Expose an API' section for refresh tokens to work. | ||
|
||
Learn more in the [Microsoft Entra documentation](https://learn.microsoft.com/en-us/entra/identity-platform/v2-protocols-oidc#enable-id-tokens). | ||
|
||
|
||
To ensure Coder receives a refresh token when users authenticate with Google directly, set the `prompt` to `consent` | ||
in the auth URL parameters (`CODER_OIDC_AUTH_URL_PARAMS`). | ||
Without this, users will be logged out when their access token expires. | ||
|
||
In your [Coder configuration](../../../reference/cli/server.md#--oidc-auth-url-params): | ||
|
||
```env | ||
CODER_OIDC_SCOPES=openid,profile,email | ||
CODER_OIDC_AUTH_URL_PARAMS='{"access_type": "offline", "prompt": "consent"}' | ||
``` | ||
|
||
### Keycloak | ||
|
||
The `access_type` parameter has two possible values: `online` and `offline`. | ||
By default, the value is set to `offline`. | ||
|
||
This means that when a user authenticates using OIDC, the application requests offline access to the user's resources, | ||
including the ability to refresh access tokens without requiring the user to reauthenticate. | ||
|
||
Add the `offline_access` scope to enable refresh tokens in your | ||
[Coder configuration](../../../reference/cli/server.md#--oidc-auth-url-params): | ||
|
||
```env | ||
CODER_OIDC_SCOPES=openid,profile,email,offline_access | ||
CODER_OIDC_AUTH_URL_PARAMS='{"access_type":"offline"}' | ||
``` | ||
|
||
### PingFederate | ||
|
||
1. In PingFederate go to **Applications** > **OAuth Clients** > Your Coder client. | ||
|
||
1. On the **Client** tab: | ||
|
||
- **Grant Types**: Enable `refresh_token` | ||
- **Allowed Scopes**: Add `offline_access` and keep `openid`, `profile`, and `email` | ||
|
||
1. Optionally, in **Token Settings** | ||
|
||
- **Refresh Token Lifetime**: set a value that matches your security policy. Ping's default is 30 days. | ||
- **Idle Timeout**: ensure it's more than or equal to the lifetime of the access token so that refreshes don't fail prematurely. | ||
|
||
1. Save your changes in PingFederate. | ||
|
||
1. In your [Coder configuration](../../../reference/cli/server.md#--oidc-scopes), add the `offline_access` scope: | ||
|
||
```env | ||
CODER_OIDC_SCOPES=openid,profile,email,offline_access | ||
``` | ||
|
||
1. Restart your Coder deployment to apply these changes. | ||
|
||
Users must log out and log in once to store their new refresh tokens. | ||
After that, sessions should last until the Ping Federate refresh token expires. | ||
|
||
Learn more in the [PingFederate documentation](https://docs.pingidentity.com/pingfederate/12.2/administrators_reference_guide/pf_configuring_oauth_clients.html). | ||
|
||
</div> | ||
|
||
## Confirm refresh token configuration | ||
|
||
To verify refresh tokens are working correctly: | ||
|
||
1. Check that your OIDC configuration includes the required refresh token parameters: | ||
|
||
- `offline_access` scope for most providers | ||
- `"access_type": "offline"` for Google | ||
|
||
1. Verify provider-specific token configuration: | ||
|
||
<div class="tabs"> | ||
|
||
### Azure AD | ||
|
||
Use [jwt.ms](https://jwt.ms) to inspect the `id_token` and ensure the `rt_hash` claim is present. | ||
This shows that a refresh token was issued. | ||
|
||
|
||
If users are still being logged out periodically, check your client configuration in Google Cloud Console. | ||
|
||
### Keycloak | ||
|
||
Review Keycloak sessions for the presence of refresh tokens | ||
|
||
### Ping Federate | ||
|
||
- Verify the client sent `offline_access` in the `grantedScopes` portion of the ID token | ||
- Confirm `refresh_token` appears in the `grant_types` list returned by `/pf-admin-api/v1/oauth/clients/{id}` | ||
|
||
</div> | ||
|
||
1. Verify users can stay logged in beyond the identity provider's access token expiration period (typically 1 hour). | ||
|
||
1. Monitor Coder logs for `failed to renew OIDC token: token has expired` messages. | ||
There should not be any. | ||
|
||
If all verification steps pass successfully, your refresh token configuration is working properly. | ||
|
||
## Troubleshooting OIDC Refresh Tokens | ||
|
||
### Users are logged out too frequently | ||
EdwardAngert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
**Symptoms**: | ||
|
||
- Users experience session timeouts and must re-authenticate | ||
- Session timeouts typically occur after the access token expiration period (varies by provider, commonly 1 hour) | ||
|
||
**Causes**: | ||
|
||
- Missing `offline_access` scope in `CODER_OIDC_SCOPES` | ||
- Provider not configured to issue refresh tokens | ||
EdwardAngert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- User has not logged in since refresh token configuration was added | ||
|
||
**Solution**: | ||
|
||
- Add `offline_access` to your `CODER_OIDC_SCOPES` configuration | ||
- Configure your identity provider according to the provider-specific instructions above | ||
- Have users log out and log in again to obtain refresh tokens. | ||
Look for entries containing `failed to renew OIDC token` which might indicate specific provider issues. | ||
|
||
Users might get logged out again before the new configuration takes effect completely. | ||
|
||
### Refresh tokens don't work after configuration change | ||
|
||
**Symptoms**: | ||
|
||
- Session timeouts continue despite refresh token configuration and users re-authenticating | ||
- Some users experience frequent logouts | ||
|
||
**Cause**: | ||
|
||
- Existing user sessions don't have refresh tokens stored | ||
- Configuration may be incomplete | ||
|
||
**Solution**: | ||
|
||
- Users must log out and log in again to get refresh tokens stored in the database | ||
- Verify you've correctly configured your provider as described in the configuration steps above | ||
- Check Coder logs for specific error messages related to token refresh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.