-
Notifications
You must be signed in to change notification settings - Fork 25
feat: support custom OIDC token endpoint URL #285
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
base: main
Are you sure you want to change the base?
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe changes implement intelligent OIDC token endpoint URL construction by introducing a helper method that parses and normalizes Changes
Sequence DiagramsequenceDiagram
participant Caller
participant Credentials
participant buildApiTokenUrl
participant TokenEndpoint
Caller->>Credentials: getAccessTokenHeader() or isValid()
Credentials->>buildApiTokenUrl: buildApiTokenUrl(apiTokenIssuer)
alt Valid URL with scheme
buildApiTokenUrl->>buildApiTokenUrl: Parse URL
buildApiTokenUrl->>buildApiTokenUrl: Check if path exists
alt Path missing or empty
buildApiTokenUrl->>buildApiTokenUrl: Append /oauth/token
end
buildApiTokenUrl-->>Credentials: Return normalized URL
else Invalid URL
buildApiTokenUrl-->>Credentials: Return empty string
end
Credentials->>TokenEndpoint: POST normalized endpoint URL
TokenEndpoint-->>Credentials: Access token response
Credentials-->>Caller: Token or validation result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–25 minutes
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
credentials/credentials.ts (1)
234-251: Fix JWT audience construction to respect the scheme in apiTokenIssuer.Line 249 hardcodes the JWT audience as
https://${config.apiTokenIssuer}/, which always forces the https:// scheme. This contradicts the new flexible URL handling inbuildApiTokenUrl(lines 150-151), which respects the actual scheme—adding https:// only when no scheme is present.The test suite confirms multiple schemes are intentionally supported (tests/index.test.ts:64). If
apiTokenIssueris set tohttp://issuer.example.com, the token endpoint respects this, but the JWT audience incorrectly forces it tohttps://issuer.example.com/, creating a mismatch that violates OAuth 2.0 spec requirements for the audience claim.Fix: Extract or derive the issuer base URL using the same scheme-handling logic as
buildApiTokenUrl, rather than hardcoding https://.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
credentials/credentials.ts(3 hunks)tests/credentials.test.ts(1 hunks)tests/index.test.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
tests/credentials.test.ts (4)
telemetry/configuration.ts (1)
TelemetryConfiguration(44-156)credentials/credentials.ts (2)
DEFAULT_TOKEN_ENDPOINT_PATH(40-40)Credentials(42-272)tests/helpers/default-config.ts (3)
OPENFGA_API_AUDIENCE(8-8)OPENFGA_CLIENT_ID(9-9)OPENFGA_CLIENT_SECRET(10-10)credentials/types.ts (1)
AuthCredentialsConfig(98-107)
credentials/credentials.ts (2)
validation.ts (1)
isWellFormedUriString(18-26)credentials/types.ts (1)
ClientCredentialsConfig(75-75)
tests/index.test.ts (2)
tests/helpers/default-config.ts (1)
baseConfig(41-54)configuration.ts (1)
Configuration(58-202)
🔇 Additional comments (7)
credentials/credentials.ts (2)
40-41: LGTM!The constant is well-defined and provides a clear default for the token endpoint path.
169-171: LGTM!The token refresh flow now correctly uses the new URL builder helper.
tests/credentials.test.ts (3)
1-15: LGTM!Test setup is well-structured with proper imports and network isolation using nock.
16-81: LGTM!Comprehensive test cases covering various URL formats, schemes, paths, query parameters, and port numbers. The test descriptions are clear and align well with the PR objectives.
83-118: LGTM!The parameterized test implementation is clean and properly verifies that the token endpoint is called with the correct base URL and path. Good use of nock for mocking and proper cleanup.
tests/index.test.ts (2)
64-77: LGTM!Parameterized test properly validates that valid schemes (https://, http://, and empty/default) are accepted during construction. Good coverage of the intended behavior.
79-92: Good test coverage for invalid schemes.The test properly validates that invalid schemes are rejected. Note that this test's effectiveness depends on
buildApiTokenUrlproperly validating schemes (see my comment on credentials/credentials.ts lines 148-163 about adding scheme validation).
25729ee to
38392a1
Compare
38392a1 to
414e4d2
Compare
|
@mikesouza Thanks for the PR! We will get someone on the team to review. |
|
With this PR we now normalize the token endpoint URL via buildApiTokenUrl(apiTokenIssuer), including handling full URLs and custom paths, but the PrivateKeyJWT aud is still built as https://${apiTokenIssuer}/. That means: For domain-only issuers (issuer.fga.example) the token endpoint might be https://issuer.fga.example/oauth/token, but the JWT aud stays https://issuer.fga.example/. For full URLs like https://issuer.fga.example/custom/path, token URL is normalized correctly, but the audience is still effectively “host only” (https://issuer.fga.example/), which may or may not match what non-Auth0 providers expect. In #271 the normalization helper was reused for the audience as well (so audience matches the same normalization rules as the token URL). Either: Reuse the same normalization helper here for aud, or Explicitly document in README that apiTokenIssuer must resolve to a bare host when using PrivateKeyJWT, and that only the token endpoint URL is customizable. Right now it feels like we’re only halfway towards “fully support non-standard OIDC providers.” Reference from #271 |
|
@mikesouza I reviewed the updates you made from the feedback. There is an error in one of the test runs. Please review and update it with a fix. I have approved the PR in general. Thank you, and solid work! |
Head branch was pushed to by a user without write access
|
@daniel-jonathan Thanks for the re-review! Hmmm strange, the unit tests all pass on my local machine, but it looks like the test failures in CI are related to the 15 tests that use
|


Description
This PR addresses the inconsistency in how the JS SDK constructs the OIDC token endpoint URL (see openfga/sdk-generator#238), so that it is inline with how the Go and other SDKs work.
apiTokenIssuer.apiTokenIssuernow accepts a full URL that can optionally include the scheme. If a scheme is not specified, it defaults tohttps://.References
NOTE: This PR #271 seems to be outdated and the author doesn't seem to be working on it, so I decided to submit my own PR.
Review Checklist
Summary by CodeRabbit
Improvements
Tests