-
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
Open
mikesouza
wants to merge
9
commits into
openfga:main
Choose a base branch
from
mikesouza:feat/custom-token-endpoint-url
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+606
−7
Open
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
414e4d2
feat: support custom OIDC token endpoint URL
mikesouza 3173c02
Resolve requested changes
mikesouza 5e0d153
Fix additional requested changes
mikesouza e1619b9
Add more tests and refactor constants
mikesouza 05f0dbb
Add more test cases
mikesouza ff53e64
Merge branch 'main' into feat/custom-token-endpoint-url
mikesouza c218edb
Fix nock issue in CI
mikesouza 8293128
Merge branch 'main' into feat/custom-token-endpoint-url
SoulPancake 685f2af
Attempt to fix nock issue in CI
mikesouza 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
Some comments aren't visible on the classic Files Changed page.
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
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,120 @@ | ||
| import * as nock from "nock"; | ||
| import { Credentials, CredentialsMethod, DEFAULT_TOKEN_ENDPOINT_PATH } from "../credentials"; | ||
| import { AuthCredentialsConfig } from "../credentials/types"; | ||
| import { TelemetryConfiguration } from "../telemetry/configuration"; | ||
| import { | ||
| OPENFGA_API_AUDIENCE, | ||
| OPENFGA_CLIENT_ID, | ||
| OPENFGA_CLIENT_SECRET, | ||
| } from "./helpers/default-config"; | ||
|
|
||
| nock.disableNetConnect(); | ||
|
|
||
| describe("Credentials", () => { | ||
| const mockTelemetryConfig: TelemetryConfiguration = new TelemetryConfiguration({}); | ||
|
|
||
| describe("Refreshing access token", () => { | ||
mikesouza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| interface TestCase { | ||
| description: string; | ||
| apiTokenIssuer: string; | ||
| expectedBaseUrl: string; | ||
| expectedPath: string; | ||
| queryParams?: Record<string, string>; | ||
| } | ||
|
|
||
| const testCases: TestCase[] = [ | ||
| { | ||
| description: "should use default scheme and token endpoint path when apiTokenIssuer has no scheme and no path", | ||
| apiTokenIssuer: "issuer.fga.example", | ||
| expectedBaseUrl: "https://issuer.fga.example", | ||
| expectedPath: `/${DEFAULT_TOKEN_ENDPOINT_PATH}`, | ||
| }, | ||
| { | ||
| description: "should use default token endpoint path when apiTokenIssuer has root path and no scheme", | ||
| apiTokenIssuer: "https://issuer.fga.example/", | ||
| expectedBaseUrl: "https://issuer.fga.example", | ||
| expectedPath: `/${DEFAULT_TOKEN_ENDPOINT_PATH}`, | ||
| }, | ||
| { | ||
| description: "should preserve custom token endpoint path when provided", | ||
| apiTokenIssuer: "https://issuer.fga.example/some_endpoint", | ||
| expectedBaseUrl: "https://issuer.fga.example", | ||
| expectedPath: "/some_endpoint", | ||
| }, | ||
| { | ||
| description: "should preserve custom token endpoint path with nested path when provided", | ||
| apiTokenIssuer: "https://issuer.fga.example/api/v1/oauth/token", | ||
| expectedBaseUrl: "https://issuer.fga.example", | ||
| expectedPath: "/api/v1/oauth/token", | ||
| }, | ||
| { | ||
| description: "should add https:// prefix when apiTokenIssuer has no scheme", | ||
| apiTokenIssuer: "issuer.fga.example/some_endpoint", | ||
| expectedBaseUrl: "https://issuer.fga.example", | ||
| expectedPath: "/some_endpoint", | ||
| }, | ||
| { | ||
| description: "should preserve http:// scheme when provided", | ||
| apiTokenIssuer: "http://issuer.fga.example/some_endpoint", | ||
| expectedBaseUrl: "http://issuer.fga.example", | ||
| expectedPath: "/some_endpoint", | ||
| }, | ||
| { | ||
| description: "should use default path when apiTokenIssuer has https:// scheme but no path", | ||
| apiTokenIssuer: "https://issuer.fga.example", | ||
| expectedBaseUrl: "https://issuer.fga.example", | ||
| expectedPath: `/${DEFAULT_TOKEN_ENDPOINT_PATH}`, | ||
| }, | ||
| { | ||
| description: "should preserve custom path with query parameters", | ||
| apiTokenIssuer: "https://issuer.fga.example/some_endpoint?param=value", | ||
| expectedBaseUrl: "https://issuer.fga.example", | ||
| expectedPath: "/some_endpoint", | ||
| queryParams: { param: "value" }, | ||
| }, | ||
| { | ||
| description: "should preserve custom path with port number", | ||
| apiTokenIssuer: "https://issuer.fga.example:8080/some_endpoint", | ||
| expectedBaseUrl: "https://issuer.fga.example:8080", | ||
| expectedPath: "/some_endpoint", | ||
| }, | ||
| ]; | ||
daniel-jonathan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| test.each(testCases)("$description", async ({ apiTokenIssuer, expectedBaseUrl, expectedPath, queryParams }) => { | ||
| const scope = queryParams | ||
| ? nock(expectedBaseUrl) | ||
| .post(expectedPath) | ||
| .query(queryParams) | ||
| .reply(200, { | ||
| access_token: "test-token", | ||
| expires_in: 300, | ||
| }) | ||
| : nock(expectedBaseUrl) | ||
| .post(expectedPath) | ||
| .reply(200, { | ||
| access_token: "test-token", | ||
| expires_in: 300, | ||
| }); | ||
|
|
||
| const credentials = new Credentials( | ||
| { | ||
| method: CredentialsMethod.ClientCredentials, | ||
| config: { | ||
| apiTokenIssuer, | ||
| apiAudience: OPENFGA_API_AUDIENCE, | ||
| clientId: OPENFGA_CLIENT_ID, | ||
| clientSecret: OPENFGA_CLIENT_SECRET, | ||
| }, | ||
| } as AuthCredentialsConfig, | ||
| undefined, | ||
| mockTelemetryConfig, | ||
| ); | ||
|
|
||
| await credentials.getAccessTokenHeader(); | ||
|
|
||
| expect(scope.isDone()).toBe(true); | ||
| nock.cleanAll(); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
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
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.