-
Notifications
You must be signed in to change notification settings - Fork 53
fix!: rename portal to adminPortal
#1562
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| import fetch from 'jest-fetch-mock'; | ||
| import { fetchBody, fetchOnce } from '../common/utils/test-utils'; | ||
| import { WorkOS } from '../workos'; | ||
| import portalLinkResponse from './fixtures/portal-link-response.fixture.json'; | ||
| import generateLinkInvalid from './fixtures/generate-link-invalid.fixture.json'; | ||
|
|
||
| const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); | ||
|
|
||
| describe('AdminPortal', () => { | ||
| beforeEach(() => fetch.resetMocks()); | ||
|
|
||
| describe('generateLink', () => { | ||
| describe('with the sso intent', () => { | ||
| it('returns an Admin Portal link', async () => { | ||
| fetchOnce(portalLinkResponse, { status: 201 }); | ||
|
|
||
| const { link } = await workos.adminPortal.generateLink({ | ||
| intent: 'sso', | ||
| organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3', | ||
| returnUrl: 'https://www.example.com', | ||
| }); | ||
|
|
||
| expect(fetchBody()).toEqual({ | ||
| intent: 'sso', | ||
| organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3', | ||
| return_url: 'https://www.example.com', | ||
| }); | ||
| expect(link).toBeDefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with the dsync intent', () => { | ||
| it('returns an Admin Portal link', async () => { | ||
| fetchOnce(portalLinkResponse, { status: 201 }); | ||
|
|
||
| const { link } = await workos.adminPortal.generateLink({ | ||
| intent: 'dsync', | ||
| organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3', | ||
| returnUrl: 'https://www.example.com', | ||
| }); | ||
|
|
||
| expect(fetchBody()).toEqual({ | ||
| intent: 'dsync', | ||
| organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3', | ||
| return_url: 'https://www.example.com', | ||
| }); | ||
| expect(link).toBeDefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with the audit_logs intent', () => { | ||
| it('returns an Admin Portal link', async () => { | ||
| fetchOnce(portalLinkResponse, { status: 201 }); | ||
|
|
||
| const { link } = await workos.adminPortal.generateLink({ | ||
| intent: 'audit_logs', | ||
| organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3', | ||
| returnUrl: 'https://www.example.com', | ||
| }); | ||
|
|
||
| expect(fetchBody()).toEqual({ | ||
| intent: 'audit_logs', | ||
| organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3', | ||
| return_url: 'https://www.example.com', | ||
| }); | ||
| expect(link).toBeDefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with the log_streams intent', () => { | ||
| it('returns an Admin Portal link', async () => { | ||
| fetchOnce(portalLinkResponse, { status: 201 }); | ||
|
|
||
| const { link } = await workos.adminPortal.generateLink({ | ||
| intent: 'log_streams', | ||
| organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3', | ||
| returnUrl: 'https://www.example.com', | ||
| }); | ||
|
|
||
| expect(fetchBody()).toEqual({ | ||
| intent: 'log_streams', | ||
| organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3', | ||
| return_url: 'https://www.example.com', | ||
| }); | ||
| expect(link).toBeDefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with the domain_verification intent', () => { | ||
| it('returns an Admin Portal link', async () => { | ||
| fetchOnce(portalLinkResponse, { status: 201 }); | ||
|
|
||
| const { link } = await workos.adminPortal.generateLink({ | ||
| intent: 'domain_verification', | ||
| organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3', | ||
| returnUrl: 'https://www.example.com', | ||
| }); | ||
|
|
||
| expect(fetchBody()).toEqual({ | ||
| intent: 'domain_verification', | ||
| organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3', | ||
| return_url: 'https://www.example.com', | ||
| }); | ||
| expect(link).toBeDefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with the certificate_renewal intent', () => { | ||
| it('returns an Admin Portal link', async () => { | ||
| fetchOnce(portalLinkResponse, { status: 201 }); | ||
|
|
||
| const { link } = await workos.adminPortal.generateLink({ | ||
| intent: 'certificate_renewal', | ||
| organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3', | ||
| returnUrl: 'https://www.example.com', | ||
| }); | ||
|
|
||
| expect(fetchBody()).toEqual({ | ||
| intent: 'certificate_renewal', | ||
| organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3', | ||
| return_url: 'https://www.example.com', | ||
| }); | ||
| expect(link).toBeDefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with the bring_your_own_key intent', () => { | ||
| it('returns an Admin Portal link', async () => { | ||
| fetchOnce(portalLinkResponse, { status: 201 }); | ||
|
|
||
| const { link } = await workos.adminPortal.generateLink({ | ||
| intent: 'bring_your_own_key', | ||
| organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3', | ||
| returnUrl: 'https://www.example.com', | ||
| }); | ||
|
|
||
| expect(fetchBody()).toEqual({ | ||
| intent: 'bring_your_own_key', | ||
| organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3', | ||
| return_url: 'https://www.example.com', | ||
| }); | ||
| expect(link).toBeDefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with intentOptions and adminEmails', () => { | ||
| it('serializes the new parameters correctly', async () => { | ||
| fetchOnce(portalLinkResponse, { status: 201 }); | ||
|
|
||
| const { link } = await workos.adminPortal.generateLink({ | ||
| intent: 'sso', | ||
| organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3', | ||
| returnUrl: 'https://www.example.com', | ||
| intentOptions: { | ||
| sso: { | ||
| bookmarkSlug: 'chatgpt', | ||
| providerType: 'GoogleSAML', | ||
| }, | ||
| }, | ||
| adminEmails: ['admin@example.com'], | ||
| }); | ||
|
|
||
| expect(fetchBody()).toEqual({ | ||
| intent: 'sso', | ||
| organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3', | ||
| return_url: 'https://www.example.com', | ||
| intent_options: { | ||
| sso: { | ||
| bookmark_slug: 'chatgpt', | ||
| provider_type: 'GoogleSAML', | ||
| }, | ||
| }, | ||
| admin_emails: ['admin@example.com'], | ||
| }); | ||
| expect(link).toBeDefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with an invalid organization', () => { | ||
| it('throws an error', async () => { | ||
| fetchOnce(generateLinkInvalid, { | ||
| status: 400, | ||
| headers: { 'X-Request-ID': 'a-request-id' }, | ||
| }); | ||
|
|
||
| await expect( | ||
| workos.adminPortal.generateLink({ | ||
| intent: 'sso', | ||
| organization: 'bogus-id', | ||
| returnUrl: 'https://www.example.com', | ||
| }), | ||
| ).rejects.toThrow( | ||
| 'Could not find an organization with the id, bogus-id.', | ||
| ); | ||
| expect(fetchBody()).toEqual({ | ||
| intent: 'sso', | ||
| organization: 'bogus-id', | ||
| return_url: 'https://www.example.com', | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
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,33 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| import type { WorkOS } from '../workos'; | ||
| import type { | ||
| PortalLinkResponse, | ||
| PortalLinkResponseWire, | ||
| } from './interfaces/portal-link-response.interface'; | ||
| import type { GenerateLink } from './interfaces/generate-link.interface'; | ||
| import { deserializePortalLinkResponse } from './serializers/portal-link-response.serializer'; | ||
| import { serializeGenerateLink } from './serializers/generate-link.serializer'; | ||
|
|
||
| export class AdminPortal { | ||
| constructor(private readonly workos: WorkOS) {} | ||
|
|
||
| /** | ||
| * Generate a Portal Link | ||
| * | ||
| * Generate a Portal Link scoped to an Organization. | ||
| * @param payload - Admin Portal link generation parameters. | ||
| * @returns {Promise<PortalLinkResponse>} | ||
| * @throws {BadRequestException} 400 | ||
| * @throws {UnauthorizedException} 401 | ||
| * @throws {NotFoundException} 404 | ||
| * @throws {UnprocessableEntityException} 422 | ||
| */ | ||
| async generateLink(payload: GenerateLink): Promise<PortalLinkResponse> { | ||
| const { data } = await this.workos.post<PortalLinkResponseWire>( | ||
| '/portal/generate_link', | ||
| serializeGenerateLink(payload), | ||
| ); | ||
| return deserializePortalLinkResponse(data); | ||
| } | ||
| } |
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,3 @@ | ||
| { | ||
| "message": "Could not find an organization with the id, bogus-id." | ||
| } |
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,13 @@ | ||
| { | ||
| "return_url": "https://example.com/admin-portal/return", | ||
| "success_url": "https://example.com/admin-portal/success", | ||
| "organization": "org_01EHZNVPK3SFK441A1RGBFSHRT", | ||
| "intent": "sso", | ||
| "intent_options": { | ||
| "sso": { | ||
| "bookmark_slug": "chatgpt", | ||
| "provider_type": "GoogleSAML" | ||
| } | ||
| }, | ||
| "admin_emails": ["admin@example.com"] | ||
| } |
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,6 @@ | ||
| { | ||
| "sso": { | ||
| "bookmark_slug": "chatgpt", | ||
| "provider_type": "GoogleSAML" | ||
| } | ||
| } |
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,3 @@ | ||
| { | ||
| "link": "https://setup.workos.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." | ||
| } | ||
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,4 @@ | ||
| { | ||
| "bookmark_slug": "chatgpt", | ||
| "provider_type": "GoogleSAML" | ||
| } |
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,41 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| import type { | ||
| IntentOptions, | ||
| IntentOptionsResponse, | ||
| } from './intent-options.interface'; | ||
| import type { GenerateLinkIntent } from '../../common/interfaces/generate-link-intent.interface'; | ||
|
|
||
| export interface GenerateLink { | ||
| /** The URL to go to when an admin clicks on your logo in the Admin Portal. If not specified, the return URL configured on the [Redirects](https://dashboard.workos.com/redirects) page will be used. */ | ||
| returnUrl?: string; | ||
| /** The URL to redirect the admin to when they finish setup. If not specified, the success URL configured on the [Redirects](https://dashboard.workos.com/redirects) page will be used. */ | ||
| successUrl?: string; | ||
| /** An [Organization](https://workos.com/docs/reference/organization) identifier. */ | ||
| organization: string; | ||
| /** | ||
| * | ||
| * The intent of the Admin Portal. | ||
| * - `sso` - Launch Admin Portal for creating SSO connections | ||
| * - `dsync` - Launch Admin Portal for creating Directory Sync connections | ||
| * - `audit_logs` - Launch Admin Portal for viewing Audit Logs | ||
| * - `log_streams` - Launch Admin Portal for creating Log Streams | ||
| * - `domain_verification` - Launch Admin Portal for Domain Verification | ||
| * - `certificate_renewal` - Launch Admin Portal for renewing SAML Certificates | ||
| * - `bring_your_own_key` - Launch Admin Portal for configuring Bring Your Own Key | ||
| */ | ||
| intent?: GenerateLinkIntent; | ||
| /** Options to configure the Admin Portal based on the intent. */ | ||
| intentOptions?: IntentOptions; | ||
| /** The email addresses of the IT admins to grant access to the Admin Portal for the given organization. Accepts up to 20 emails. */ | ||
| adminEmails?: string[]; | ||
| } | ||
|
|
||
| export interface GenerateLinkResponse { | ||
| return_url?: string; | ||
| success_url?: string; | ||
| organization: string; | ||
| intent?: GenerateLinkIntent; | ||
| intent_options?: IntentOptionsResponse; | ||
| admin_emails?: string[]; | ||
| } |
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,6 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| export * from './generate-link.interface'; | ||
| export * from './intent-options.interface'; | ||
| export * from './portal-link-response.interface'; | ||
| export * from './sso-intent-options.interface'; |
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,15 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| import type { | ||
| SSOIntentOptions, | ||
| SSOIntentOptionsResponse, | ||
| } from './sso-intent-options.interface'; | ||
|
|
||
| export interface IntentOptions { | ||
| /** SSO-specific options for the Admin Portal. */ | ||
| sso: SSOIntentOptions; | ||
| } | ||
|
|
||
| export interface IntentOptionsResponse { | ||
| sso: SSOIntentOptionsResponse; | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/admin-portal/interfaces/portal-link-response.interface.ts
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,10 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| export interface PortalLinkResponse { | ||
| /** An ephemeral link to initiate the Admin Portal. */ | ||
| link: string; | ||
| } | ||
|
|
||
| export interface PortalLinkResponseWire { | ||
| link: string; | ||
| } |
13 changes: 13 additions & 0 deletions
13
src/admin-portal/interfaces/sso-intent-options.interface.ts
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,13 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| export interface SSOIntentOptions { | ||
| /** The bookmark slug to use for SSO. */ | ||
| bookmarkSlug?: string; | ||
| /** The SSO provider type to configure. */ | ||
| providerType?: 'GoogleSAML'; | ||
| } | ||
|
|
||
| export interface SSOIntentOptionsResponse { | ||
| bookmark_slug?: string; | ||
| provider_type?: 'GoogleSAML'; | ||
| } |
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.
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.
Replace secret-like token in fixture to avoid leak-scanner failures.
Line 2 uses a JWT-looking token string. Even in test fixtures, this pattern can be treated as exposed credentials and fail security checks. Use an obviously fake token value instead.
Suggested change
📝 Committable suggestion
🧰 Tools
🪛 Betterleaks (1.1.2)
[high] 2-2: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
🤖 Prompt for AI Agents