From fffb4286342c8e57ce665523c99b4cba7e105d3f Mon Sep 17 00:00:00 2001 From: Andrew Israel Date: Tue, 6 Jun 2023 12:54:52 -0700 Subject: [PATCH] Add redirects to the API key pages --- package.json | 2 +- src/client.ts | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index db38e30..69c8360 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "type": "git", "url": "https://github.com/PropelAuth/javascript" }, - "version": "2.0.5", + "version": "2.0.6", "keywords": [ "auth", "user", diff --git a/src/client.ts b/src/client.ts index 809e28a..e941b63 100644 --- a/src/client.ts +++ b/src/client.ts @@ -64,6 +64,16 @@ export interface IAuthClient { */ getSetupSAMLPageUrl(orgId: string): string + /** + * Gets the URL for the hosted personal API key page. + */ + getPersonalApiKeyPageUrl(): string + + /** + * Gets the URL for the hosted org API key page. + */ + getOrgApiKeyPageUrl(orgId: string): string + /** * Redirects the user to the signup page. */ @@ -95,6 +105,16 @@ export interface IAuthClient { */ redirectToSetupSAMLPage(orgId: string): void + /** + * Redirects the user to the personal API key page. + */ + redirectToPersonalApiKeyPage(): void + + /** + * Redirects the user to the org API key page. + */ + redirectToOrgApiKeyPage(): void + /** * Adds an observer which is called whenever the users logs in or logs out. @@ -277,6 +297,14 @@ export function createClient(authOptions: IAuthOptions): IAuthClient { return `${clientState.authUrl}/saml?id=${orgId}` } + const getPersonalApiKeyPageUrl = () => { + return `${clientState.authUrl}/api_keys/personal` + } + + const getOrgApiKeyPageUrl = () => { + return `${clientState.authUrl}/api_keys/org` + } + const client = { addLoggedInChangeObserver(loggedInChangeObserver: (isLoggedIn: boolean) => void): void { const hasObserver = clientState.observers.includes(loggedInChangeObserver) @@ -329,6 +357,14 @@ export function createClient(authOptions: IAuthOptions): IAuthClient { return getAccountPageUrl() }, + getPersonalApiKeyPageUrl(): string { + return getPersonalApiKeyPageUrl() + }, + + getOrgApiKeyPageUrl(): string { + return getOrgApiKeyPageUrl() + }, + getOrgPageUrl(orgId?: string): string { return getOrgPageUrl(orgId) }, @@ -365,6 +401,14 @@ export function createClient(authOptions: IAuthOptions): IAuthClient { window.location.href = getSetupSAMLPageUrl(orgId) }, + redirectToPersonalApiKeyPage(): void { + window.location.href = getPersonalApiKeyPageUrl() + }, + + redirectToOrgApiKeyPage(): void { + window.location.href = getOrgApiKeyPageUrl() + }, + async logout(redirectAfterLogout: boolean): Promise { const logoutResponse = await logout(clientState.authUrl) setAuthenticationInfoAndUpdateDownstream(null)