Skip to content

Add client-level default token audience config - #4198

Merged
thiva-k merged 1 commit into
thunder-id:mainfrom
thiva-k:default-oauth-aud
Jul 21, 2026
Merged

Add client-level default token audience config#4198
thiva-k merged 1 commit into
thunder-id:mainfrom
thiva-k:default-oauth-aud

Conversation

@thiva-k

@thiva-k thiva-k commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Purpose

Fixes #3725. Access tokens that aren't bound to a resource server (OIDC-only or scopeless requests) defaulted their aud claim to the client_id, which is ambiguous and deviates from RFC 9068 (the client isn't the audience). This adds a configurable default audience per application/agent for exactly those unbound tokens.

Approach

  • New optional token.accessToken.defaultAudience on OAuth applications and agents.
  • When a request resolves to no resource server (no resource parameter and no permission scopes), the access token's aud uses this value, falling back to client_id when unset. Resource-bound tokens are unaffected; they still get the resource server identifier. Precedence: explicit resourcedefaultResourceServer → per-app defaultAudienceclient_id.
  • Applied uniformly across all grants that mint access tokens (authorization_code, client_credentials, jwt_bearer, token_exchange, ciba); refresh tokens inherit the original binding.
  • Console: free-text field under Advanced Settings for both applications and agents.

Related Issues

Summary by CodeRabbit

  • New Features

    • Added defaultAudience configuration for access tokens when no resource server is targeted (aud falls back to client ID when unset).
    • Updated token flows so OIDC-only/scopeless requests use the configured default audience, while resource-bound requests still use the resolved resource server audience.
    • Added console UI controls for setting default token audience (application and agent advanced settings).
  • Documentation

    • Updated OAuth/OIDC, token, resource indicators, CIBA, token exchange, and authentication guides to reflect the new aud claim behavior.
  • Tests

    • Added unit and integration tests covering configured default audience behavior and resource override.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@thiva-k, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 25 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e3944d36-acf4-4899-a9ea-7801887d3c60

📥 Commits

Reviewing files that changed from the base of the PR and between 9556bb9 and 6ab6d6d.

📒 Files selected for processing (31)
  • api/agent.yaml
  • api/application.yaml
  • backend/internal/inboundclient/error_constants.go
  • backend/internal/inboundclient/service.go
  • backend/internal/inboundclient/service_test.go
  • backend/internal/oauth/oauth2/granthandlers/authorization_code.go
  • backend/internal/oauth/oauth2/granthandlers/ciba.go
  • backend/internal/oauth/oauth2/granthandlers/ciba_test.go
  • backend/internal/oauth/oauth2/granthandlers/client_credentials.go
  • backend/internal/oauth/oauth2/granthandlers/client_credentials_test.go
  • backend/internal/oauth/oauth2/granthandlers/jwt_bearer.go
  • backend/internal/oauth/oauth2/granthandlers/token_exchange.go
  • backend/pkg/thunderidengine/providers/model.go
  • backend/pkg/thunderidengine/providers/oauth_client.go
  • backend/pkg/thunderidengine/providers/oauth_client_test.go
  • docs/content/guides/getting-started/configuration.mdx
  • docs/content/guides/guides/agents/agent-authentication.mdx
  • docs/content/guides/guides/identity-providers/token-exchange-idp.mdx
  • docs/content/guides/guides/protocols/oauth-oidc/authorization-code.mdx
  • docs/content/guides/guides/protocols/oauth-oidc/backchannel-authentication.mdx
  • docs/content/guides/guides/protocols/oauth-oidc/client-credentials.mdx
  • docs/content/guides/guides/protocols/oauth-oidc/resource-indicators.mdx
  • docs/content/guides/guides/protocols/oauth-oidc/token-exchange.mdx
  • docs/content/guides/key-concepts/tokens.mdx
  • frontend/apps/console/src/features/agents/components/edit-agent/advanced-settings/EditAdvancedSettings.tsx
  • frontend/apps/console/src/features/applications/components/edit-application/advanced-settings/AudienceSection.tsx
  • frontend/apps/console/src/features/applications/components/edit-application/advanced-settings/EditAdvancedSettings.tsx
  • frontend/apps/console/src/features/applications/components/edit-application/advanced-settings/__tests__/AudienceSection.test.tsx
  • frontend/apps/console/src/features/applications/models/token.ts
  • frontend/packages/i18n/src/locales/en-US.ts
  • tests/integration/oauth/token/default_resource_server_test.go
📝 Walkthrough

Walkthrough

Adds configurable default audiences for unbound access tokens, propagates the setting through OAuth configuration, applies it across grant handlers with client ID fallback, exposes it in the console, updates documentation, and adds unit and integration coverage.

Changes

Default Audience Configuration

Layer / File(s) Summary
Audience configuration contract and propagation
api/*.yaml, backend/pkg/thunderidengine/providers/*, backend/internal/inboundclient/*, frontend/apps/console/src/features/applications/models/token.ts
Adds defaultAudience to API and application models and preserves it during inbound OAuth configuration resolution.
Default audience resolution across grants
backend/internal/oauth/oauth2/granthandlers/*, backend/pkg/thunderidengine/providers/oauth_client.go
Resolves configured default audiences with client_id fallback for unbound authorization code, CIBA, client credentials, JWT bearer, and token exchange flows; resource-bound requests retain resource audiences.
Grant-flow and integration validation
backend/internal/oauth/oauth2/granthandlers/*_test.go, backend/pkg/thunderidengine/providers/oauth_client_test.go, tests/integration/oauth/token/default_resource_server_test.go
Tests configured audiences, fallback behavior, scopeless requests, CIBA handling, and explicit resource overrides.
Console audience settings
frontend/apps/console/src/features/{applications,agents}/components/edit-*/advanced-settings/*, frontend/packages/i18n/src/locales/en-US.ts
Adds an editable default-audience field to application and agent advanced settings with localized labels, trimming, read-only handling, and component tests.
Audience behavior documentation
docs/content/guides/**
Updates OAuth, OBO, CIBA, token exchange, resource indicator, and token documentation for default-audience fallback and resource precedence.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant OAuthClient
  participant GrantHandler
  participant AccessTokenBuilder
  OAuthClient->>GrantHandler: Provide OAuth app configuration
  GrantHandler->>OAuthClient: ResolveDefaultAudiences(clientID)
  OAuthClient-->>GrantHandler: Default audience or clientID fallback
  GrantHandler->>AccessTokenBuilder: Build token with resolved audiences
Loading

Possibly related PRs

Suggested reviewers: brionmario, donomalvindula, jeradrutnam, thamindudilshan

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding a client-level default token audience.
Description check ✅ Passed The description covers purpose, approach, and the related issue, though it omits noncritical template sections like checklist and related PRs.
Linked Issues check ✅ Passed The changes address #3725 by replacing client_id as the default aud for unbound access tokens with a configurable defaultAudience.
Out of Scope Changes check ✅ Passed The frontend, docs, backend, and tests all support the new default audience behavior, with no unrelated changes evident.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@thiva-k thiva-k changed the title Add client-level default token audience Add client-level default token audience config Jul 21, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/integration/oauth/token/default_resource_server_test.go (1)

237-261: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

DRY up request helpers.

requestClientCredentialsAs duplicates the HTTP request logic of the existing requestClientCredentials method (lines 131-153). You could refactor requestClientCredentials to delegate to this new helper to eliminate the duplication.

♻️ Proposed refactor (outside this segment)

Update the existing requestClientCredentials method (around line 131) to reuse your new helper:

-func (s *DefaultResourceServerTestSuite) requestClientCredentials(scope, resource string) (int, map[string]interface{}) {
-	form := url.Values{}
-	form.Set("grant_type", "client_credentials")
-	if scope != "" {
-		form.Set("scope", scope)
-	}
-	if resource != "" {
-		form.Set("resource", resource)
-	}
-
-	req, err := http.NewRequest(http.MethodPost, testServerURL+"/oauth2/token", strings.NewReader(form.Encode()))
-	s.Require().NoError(err)
-	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
-	req.SetBasicAuth(defaultRSTestClientID, defaultRSTestClientSecret)
-
-	resp, err := s.client.Do(req)
-	s.Require().NoError(err)
-	defer resp.Body.Close()
-
-	var respBody map[string]interface{}
-	s.Require().NoError(json.NewDecoder(resp.Body).Decode(&respBody))
-	return resp.StatusCode, respBody
-}
+func (s *DefaultResourceServerTestSuite) requestClientCredentials(scope, resource string) (int, map[string]interface{}) {
+	return s.requestClientCredentialsAs(defaultRSTestClientID, defaultRSTestClientSecret, scope, resource)
+}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/integration/oauth/token/default_resource_server_test.go` around lines
237 - 261, Refactor the existing requestClientCredentials method to delegate to
requestClientCredentialsAs with its current client ID, client secret, scope, and
no resource value. Remove the duplicated request construction and response
decoding logic while preserving requestClientCredentials’ existing behavior and
return values.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/content/guides/key-concepts/tokens.mdx`:
- Line 19: Update the unbound-token audience rule in the relevant token
documentation bullet to use the configured default audience, falling back to
client_id, and change the condition from “without resource or permission scopes”
to “without resource and permission scopes.” Keep the existing audience behavior
for other token categories unchanged.

---

Nitpick comments:
In `@tests/integration/oauth/token/default_resource_server_test.go`:
- Around line 237-261: Refactor the existing requestClientCredentials method to
delegate to requestClientCredentialsAs with its current client ID, client
secret, scope, and no resource value. Remove the duplicated request construction
and response decoding logic while preserving requestClientCredentials’ existing
behavior and return values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: af5cd535-d365-4076-a4f1-10e72a5a7c40

📥 Commits

Reviewing files that changed from the base of the PR and between 47e8545 and 305efec.

📒 Files selected for processing (30)
  • api/agent.yaml
  • api/application.yaml
  • backend/internal/inboundclient/service.go
  • backend/internal/inboundclient/service_test.go
  • backend/internal/oauth/oauth2/granthandlers/authorization_code.go
  • backend/internal/oauth/oauth2/granthandlers/ciba.go
  • backend/internal/oauth/oauth2/granthandlers/ciba_test.go
  • backend/internal/oauth/oauth2/granthandlers/client_credentials.go
  • backend/internal/oauth/oauth2/granthandlers/client_credentials_test.go
  • backend/internal/oauth/oauth2/granthandlers/jwt_bearer.go
  • backend/internal/oauth/oauth2/granthandlers/token_exchange.go
  • backend/pkg/thunderidengine/providers/model.go
  • backend/pkg/thunderidengine/providers/oauth_client.go
  • backend/pkg/thunderidengine/providers/oauth_client_test.go
  • docs/content/guides/getting-started/configuration.mdx
  • docs/content/guides/guides/agents/agent-authentication.mdx
  • docs/content/guides/guides/identity-providers/token-exchange-idp.mdx
  • docs/content/guides/guides/protocols/oauth-oidc/authorization-code.mdx
  • docs/content/guides/guides/protocols/oauth-oidc/backchannel-authentication.mdx
  • docs/content/guides/guides/protocols/oauth-oidc/client-credentials.mdx
  • docs/content/guides/guides/protocols/oauth-oidc/resource-indicators.mdx
  • docs/content/guides/guides/protocols/oauth-oidc/token-exchange.mdx
  • docs/content/guides/key-concepts/tokens.mdx
  • frontend/apps/console/src/features/agents/components/edit-agent/advanced-settings/EditAdvancedSettings.tsx
  • frontend/apps/console/src/features/applications/components/edit-application/advanced-settings/AudienceSection.tsx
  • frontend/apps/console/src/features/applications/components/edit-application/advanced-settings/EditAdvancedSettings.tsx
  • frontend/apps/console/src/features/applications/components/edit-application/advanced-settings/__tests__/AudienceSection.test.tsx
  • frontend/apps/console/src/features/applications/models/token.ts
  • frontend/packages/i18n/src/locales/en-US.ts
  • tests/integration/oauth/token/default_resource_server_test.go

Comment thread docs/content/guides/key-concepts/tokens.mdx
@thiva-k
thiva-k force-pushed the default-oauth-aud branch from 305efec to 9556bb9 Compare July 21, 2026 07:54
Comment thread backend/pkg/thunderidengine/providers/oauth_client.go Outdated
@thiva-k
thiva-k force-pushed the default-oauth-aud branch from 9556bb9 to 6ab6d6d Compare July 21, 2026 08:10
@Dilusha-Madushan

Copy link
Copy Markdown
Contributor

@thiva-k Should defaultAudience live under the Token tab rather than Advanced Settings?

@thiva-k

thiva-k commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@thiva-k Should defaultAudience live under the Token tab rather than Advanced Settings?

Keeping it under advanced settings for now since the token section is planned to be fully revamped

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

@thiva-k
thiva-k added this pull request to the merge queue Jul 21, 2026
Merged via the queue into thunder-id:main with commit c83ab6f Jul 21, 2026
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The default aud value of an access token is set to the client_id, which is ambiguous

3 participants