[TT-17580] Add JWT bearer grant (RFC 7523) to OAuth2 token exchange#8466
[TT-17580] Add JWT bearer grant (RFC 7523) to OAuth2 token exchange#8466lghiur wants to merge 3 commits into
Conversation
|
This pull request introduces support for the JWT Bearer Grant (RFC 7523) for OAuth2 token exchange, enhancing Tyk's capabilities for implementing On-Behalf-Of (OBO) delegation flows, particularly with identity providers like Microsoft Entra ID. The changes also include significant improvements for multi-tenant configurations and add support for Key changes include:
Files Changed AnalysisThe changes are spread across 30 files, with approximately 1745 lines of code added, reflecting a significant feature implementation. The modifications are logically structured:
Architecture & Impact Assessment
JWT Bearer Flow with Step-Up ChallengesequenceDiagram
participant Client
participant Tyk Gateway
participant "Identity Provider (IdP)"
Client->>+Tyk Gateway: API Request with Inbound JWT
Tyk Gateway->>Tyk Gateway: "Select Provider (iss match, regex support)"
Tyk Gateway->>Tyk Gateway: Resolve dynamic Token Endpoint from JWT
Tyk Gateway->>Tyk Gateway: "Build JWT Bearer request (token as `assertion`)"
alt private_key_jwt auth
Tyk Gateway->>Tyk Gateway: Sign client assertion with private key
end
Tyk Gateway->>+"Identity Provider (IdP)": "POST /token (grant_type=jwt-bearer, assertion=...)"
alt Step-Up Required
"Identity Provider (IdP)"-->>-Tyk Gateway: "400 Bad Request (error=interaction_required, claims=...)"
Tyk Gateway->>Tyk Gateway: "Classify as StepUpRequiredError"
Tyk Gateway-->>-Client: "401 Unauthorized (WWW-Authenticate: Bearer error=\"insufficient_claims\")"
else Success
"Identity Provider (IdP)"-->>-Tyk Gateway: "200 OK (Exchanged Token)"
Tyk Gateway->>Tyk Gateway: "Cache exchanged token (key includes tenant endpoint)"
Tyk Gateway-->>Client: Proxy request to upstream with new token
end
Scope Discovery & Context Expansion
Metadata
Powered by Visor from Probelabs Last updated: 2026-07-09T08:46:01.565Z | Triggered by: pr_updated | Commit: 8539397 💡 TIP: You can chat with Visor using |
✅ Security Check PassedNo security issues found – changes LGTM. Architecture Issues (1)
✅ Security Check PassedNo security issues found – changes LGTM. \n\nArchitecture Issues (1)
Quality Issues (2)
Powered by Visor from Probelabs Last updated: 2026-07-09T08:45:29.490Z | Triggered by: pr_updated | Commit: 8539397 💡 TIP: You can chat with Visor using |
| endpoint = st.ReplaceVariables(endpoint) | ||
| } | ||
| tenantEndpoint := "" | ||
| if endpoint != provider.TokenEndpoint { |
There was a problem hiding this comment.
the below concern flagged by Visor should be handled
| if _, err := regexp.Compile(pattern); err != nil { | ||
| return fmt.Errorf("oauth2 scheme %q: tokenExchange.provider %q issuers regex %q does not compile: %v", schemeName, providerName, pattern, err) | ||
| } | ||
| if !strings.HasPrefix(pattern, "^") || !strings.HasSuffix(pattern, "$") { |
There was a problem hiding this comment.
this should be moved above the compile call
| // validateExchangeCustomParams rejects customParams that would override a wire | ||
| // key the gateway sets under the provider's grant. | ||
| func validateExchangeCustomParams(schemeName string, p *OAuth2TokenExchangeProvider) error { | ||
| reservedKeys, grantLabel := oauth2ReservedExchangeFormKeys, "RFC 8693" |
There was a problem hiding this comment.
magic strings used as values should be replaced for constants
|
SentinelOne CNS Hardcoded Secret Detector SentinelOne CNS is a cloud-agnostic, agentless CSPM & CWPP solution that continuously detects and prevents vulnerabilities that have the highest probability of being exploited in Azure, AWS, Google Cloud, and Kubernetes. |
PR description:
Adds the RFC 7523 JWT bearer grant as a second delegation grant for the OAuth2 token exchange feature, selected per provider via a new optional
grantTypefield (token-exchangedefault |jwt-bearer).Ticket Details
TT-17580
Generated at: 2026-07-09 08:43:38