Repository navigation
fix(install): repair Auth0 and project setup flow #24
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 all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dbd8cb0
fix(auth): include Auth0 organization in PKCE flow
pitzcarraldo fc5cf11
fix(handoff): avoid execve for injected spawners
pitzcarraldo 87d657e
chore(release): bump version to 1.1.3
pitzcarraldo c57bfd2
fix(api): use management api for org setup
pitzcarraldo 738f778
fix(api): align management API environment
pitzcarraldo 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
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,125 @@ | ||
| import { afterEach, beforeEach, describe, expect, mock, test } from 'bun:test'; | ||
| import { AUTH_ENV_VARS } from '@/lib/auth'; | ||
| import { InternalApiClient } from '../internal-client'; | ||
|
|
||
| const originalFetch = globalThis.fetch; | ||
| const originalConsoleUrl = process.env[AUTH_ENV_VARS.CONSOLE_URL]; | ||
| const originalManagementApiUrl = process.env[AUTH_ENV_VARS.MANAGEMENT_API_URL]; | ||
|
|
||
| function jsonResponse(body: unknown): Response { | ||
| return new Response(JSON.stringify(body), { | ||
| status: 200, | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| }); | ||
| } | ||
|
|
||
| describe('InternalApiClient', () => { | ||
| const requests: string[] = []; | ||
|
|
||
| beforeEach(() => { | ||
| requests.length = 0; | ||
| delete process.env[AUTH_ENV_VARS.CONSOLE_URL]; | ||
| delete process.env[AUTH_ENV_VARS.MANAGEMENT_API_URL]; | ||
|
|
||
| globalThis.fetch = mock(async (input: string | URL | Request) => { | ||
| const url = String(input); | ||
| requests.push(url); | ||
|
|
||
| if (url.endsWith('/api/v1/members/me')) { | ||
| return jsonResponse({ | ||
| member: { | ||
| id: 'member-1', | ||
| auth_provider_id: 'auth0|1', | ||
| email: 'user@example.com', | ||
| name: 'User', | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| if (url.endsWith('/api/v1/organizations')) { | ||
| return jsonResponse({ organizations: [{ id: 'org-1', name: 'Org 1' }] }); | ||
| } | ||
|
|
||
| if (url.endsWith('/api/v1/organizations/org-1/projects')) { | ||
| return jsonResponse({ | ||
| projects: [{ id: 'project-1', organization_id: 'org-1', name: 'Project 1' }], | ||
| }); | ||
| } | ||
|
|
||
| if (url.endsWith('/api/v1/projects/project-1')) { | ||
| return jsonResponse({ | ||
| project: { id: 'project-1', organization_id: 'org-1', name: 'Project 1' }, | ||
| }); | ||
| } | ||
|
|
||
| return new Response('not found', { status: 404 }); | ||
| }) as unknown as typeof fetch; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| if (originalConsoleUrl === undefined) { | ||
| delete process.env[AUTH_ENV_VARS.CONSOLE_URL]; | ||
| } else { | ||
| process.env[AUTH_ENV_VARS.CONSOLE_URL] = originalConsoleUrl; | ||
| } | ||
|
|
||
| if (originalManagementApiUrl === undefined) { | ||
| delete process.env[AUTH_ENV_VARS.MANAGEMENT_API_URL]; | ||
| } else { | ||
| process.env[AUTH_ENV_VARS.MANAGEMENT_API_URL] = originalManagementApiUrl; | ||
| } | ||
|
|
||
| globalThis.fetch = originalFetch; | ||
| }); | ||
|
|
||
| test('uses the production management API by default', async () => { | ||
| const client = new InternalApiClient(); | ||
|
|
||
| await client.getMe({ authToken: 'token-1' }); | ||
|
|
||
| expect(requests).toEqual(['https://management-api.clix.so/api/v1/members/me']); | ||
| }); | ||
|
|
||
| test('derives management reads from the console override', async () => { | ||
| process.env[AUTH_ENV_VARS.CONSOLE_URL] = 'http://localhost:3000'; | ||
| const client = new InternalApiClient(); | ||
|
|
||
| await client.getMe({ authToken: 'token-1' }); | ||
|
|
||
| expect(requests).toEqual(['http://localhost:3000/api/clix/management/api/v1/members/me']); | ||
| }); | ||
|
|
||
| test('uses the explicit management API override when configured', async () => { | ||
| process.env[AUTH_ENV_VARS.CONSOLE_URL] = 'http://localhost:3000'; | ||
| process.env[AUTH_ENV_VARS.MANAGEMENT_API_URL] = 'https://management.example'; | ||
| const client = new InternalApiClient(); | ||
|
|
||
| await client.getMe({ authToken: 'token-1' }); | ||
|
|
||
| expect(requests).toEqual(['https://management.example/api/v1/members/me']); | ||
| }); | ||
|
|
||
| test('reads member, organizations, and org projects from management-api', async () => { | ||
| const client = new InternalApiClient('https://console.example', 'https://management.example'); | ||
|
|
||
| await client.getMe({ authToken: 'token-1' }); | ||
| await client.listOrganizations({ authToken: 'token-1' }); | ||
| await client.listProjects('org-1', { authToken: 'token-1' }); | ||
|
|
||
| expect(requests).toEqual([ | ||
| 'https://management.example/api/v1/members/me', | ||
| 'https://management.example/api/v1/organizations', | ||
| 'https://management.example/api/v1/organizations/org-1/projects', | ||
| ]); | ||
| }); | ||
|
|
||
| test('keeps runtime project reads on the console internal proxy', async () => { | ||
| const client = new InternalApiClient('https://console.example', 'https://management.example'); | ||
|
|
||
| await client.getProject('project-1', { authToken: 'token-1' }); | ||
|
|
||
| expect(requests).toEqual([ | ||
| 'https://console.example/api/clix/internal/api/v1/projects/project-1', | ||
| ]); | ||
| }); | ||
| }); |
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,65 @@ | ||
| import { afterEach, describe, expect, test } from 'bun:test'; | ||
| import { AUTH_ENV_VARS, getAuth0Config } from '../config'; | ||
| import { PKCEFlowService } from '../pkce-flow'; | ||
|
|
||
| const authEnvVars = Object.values(AUTH_ENV_VARS); | ||
| const previousEnv = new Map(authEnvVars.map((key) => [key, process.env[key]])); | ||
|
|
||
| afterEach(() => { | ||
| for (const key of authEnvVars) { | ||
| const previous = previousEnv.get(key); | ||
| if (previous === undefined) { | ||
| delete process.env[key]; | ||
| } else { | ||
| process.env[key] = previous; | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| describe('Auth0 PKCE flow', () => { | ||
| test('uses the production Auth0 organization for the bundled client', () => { | ||
| for (const key of authEnvVars) { | ||
| delete process.env[key]; | ||
| } | ||
|
|
||
| expect(getAuth0Config().organizationId).toBe('org_X7z9sXwAd3bWpEqu'); | ||
| }); | ||
|
|
||
| test('does not use the production Auth0 organization for custom clients', () => { | ||
| for (const key of authEnvVars) { | ||
| delete process.env[key]; | ||
| } | ||
|
|
||
| process.env[AUTH_ENV_VARS.AUTH0_CLIENT_ID] = 'custom-client-id'; | ||
|
|
||
| expect(getAuth0Config().organizationId).toBeUndefined(); | ||
| }); | ||
|
|
||
| test('allows custom Auth0 organization override', () => { | ||
| for (const key of authEnvVars) { | ||
| delete process.env[key]; | ||
| } | ||
|
|
||
| process.env[AUTH_ENV_VARS.AUTH0_CLIENT_ID] = 'custom-client-id'; | ||
| process.env[AUTH_ENV_VARS.AUTH0_ORGANIZATION_ID] = 'org_custom'; | ||
|
|
||
| expect(getAuth0Config().organizationId).toBe('org_custom'); | ||
| }); | ||
|
|
||
| test('includes organization in authorization URL', async () => { | ||
| const service = new PKCEFlowService({ | ||
| domain: 'example.auth0.com', | ||
| clientId: 'client-id', | ||
| organizationId: 'org_test', | ||
| audience: 'https://example.auth0.com/api/v2/', | ||
| scope: 'openid profile email offline_access', | ||
| }); | ||
|
|
||
| try { | ||
| const { authUrl } = await service.startAuthFlow(); | ||
| expect(new URL(authUrl).searchParams.get('organization')).toBe('org_test'); | ||
| } finally { | ||
| service.abort(); | ||
| } | ||
| }); | ||
| }); |
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.