@osdk/oauth 1.8.0-beta.3 → 1.8.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/build/browser/Logger.js +2 -0
- package/build/browser/Logger.js.map +1 -0
- package/build/browser/createPublicOauthClient.js +5 -5
- package/build/browser/createPublicOauthClient.js.map +1 -1
- package/build/browser/index.js.map +1 -1
- package/build/browser/utils.js +2 -1
- package/build/browser/utils.js.map +1 -1
- package/build/cjs/index.cjs +7 -4
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +10 -1
- package/build/esm/Logger.js +2 -0
- package/build/esm/Logger.js.map +1 -0
- package/build/esm/createPublicOauthClient.js +5 -5
- package/build/esm/createPublicOauthClient.js.map +1 -1
- package/build/esm/index.js.map +1 -1
- package/build/esm/utils.js +2 -1
- package/build/esm/utils.js.map +1 -1
- package/build/types/Logger.d.ts +3 -0
- package/build/types/Logger.d.ts.map +1 -0
- package/build/types/createPublicOauthClient.d.ts +6 -0
- package/build/types/createPublicOauthClient.d.ts.map +1 -1
- package/build/types/index.d.ts +1 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/utils.d.ts +3 -1
- package/build/types/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/build/browser/AuthorizationServer.test.js +0 -53
- package/build/browser/AuthorizationServer.test.js.map +0 -1
- package/build/browser/__tests__/createPublicOauthClient.test.js +0 -59
- package/build/browser/__tests__/createPublicOauthClient.test.js.map +0 -1
- package/build/browser/common.test.js +0 -68
- package/build/browser/common.test.js.map +0 -1
- package/build/browser/createAuthlessClient.test.js +0 -31
- package/build/browser/createAuthlessClient.test.js.map +0 -1
- package/build/browser/publicOauth.test.js +0 -430
- package/build/browser/publicOauth.test.js.map +0 -1
- package/build/esm/AuthorizationServer.test.js +0 -53
- package/build/esm/AuthorizationServer.test.js.map +0 -1
- package/build/esm/__tests__/createPublicOauthClient.test.js +0 -59
- package/build/esm/__tests__/createPublicOauthClient.test.js.map +0 -1
- package/build/esm/common.test.js +0 -68
- package/build/esm/common.test.js.map +0 -1
- package/build/esm/createAuthlessClient.test.js +0 -31
- package/build/esm/createAuthlessClient.test.js.map +0 -1
- package/build/esm/publicOauth.test.js +0 -430
- package/build/esm/publicOauth.test.js.map +0 -1
- package/build/types/AuthorizationServer.test.d.ts +0 -1
- package/build/types/AuthorizationServer.test.d.ts.map +0 -1
- package/build/types/__tests__/createPublicOauthClient.test.d.ts +0 -1
- package/build/types/__tests__/createPublicOauthClient.test.d.ts.map +0 -1
- package/build/types/common.test.d.ts +0 -1
- package/build/types/common.test.d.ts.map +0 -1
- package/build/types/createAuthlessClient.test.d.ts +0 -1
- package/build/types/createAuthlessClient.test.d.ts.map +0 -1
- package/build/types/publicOauth.test.d.ts +0 -1
- package/build/types/publicOauth.test.d.ts.map +0 -1
package/build/cjs/index.d.cts
CHANGED
|
@@ -42,6 +42,10 @@ interface ConfidentialOauthClient extends BaseOauthClient<"signIn" | "signOut">
|
|
|
42
42
|
*/
|
|
43
43
|
declare function createConfidentialOauthClient(client_id: string, client_secret: string, url: string, scopes?: string[], fetchFn?: typeof globalThis.fetch, ctxPath?: string): ConfidentialOauthClient;
|
|
44
44
|
|
|
45
|
+
interface OauthLogger {
|
|
46
|
+
warn: (...args: any[]) => void;
|
|
47
|
+
}
|
|
48
|
+
|
|
45
49
|
interface PublicOauthClient extends BaseOauthClient<"signIn" | "signOut" | "refresh"> {
|
|
46
50
|
refresh: () => Promise<Token | undefined>;
|
|
47
51
|
}
|
|
@@ -90,6 +94,11 @@ interface PublicOauthClientOptions {
|
|
|
90
94
|
* @default 'localStorage'
|
|
91
95
|
*/
|
|
92
96
|
tokenStorage?: TokenStorageType;
|
|
97
|
+
/**
|
|
98
|
+
* Optional logger for warning messages. If not provided, warnings are silently dropped.
|
|
99
|
+
* Structurally compatible with `@osdk/api`'s `Logger`.
|
|
100
|
+
*/
|
|
101
|
+
logger?: OauthLogger;
|
|
93
102
|
}
|
|
94
103
|
/**
|
|
95
104
|
* Creates a PublicOauthClient for authentication.
|
|
@@ -117,4 +126,4 @@ declare function createPublicOauthClient(clientId: string, url: string, redirect
|
|
|
117
126
|
*/
|
|
118
127
|
declare function createPublicOauthClient(client_id: string, url: string, redirectUrl: string, useHistory?: boolean, loginPage?: string, postLoginPage?: string, scopes?: string[], fetchFn?: typeof globalThis.fetch, ctxPath?: string): PublicOauthClient;
|
|
119
128
|
|
|
120
|
-
export { type ConfidentialOauthClient, type PublicOauthClient, type PublicOauthClientOptions, type TokenStorageType, createConfidentialOauthClient, createPublicOauthClient };
|
|
129
|
+
export { type ConfidentialOauthClient, type OauthLogger, type PublicOauthClient, type PublicOauthClientOptions, type TokenStorageType, createConfidentialOauthClient, createPublicOauthClient };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.js","names":[],"sources":["Logger.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport interface OauthLogger {\n warn: (...args: any[]) => void;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -49,6 +49,7 @@ export function createPublicOauthClient(client_id, url, redirect_uri, useHistory
|
|
|
49
49
|
let refreshTokenMarker;
|
|
50
50
|
let joinedScopes;
|
|
51
51
|
let tokenStorage;
|
|
52
|
+
let logger;
|
|
52
53
|
({
|
|
53
54
|
useHistory,
|
|
54
55
|
loginPage,
|
|
@@ -57,7 +58,8 @@ export function createPublicOauthClient(client_id, url, redirect_uri, useHistory
|
|
|
57
58
|
fetchFn,
|
|
58
59
|
ctxPath,
|
|
59
60
|
refreshTokenMarker,
|
|
60
|
-
tokenStorage
|
|
61
|
+
tokenStorage,
|
|
62
|
+
logger
|
|
61
63
|
} = processOptionsAndAssignDefaults(url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath));
|
|
62
64
|
const client = {
|
|
63
65
|
client_id,
|
|
@@ -119,8 +121,7 @@ export function createPublicOauthClient(client_id, url, redirect_uri, useHistory
|
|
|
119
121
|
return result;
|
|
120
122
|
} catch (e) {
|
|
121
123
|
if (process.env.NODE_ENV !== "production") {
|
|
122
|
-
|
|
123
|
-
console.warn("Failed to get OAuth2 refresh token. Removing refresh token", e);
|
|
124
|
+
logger?.warn("Failed to get OAuth2 refresh token. Removing refresh token", e);
|
|
124
125
|
}
|
|
125
126
|
removeLocal(client, storage);
|
|
126
127
|
if (expectRefreshToken) {
|
|
@@ -141,8 +142,7 @@ export function createPublicOauthClient(client_id, url, redirect_uri, useHistory
|
|
|
141
142
|
return ret;
|
|
142
143
|
} catch (e) {
|
|
143
144
|
if (process.env.NODE_ENV !== "production") {
|
|
144
|
-
|
|
145
|
-
console.warn("Failed to get OAuth2 token using PKCE, removing PKCE and starting a new auth flow", e);
|
|
145
|
+
logger?.warn("Failed to get OAuth2 token using PKCE, removing PKCE and starting a new auth flow", e);
|
|
146
146
|
}
|
|
147
147
|
removeLocal(client, storage);
|
|
148
148
|
removeSession(client);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPublicOauthClient.js","names":["authorizationCodeGrantRequest","calculatePKCECodeChallenge","customFetch","generateRandomCodeVerifier","generateRandomState","processAuthorizationCodeOAuth2Response","refreshTokenGrantRequest","validateAuthResponse","common","createAuthorizationServer","getStorage","readLocal","readSession","removeLocal","removeSession","saveLocal","saveSession","delay","throwIfError","processOptionsAndAssignDefaults","createPublicOauthClient","client_id","url","redirect_uri","useHistory","loginPage","postLoginPage","scopes","fetchFn","ctxPath","refreshTokenMarker","joinedScopes","tokenStorage","client","token_endpoint_auth_method","authServer","oauthHttpOptions","storage","makeTokenAndSaveRefresh","getToken","_signIn","maybeRefresh","maybeHandleAuthReturn","initiateLoginRedirect","bind","globalThis","go","x","window","history","replaceState","location","assign","Error","expectRefreshToken","refresh_token","lastRefreshTokenMarker","requestedScopes","initialRequestedScopes","areScopesEqual","result","pathname","URL","oldUrl","e","process","env","NODE_ENV","console","warn","state","codeVerifier","ret","href","toString","scopeString","authorization_endpoint","URLSearchParams","response_type","code_challenge","code_challenge_method","scope"],"sources":["createPublicOauthClient.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Client, HttpRequestOptions } from \"oauth4webapi\";\nimport {\n authorizationCodeGrantRequest,\n calculatePKCECodeChallenge,\n customFetch,\n generateRandomCodeVerifier,\n generateRandomState,\n processAuthorizationCodeOAuth2Response,\n refreshTokenGrantRequest,\n validateAuthResponse,\n} from \"oauth4webapi\";\nimport {\n common,\n createAuthorizationServer,\n getStorage,\n readLocal,\n readSession,\n removeLocal,\n removeSession,\n saveLocal,\n saveSession,\n} from \"./common.js\";\nimport type { TokenStorageType } from \"./common.js\";\nimport { delay } from \"./delay.js\";\nimport type { PublicOauthClient } from \"./PublicOauthClient.js\";\nimport { throwIfError } from \"./throwIfError.js\";\nimport type { Token } from \"./Token.js\";\nimport { processOptionsAndAssignDefaults } from \"./utils.js\";\n\ndeclare const process: {\n env: {\n NODE_ENV: \"production\" | \"development\";\n TARGET: \"browser\" | \"node\";\n };\n};\n\nexport interface PublicOauthClientOptions {\n /**\n * If true, uses `history.replaceState()`, otherwise uses `window.location.assign()` (defaults to true)\n */\n useHistory?: boolean;\n\n /**\n * Custom landing page URL prior to logging in\n */\n loginPage?: string;\n\n /**\n * URL to return to after completed authentication cycle (defaults to `window.location.toString()`)\n */\n postLoginPage?: string;\n\n /**\n * * @param {string[]} [scopes=[]] - OAuth scopes to request. If not provided, defaults to `[\"api:read-data\", \"api:write-data\", \"api:use-ontologies-read\", \"api:use-ontologies-write\"]`\n */\n scopes?: string[];\n\n /**\n * Custom fetch function to use for requests (defaults to `globalThis.fetch`)\n */\n fetchFn?: typeof globalThis.fetch;\n\n /**\n * Context path for the authorization server (defaults to \"multipass\")\n */\n ctxPath?: string;\n\n /**\n * Allows for an additional value to be appended to the local storage key for the refresh token.\n */\n refreshTokenMarker?: string;\n\n /**\n * Controls how refresh tokens are stored. Affects security vs. convenience tradeoff.\n *\n * - `'localStorage'` (default): Tokens persist across browser sessions.\n * Best UX but vulnerable on shared devices.\n *\n * - `'sessionStorage'`: Tokens cleared when browser/tab closes.\n * Recommended for shared devices. Users re-authenticate each browser session.\n *\n * - `'none'`: Tokens never stored. Users re-authenticate on every page load.\n * Most secure but worst UX. Does not request `offline_access` scope.\n *\n * @default 'localStorage'\n */\n tokenStorage?: TokenStorageType;\n}\n\n/**\n * Creates a PublicOauthClient for authentication.\n *\n * @param {string} clientId - The client_id from the OAuth configuration on the server\n * @param {string} url - The base URL of your Foundry server\n * @param {string} redirectUrl - The URL configured for redirect in the OAuth configuration on the server\n * @param {PublicOauthClientOptions} options - Additional options for the client\n * @returns {PublicOauthClient} A client that can be used as a token provider\n */\nexport function createPublicOauthClient(\n clientId: string,\n url: string,\n redirectUrl: string,\n options?: PublicOauthClientOptions,\n): PublicOauthClient;\n\n/**\n * Creates a PublicOauthClient for authentication.\n *\n * @param {string} clientId - The client_id from the OAuth configuration on the server\n * @param {string} url - The base URL of your Foundry server\n * @param {string} redirectUrl - The URL configured for redirect in the OAuth configuration on the server\n * @param {boolean} useHistory - If true, uses `history.replaceState()`, otherwise uses `window.location.assign()` (defaults to true)\n * @param {string} loginPage - Custom landing page URL prior to logging in\n * @param {string} postLoginPage - URL to return to after completed authentication cycle (defaults to `window.location.toString()`)\n * @param {string[]} scopes - OAuth scopes to request. If not provided, defaults to `[\"api:read-data\", \"api:write-data\", \"api:use-ontologies-read\", \"api:use-ontologies-write\"]`\n * @param {typeof globalThis.fetch} fetchFn - Custom fetch function to use for requests (defaults to `globalThis.fetch`)\n * @param {string} ctxPath - Context path for the authorization server (defaults to \"multipass\")\n * @returns {PublicOauthClient} A client that can be used as a token provider\n */\nexport function createPublicOauthClient(\n client_id: string,\n url: string,\n redirectUrl: string,\n useHistory?: boolean,\n loginPage?: string,\n postLoginPage?: string,\n scopes?: string[],\n fetchFn?: typeof globalThis.fetch,\n ctxPath?: string,\n): PublicOauthClient;\nexport function createPublicOauthClient(\n client_id: string,\n url: string,\n redirect_uri: string,\n useHistory?: boolean | PublicOauthClientOptions,\n loginPage?: string,\n postLoginPage?: string,\n scopes?: string[],\n fetchFn?: typeof globalThis.fetch,\n ctxPath?: string,\n): PublicOauthClient {\n let refreshTokenMarker: string | undefined;\n let joinedScopes: string;\n let tokenStorage: TokenStorageType;\n ({\n useHistory,\n loginPage,\n postLoginPage,\n joinedScopes,\n fetchFn,\n ctxPath,\n refreshTokenMarker,\n tokenStorage,\n } = processOptionsAndAssignDefaults(\n url,\n redirect_uri,\n useHistory,\n loginPage,\n postLoginPage,\n scopes,\n fetchFn,\n ctxPath,\n ));\n\n const client: Client = {\n client_id,\n token_endpoint_auth_method: \"none\",\n };\n const authServer = createAuthorizationServer(ctxPath, url);\n const oauthHttpOptions: HttpRequestOptions = { [customFetch]: fetchFn };\n\n const storage = getStorage(tokenStorage);\n\n const { makeTokenAndSaveRefresh, getToken } = common(\n client,\n authServer,\n _signIn,\n oauthHttpOptions,\n maybeRefresh.bind(globalThis, true),\n refreshTokenMarker,\n joinedScopes,\n storage,\n );\n\n // as an arrow function, `useHistory` is known to be a boolean\n const go = async (x: string) => {\n if (useHistory) {\n window.history.replaceState({}, \"\", x);\n return;\n } else window.location.assign(x);\n\n await delay(1000);\n throw new Error(\"Unable to redirect\");\n };\n\n async function maybeRefresh(\n expectRefreshToken?: boolean,\n ): Promise<Token | undefined> {\n if (tokenStorage === \"none\") {\n if (expectRefreshToken) throw new Error(\"No refresh token found\");\n return;\n }\n\n const {\n refresh_token,\n refreshTokenMarker: lastRefreshTokenMarker,\n requestedScopes: initialRequestedScopes,\n } = readLocal(client, storage);\n\n const areScopesEqual = initialRequestedScopes != null\n && joinedScopes === initialRequestedScopes;\n\n if (\n !refresh_token || lastRefreshTokenMarker !== refreshTokenMarker\n || !areScopesEqual\n ) {\n if (expectRefreshToken) throw new Error(\"No refresh token found\");\n return;\n }\n\n try {\n // note, we don't use processRefreshTokenResponse because the mp oauth implementation\n // doesn't do refresh tokens quite right and this lets us skip the id check\n const result = makeTokenAndSaveRefresh(\n throwIfError(\n await processAuthorizationCodeOAuth2Response(\n authServer,\n client,\n await refreshTokenGrantRequest(\n authServer,\n client,\n refresh_token,\n oauthHttpOptions,\n ),\n ),\n ),\n \"refresh\",\n );\n\n if (\n result && window.location.pathname === new URL(redirect_uri).pathname\n ) {\n const { oldUrl } = readSession(client);\n // don't block on the redirect\n void go(oldUrl ?? \"/\");\n }\n return result;\n } catch (e) {\n if (process.env.NODE_ENV !== \"production\") {\n // eslint-disable-next-line no-console\n console.warn(\n \"Failed to get OAuth2 refresh token. Removing refresh token\",\n e,\n );\n }\n removeLocal(client, storage);\n if (expectRefreshToken) {\n throw new Error(\"Could not refresh token\");\n }\n }\n }\n\n async function maybeHandleAuthReturn() {\n const { state, oldUrl, codeVerifier } = readSession(client);\n if (!codeVerifier) return;\n\n try {\n const ret = makeTokenAndSaveRefresh(\n throwIfError(\n await processAuthorizationCodeOAuth2Response(\n authServer,\n client,\n await authorizationCodeGrantRequest(\n authServer,\n client,\n throwIfError(\n validateAuthResponse(\n authServer,\n client,\n new URL(window.location.href),\n state,\n ),\n ),\n redirect_uri,\n codeVerifier,\n oauthHttpOptions,\n ),\n ),\n ),\n \"signIn\",\n );\n\n void go(oldUrl);\n return ret;\n } catch (e) {\n if (process.env.NODE_ENV !== \"production\") {\n // eslint-disable-next-line no-console\n console.warn(\n \"Failed to get OAuth2 token using PKCE, removing PKCE and starting a new auth flow\",\n e,\n );\n }\n removeLocal(client, storage);\n removeSession(client);\n throw e;\n }\n }\n\n // As an arrow function, `scopes` and `postLoginPage` are known at compile time\n const initiateLoginRedirect = async (): Promise<void> => {\n if (\n loginPage\n && window.location.href !== loginPage\n && window.location.pathname !== loginPage\n ) {\n saveLocal(client, {}, storage);\n saveSession(client, { oldUrl: postLoginPage });\n await go(loginPage);\n return;\n }\n\n const state = generateRandomState()!;\n const codeVerifier = generateRandomCodeVerifier();\n const oldUrl = readSession(client).oldUrl ?? window.location.toString();\n saveLocal(client, {}, storage);\n saveSession(client, { codeVerifier, state, oldUrl });\n\n // Only request offline_access (refresh tokens) if we're going to store them\n const scopeString = tokenStorage === \"none\"\n ? joinedScopes\n : `offline_access ${joinedScopes}`;\n\n window.location.assign(`${authServer\n .authorization_endpoint!}?${new URLSearchParams({\n client_id,\n response_type: \"code\",\n state,\n redirect_uri,\n code_challenge: await calculatePKCECodeChallenge(codeVerifier),\n code_challenge_method: \"S256\",\n scope: scopeString,\n })}`);\n\n // Give time for redirect to happen\n await delay(1000);\n throw new Error(\"Unable to redirect\");\n };\n\n /** Will throw if there is no token! */\n async function _signIn() {\n // 1. Check if we have a refresh token in local storage\n return await maybeRefresh()\n // 2. If there is no refresh token we are likely trying to perform the callback\n ?? await maybeHandleAuthReturn()\n // 3. If we haven't been able to load the token from one of the two above ways, we need to make the initial auth request\n ?? await initiateLoginRedirect() as unknown as Token;\n }\n\n return getToken;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SACEA,6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,GACZ,kBAAkBA,YAAY,EAAE;IAEpCiB,MAAM,CAACG,QAAQ,CAACC,MAAM,CAAC,GAAGjB,UAAU,CACjCyC,sBAAsB,IAAK,IAAIC,eAAe,CAAC;MAChDxD,SAAS;MACTyD,aAAa,EAAE,MAAM;MACrBR,KAAK;MACL/C,YAAY;MACZwD,cAAc,EAAE,MAAM9E,0BAA0B,CAACsE,YAAY,CAAC;MAC9DS,qBAAqB,EAAE,MAAM;MAC7BC,KAAK,EAAEN;IACT,CAAC,CAAC,EAAE,CAAC;;IAEL;IACA,MAAM1D,KAAK,CAAC,IAAI,CAAC;IACjB,MAAM,IAAIoC,KAAK,CAAC,oBAAoB,CAAC;EACvC,CAAC;EAYD,OAAOd,QAAQ;AACjB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"createPublicOauthClient.js","names":["authorizationCodeGrantRequest","calculatePKCECodeChallenge","customFetch","generateRandomCodeVerifier","generateRandomState","processAuthorizationCodeOAuth2Response","refreshTokenGrantRequest","validateAuthResponse","common","createAuthorizationServer","getStorage","readLocal","readSession","removeLocal","removeSession","saveLocal","saveSession","delay","throwIfError","processOptionsAndAssignDefaults","createPublicOauthClient","client_id","url","redirect_uri","useHistory","loginPage","postLoginPage","scopes","fetchFn","ctxPath","refreshTokenMarker","joinedScopes","tokenStorage","logger","client","token_endpoint_auth_method","authServer","oauthHttpOptions","storage","makeTokenAndSaveRefresh","getToken","_signIn","maybeRefresh","maybeHandleAuthReturn","initiateLoginRedirect","bind","globalThis","go","x","window","history","replaceState","location","assign","Error","expectRefreshToken","refresh_token","lastRefreshTokenMarker","requestedScopes","initialRequestedScopes","areScopesEqual","result","pathname","URL","oldUrl","e","process","env","NODE_ENV","warn","state","codeVerifier","ret","href","toString","scopeString","authorization_endpoint","URLSearchParams","response_type","code_challenge","code_challenge_method","scope"],"sources":["createPublicOauthClient.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Client, HttpRequestOptions } from \"oauth4webapi\";\nimport {\n authorizationCodeGrantRequest,\n calculatePKCECodeChallenge,\n customFetch,\n generateRandomCodeVerifier,\n generateRandomState,\n processAuthorizationCodeOAuth2Response,\n refreshTokenGrantRequest,\n validateAuthResponse,\n} from \"oauth4webapi\";\nimport {\n common,\n createAuthorizationServer,\n getStorage,\n readLocal,\n readSession,\n removeLocal,\n removeSession,\n saveLocal,\n saveSession,\n} from \"./common.js\";\nimport type { TokenStorageType } from \"./common.js\";\nimport { delay } from \"./delay.js\";\nimport type { OauthLogger } from \"./Logger.js\";\nimport type { PublicOauthClient } from \"./PublicOauthClient.js\";\nimport { throwIfError } from \"./throwIfError.js\";\nimport type { Token } from \"./Token.js\";\nimport { processOptionsAndAssignDefaults } from \"./utils.js\";\n\ndeclare const process: {\n env: {\n NODE_ENV: \"production\" | \"development\";\n TARGET: \"browser\" | \"node\";\n };\n};\n\nexport interface PublicOauthClientOptions {\n /**\n * If true, uses `history.replaceState()`, otherwise uses `window.location.assign()` (defaults to true)\n */\n useHistory?: boolean;\n\n /**\n * Custom landing page URL prior to logging in\n */\n loginPage?: string;\n\n /**\n * URL to return to after completed authentication cycle (defaults to `window.location.toString()`)\n */\n postLoginPage?: string;\n\n /**\n * * @param {string[]} [scopes=[]] - OAuth scopes to request. If not provided, defaults to `[\"api:read-data\", \"api:write-data\", \"api:use-ontologies-read\", \"api:use-ontologies-write\"]`\n */\n scopes?: string[];\n\n /**\n * Custom fetch function to use for requests (defaults to `globalThis.fetch`)\n */\n fetchFn?: typeof globalThis.fetch;\n\n /**\n * Context path for the authorization server (defaults to \"multipass\")\n */\n ctxPath?: string;\n\n /**\n * Allows for an additional value to be appended to the local storage key for the refresh token.\n */\n refreshTokenMarker?: string;\n\n /**\n * Controls how refresh tokens are stored. Affects security vs. convenience tradeoff.\n *\n * - `'localStorage'` (default): Tokens persist across browser sessions.\n * Best UX but vulnerable on shared devices.\n *\n * - `'sessionStorage'`: Tokens cleared when browser/tab closes.\n * Recommended for shared devices. Users re-authenticate each browser session.\n *\n * - `'none'`: Tokens never stored. Users re-authenticate on every page load.\n * Most secure but worst UX. Does not request `offline_access` scope.\n *\n * @default 'localStorage'\n */\n tokenStorage?: TokenStorageType;\n\n /**\n * Optional logger for warning messages. If not provided, warnings are silently dropped.\n * Structurally compatible with `@osdk/api`'s `Logger`.\n */\n logger?: OauthLogger;\n}\n\n/**\n * Creates a PublicOauthClient for authentication.\n *\n * @param {string} clientId - The client_id from the OAuth configuration on the server\n * @param {string} url - The base URL of your Foundry server\n * @param {string} redirectUrl - The URL configured for redirect in the OAuth configuration on the server\n * @param {PublicOauthClientOptions} options - Additional options for the client\n * @returns {PublicOauthClient} A client that can be used as a token provider\n */\nexport function createPublicOauthClient(\n clientId: string,\n url: string,\n redirectUrl: string,\n options?: PublicOauthClientOptions,\n): PublicOauthClient;\n\n/**\n * Creates a PublicOauthClient for authentication.\n *\n * @param {string} clientId - The client_id from the OAuth configuration on the server\n * @param {string} url - The base URL of your Foundry server\n * @param {string} redirectUrl - The URL configured for redirect in the OAuth configuration on the server\n * @param {boolean} useHistory - If true, uses `history.replaceState()`, otherwise uses `window.location.assign()` (defaults to true)\n * @param {string} loginPage - Custom landing page URL prior to logging in\n * @param {string} postLoginPage - URL to return to after completed authentication cycle (defaults to `window.location.toString()`)\n * @param {string[]} scopes - OAuth scopes to request. If not provided, defaults to `[\"api:read-data\", \"api:write-data\", \"api:use-ontologies-read\", \"api:use-ontologies-write\"]`\n * @param {typeof globalThis.fetch} fetchFn - Custom fetch function to use for requests (defaults to `globalThis.fetch`)\n * @param {string} ctxPath - Context path for the authorization server (defaults to \"multipass\")\n * @returns {PublicOauthClient} A client that can be used as a token provider\n */\nexport function createPublicOauthClient(\n client_id: string,\n url: string,\n redirectUrl: string,\n useHistory?: boolean,\n loginPage?: string,\n postLoginPage?: string,\n scopes?: string[],\n fetchFn?: typeof globalThis.fetch,\n ctxPath?: string,\n): PublicOauthClient;\nexport function createPublicOauthClient(\n client_id: string,\n url: string,\n redirect_uri: string,\n useHistory?: boolean | PublicOauthClientOptions,\n loginPage?: string,\n postLoginPage?: string,\n scopes?: string[],\n fetchFn?: typeof globalThis.fetch,\n ctxPath?: string,\n): PublicOauthClient {\n let refreshTokenMarker: string | undefined;\n let joinedScopes: string;\n let tokenStorage: TokenStorageType;\n let logger: OauthLogger | undefined;\n ({\n useHistory,\n loginPage,\n postLoginPage,\n joinedScopes,\n fetchFn,\n ctxPath,\n refreshTokenMarker,\n tokenStorage,\n logger,\n } = processOptionsAndAssignDefaults(\n url,\n redirect_uri,\n useHistory,\n loginPage,\n postLoginPage,\n scopes,\n fetchFn,\n ctxPath,\n ));\n\n const client: Client = {\n client_id,\n token_endpoint_auth_method: \"none\",\n };\n const authServer = createAuthorizationServer(ctxPath, url);\n const oauthHttpOptions: HttpRequestOptions = { [customFetch]: fetchFn };\n\n const storage = getStorage(tokenStorage);\n\n const { makeTokenAndSaveRefresh, getToken } = common(\n client,\n authServer,\n _signIn,\n oauthHttpOptions,\n maybeRefresh.bind(globalThis, true),\n refreshTokenMarker,\n joinedScopes,\n storage,\n );\n\n // as an arrow function, `useHistory` is known to be a boolean\n const go = async (x: string) => {\n if (useHistory) {\n window.history.replaceState({}, \"\", x);\n return;\n } else window.location.assign(x);\n\n await delay(1000);\n throw new Error(\"Unable to redirect\");\n };\n\n async function maybeRefresh(\n expectRefreshToken?: boolean,\n ): Promise<Token | undefined> {\n if (tokenStorage === \"none\") {\n if (expectRefreshToken) throw new Error(\"No refresh token found\");\n return;\n }\n\n const {\n refresh_token,\n refreshTokenMarker: lastRefreshTokenMarker,\n requestedScopes: initialRequestedScopes,\n } = readLocal(client, storage);\n\n const areScopesEqual = initialRequestedScopes != null\n && joinedScopes === initialRequestedScopes;\n\n if (\n !refresh_token || lastRefreshTokenMarker !== refreshTokenMarker\n || !areScopesEqual\n ) {\n if (expectRefreshToken) throw new Error(\"No refresh token found\");\n return;\n }\n\n try {\n // note, we don't use processRefreshTokenResponse because the mp oauth implementation\n // doesn't do refresh tokens quite right and this lets us skip the id check\n const result = makeTokenAndSaveRefresh(\n throwIfError(\n await processAuthorizationCodeOAuth2Response(\n authServer,\n client,\n await refreshTokenGrantRequest(\n authServer,\n client,\n refresh_token,\n oauthHttpOptions,\n ),\n ),\n ),\n \"refresh\",\n );\n\n if (\n result && window.location.pathname === new URL(redirect_uri).pathname\n ) {\n const { oldUrl } = readSession(client);\n // don't block on the redirect\n void go(oldUrl ?? \"/\");\n }\n return result;\n } catch (e) {\n if (process.env.NODE_ENV !== \"production\") {\n logger?.warn(\n \"Failed to get OAuth2 refresh token. Removing refresh token\",\n e,\n );\n }\n removeLocal(client, storage);\n if (expectRefreshToken) {\n throw new Error(\"Could not refresh token\");\n }\n }\n }\n\n async function maybeHandleAuthReturn() {\n const { state, oldUrl, codeVerifier } = readSession(client);\n if (!codeVerifier) return;\n\n try {\n const ret = makeTokenAndSaveRefresh(\n throwIfError(\n await processAuthorizationCodeOAuth2Response(\n authServer,\n client,\n await authorizationCodeGrantRequest(\n authServer,\n client,\n throwIfError(\n validateAuthResponse(\n authServer,\n client,\n new URL(window.location.href),\n state,\n ),\n ),\n redirect_uri,\n codeVerifier,\n oauthHttpOptions,\n ),\n ),\n ),\n \"signIn\",\n );\n\n void go(oldUrl);\n return ret;\n } catch (e) {\n if (process.env.NODE_ENV !== \"production\") {\n logger?.warn(\n \"Failed to get OAuth2 token using PKCE, removing PKCE and starting a new auth flow\",\n e,\n );\n }\n removeLocal(client, storage);\n removeSession(client);\n throw e;\n }\n }\n\n // As an arrow function, `scopes` and `postLoginPage` are known at compile time\n const initiateLoginRedirect = async (): Promise<void> => {\n if (\n loginPage\n && window.location.href !== loginPage\n && window.location.pathname !== loginPage\n ) {\n saveLocal(client, {}, storage);\n saveSession(client, { oldUrl: postLoginPage });\n await go(loginPage);\n return;\n }\n\n const state = generateRandomState()!;\n const codeVerifier = generateRandomCodeVerifier();\n const oldUrl = readSession(client).oldUrl ?? window.location.toString();\n saveLocal(client, {}, storage);\n saveSession(client, { codeVerifier, state, oldUrl });\n\n // Only request offline_access (refresh tokens) if we're going to store them\n const scopeString = tokenStorage === \"none\"\n ? joinedScopes\n : `offline_access ${joinedScopes}`;\n\n window.location.assign(`${authServer\n .authorization_endpoint!}?${new URLSearchParams({\n client_id,\n response_type: \"code\",\n state,\n redirect_uri,\n code_challenge: await calculatePKCECodeChallenge(codeVerifier),\n code_challenge_method: \"S256\",\n scope: scopeString,\n })}`);\n\n // Give time for redirect to happen\n await delay(1000);\n throw new Error(\"Unable to redirect\");\n };\n\n /** Will throw if there is no token! */\n async function _signIn() {\n // 1. Check if we have a refresh token in local storage\n return await maybeRefresh()\n // 2. If there is no refresh token we are likely trying to perform the callback\n ?? await maybeHandleAuthReturn()\n // 3. If we haven't been able to load the token from one of the two above ways, we need to make the initial auth request\n ?? await initiateLoginRedirect() as unknown as Token;\n }\n\n return getToken;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SACEA,6BAA6B,EAC7BC,0BAA0B,EAC1BC,WAAW,EACXC,0BAA0B,EAC1BC,mBAAmB,EACnBC,sCAAsC,EACtCC,wBAAwB,EACxBC,oBAAoB,QACf,cAAc;AACrB,SACEC,MAAM,EACNC,yBAAyB,EACzBC,UAAU,EACVC,SAAS,EACTC,WAAW,EACXC,WAAW,EACXC,aAAa,EACbC,SAAS,EACTC,WAAW,QACN,aAAa;AAEpB,SAASC,KAAK,QAAQ,YAAY;AAGlC,SAASC,YAAY,QAAQ,mBAA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C7BC,KAAK,EAAEN;IACT,CAAC,CAAC,EAAE,CAAC;;IAEL;IACA,MAAM1D,KAAK,CAAC,IAAI,CAAC;IACjB,MAAM,IAAIqC,KAAK,CAAC,oBAAoB,CAAC;EACvC,CAAC;EAYD,OAAOd,QAAQ;AACjB","ignoreList":[]}
|
package/build/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["createConfidentialOauthClient","createPublicOauthClient"],"sources":["index.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport type { TokenStorageType } from \"./common.js\";\nexport type { ConfidentialOauthClient } from \"./ConfidentialOauthClient.js\";\nexport { createConfidentialOauthClient } from \"./createConfidentialOauthClient.js\";\nexport {\n createPublicOauthClient,\n type PublicOauthClientOptions,\n} from \"./createPublicOauthClient.js\";\nexport type { PublicOauthClient } from \"./PublicOauthClient.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,SAASA,6BAA6B,QAAQ,oCAAoC;AAClF,SACEC,uBAAuB,QAElB,8BAA8B","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["createConfidentialOauthClient","createPublicOauthClient"],"sources":["index.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport type { TokenStorageType } from \"./common.js\";\nexport type { ConfidentialOauthClient } from \"./ConfidentialOauthClient.js\";\nexport { createConfidentialOauthClient } from \"./createConfidentialOauthClient.js\";\nexport {\n createPublicOauthClient,\n type PublicOauthClientOptions,\n} from \"./createPublicOauthClient.js\";\nexport type { OauthLogger } from \"./Logger.js\";\nexport type { PublicOauthClient } from \"./PublicOauthClient.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,SAASA,6BAA6B,QAAQ,oCAAoC;AAClF,SACEC,uBAAuB,QAElB,8BAA8B","ignoreList":[]}
|
package/build/esm/utils.js
CHANGED
|
@@ -42,7 +42,8 @@ export function processOptionsAndAssignDefaults(url, redirect_uri, useHistory, l
|
|
|
42
42
|
fetchFn: options.fetchFn ?? globalThis.fetch,
|
|
43
43
|
ctxPath: options.ctxPath ?? "multipass",
|
|
44
44
|
refreshTokenMarker: options.refreshTokenMarker,
|
|
45
|
-
tokenStorage: options.tokenStorage ?? "localStorage"
|
|
45
|
+
tokenStorage: options.tokenStorage ?? "localStorage",
|
|
46
|
+
logger: options.logger
|
|
46
47
|
};
|
|
47
48
|
}
|
|
48
49
|
//# sourceMappingURL=utils.js.map
|
package/build/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["invariant","processOptionsAndAssignDefaults","url","redirect_uri","useHistory","loginPage","postLoginPage","scopes","fetchFn","ctxPath","options","process","env","NODE_ENV","window","location","toString","joinedScopes","sort","join","globalThis","fetch","refreshTokenMarker","tokenStorage"],"sources":["utils.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport invariant from \"tiny-invariant\";\nimport type { TokenStorageType } from \"./common.js\";\nimport type { PublicOauthClientOptions } from \"./createPublicOauthClient.js\";\n\ninterface ProcessedPublicOauthClientOptions extends\n Omit<\n Required<PublicOauthClientOptions>,\n \"loginPage\" | \"refreshTokenMarker\" | \"scopes\" | \"tokenStorage\"\n >\n{\n loginPage?: string;\n refreshTokenMarker?: string;\n joinedScopes: string;\n tokenStorage: TokenStorageType;\n}\n\nexport function processOptionsAndAssignDefaults(\n url: string,\n redirect_uri: string,\n useHistory?: boolean | PublicOauthClientOptions,\n loginPage?: string,\n postLoginPage?: string,\n scopes?: string[],\n fetchFn?: typeof globalThis.fetch,\n ctxPath?: string,\n): ProcessedPublicOauthClientOptions {\n let options: PublicOauthClientOptions = {};\n\n if (typeof useHistory === \"object\") {\n invariant(\n !loginPage && !postLoginPage && !scopes && !fetchFn && !ctxPath,\n \"If useHistory is an object, other options should not be provided\",\n );\n options = useHistory;\n } else {\n options = {\n useHistory,\n loginPage,\n postLoginPage,\n scopes,\n fetchFn,\n ctxPath,\n };\n }\n\n invariant(url, \"url is required\");\n invariant(redirect_uri, \"redirectUrl is required\");\n\n // Assign defaults\n return {\n useHistory: options.useHistory ?? true,\n loginPage: options.loginPage,\n postLoginPage: options.postLoginPage || window.location.toString(),\n joinedScopes: [\n ...options.scopes\n ?? [\n \"api:read-data\",\n \"api:write-data\",\n \"api:use-ontologies-read\",\n \"api:use-ontologies-write\",\n ],\n ]\n .sort().join(\" \"),\n fetchFn: options.fetchFn ?? globalThis.fetch,\n ctxPath: options.ctxPath ?? \"multipass\",\n refreshTokenMarker: options.refreshTokenMarker,\n tokenStorage: options.tokenStorage ?? \"localStorage\",\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,SAAS,MAAM,gBAAgB;
|
|
1
|
+
{"version":3,"file":"utils.js","names":["invariant","processOptionsAndAssignDefaults","url","redirect_uri","useHistory","loginPage","postLoginPage","scopes","fetchFn","ctxPath","options","process","env","NODE_ENV","window","location","toString","joinedScopes","sort","join","globalThis","fetch","refreshTokenMarker","tokenStorage","logger"],"sources":["utils.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport invariant from \"tiny-invariant\";\nimport type { TokenStorageType } from \"./common.js\";\nimport type { PublicOauthClientOptions } from \"./createPublicOauthClient.js\";\nimport type { OauthLogger } from \"./Logger.js\";\n\ninterface ProcessedPublicOauthClientOptions extends\n Omit<\n Required<PublicOauthClientOptions>,\n \"loginPage\" | \"refreshTokenMarker\" | \"scopes\" | \"tokenStorage\" | \"logger\"\n >\n{\n loginPage?: string;\n refreshTokenMarker?: string;\n joinedScopes: string;\n tokenStorage: TokenStorageType;\n logger?: OauthLogger;\n}\n\nexport function processOptionsAndAssignDefaults(\n url: string,\n redirect_uri: string,\n useHistory?: boolean | PublicOauthClientOptions,\n loginPage?: string,\n postLoginPage?: string,\n scopes?: string[],\n fetchFn?: typeof globalThis.fetch,\n ctxPath?: string,\n): ProcessedPublicOauthClientOptions {\n let options: PublicOauthClientOptions = {};\n\n if (typeof useHistory === \"object\") {\n invariant(\n !loginPage && !postLoginPage && !scopes && !fetchFn && !ctxPath,\n \"If useHistory is an object, other options should not be provided\",\n );\n options = useHistory;\n } else {\n options = {\n useHistory,\n loginPage,\n postLoginPage,\n scopes,\n fetchFn,\n ctxPath,\n };\n }\n\n invariant(url, \"url is required\");\n invariant(redirect_uri, \"redirectUrl is required\");\n\n // Assign defaults\n return {\n useHistory: options.useHistory ?? true,\n loginPage: options.loginPage,\n postLoginPage: options.postLoginPage || window.location.toString(),\n joinedScopes: [\n ...options.scopes\n ?? [\n \"api:read-data\",\n \"api:write-data\",\n \"api:use-ontologies-read\",\n \"api:use-ontologies-write\",\n ],\n ]\n .sort().join(\" \"),\n fetchFn: options.fetchFn ?? globalThis.fetch,\n ctxPath: options.ctxPath ?? \"multipass\",\n refreshTokenMarker: options.refreshTokenMarker,\n tokenStorage: options.tokenStorage ?? \"localStorage\",\n logger: options.logger,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,SAAS,MAAM,gBAAgB;AAkBtC,OAAO,SAASC,+BAA+BA,CAC7CC,GAAW,EACXC,YAAoB,EACpBC,UAA+C,EAC/CC,SAAkB,EAClBC,aAAsB,EACtBC,MAAiB,EACjBC,OAAiC,EACjCC,OAAgB,EACmB;EACnC,IAAIC,OAAiC,GAAG,CAAC,CAAC;EAE1C,IAAI,OAAON,UAAU,KAAK,QAAQ,EAAE;IAClC,EACE,CAACC,SAAS,IAAI,CAACC,aAAa,IAAI,CAACC,MAAM,IAAI,CAACC,OAAO,IAAI,CAACC,OAAO,IAAAE,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBADjEb,SAAS,QAEP,kEAAkE,IAFpEA,SAAS;IAITU,OAAO,GAAGN,UAAU;EACtB,CAAC,MAAM;IACLM,OAAO,GAAG;MACRN,UAAU;MACVC,SAAS;MACTC,aAAa;MACbC,MAAM;MACNC,OAAO;MACPC;IACF,CAAC;EACH;EAEA,CAAUP,GAAG,GAAAS,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAbb,SAAS,QAAM,iBAAiB,IAAhCA,SAAS;EACT,CAAUG,YAAY,GAAAQ,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAtBb,SAAS,QAAe,yBAAyB,IAAjDA,SAAS;;EAET;EACA,OAAO;IACLI,UAAU,EAAEM,OAAO,CAACN,UAAU,IAAI,IAAI;IACtCC,SAAS,EAAEK,OAAO,CAACL,SAAS;IAC5BC,aAAa,EAAEI,OAAO,CAACJ,aAAa,IAAIQ,MAAM,CAACC,QAAQ,CAACC,QAAQ,CAAC,CAAC;IAClEC,YAAY,EAAE,CACZ,IAAGP,OAAO,CAACH,MAAM,IACZ,CACD,eAAe,EACf,gBAAgB,EAChB,yBAAyB,EACzB,0BAA0B,CAC3B,EACJ,CACEW,IAAI,CAAC,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;IACnBX,OAAO,EAAEE,OAAO,CAACF,OAAO,IAAIY,UAAU,CAACC,KAAK;IAC5CZ,OAAO,EAAEC,OAAO,CAACD,OAAO,IAAI,WAAW;IACvCa,kBAAkB,EAAEZ,OAAO,CAACY,kBAAkB;IAC9CC,YAAY,EAAEb,OAAO,CAACa,YAAY,IAAI,cAAc;IACpDC,MAAM,EAAEd,OAAO,CAACc;EAClB,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,iBAAiB,YAAY;CAC3B,OAAO,GAAG;AACX","names":[],"sources":["../../src/Logger.ts"],"version":3,"file":"Logger.d.ts"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TokenStorageType } from "./common.js";
|
|
2
|
+
import type { OauthLogger } from "./Logger.js";
|
|
2
3
|
import type { PublicOauthClient } from "./PublicOauthClient.js";
|
|
3
4
|
export interface PublicOauthClientOptions {
|
|
4
5
|
/**
|
|
@@ -44,6 +45,11 @@ export interface PublicOauthClientOptions {
|
|
|
44
45
|
* @default 'localStorage'
|
|
45
46
|
*/
|
|
46
47
|
tokenStorage?: TokenStorageType;
|
|
48
|
+
/**
|
|
49
|
+
* Optional logger for warning messages. If not provided, warnings are silently dropped.
|
|
50
|
+
* Structurally compatible with `@osdk/api`'s `Logger`.
|
|
51
|
+
*/
|
|
52
|
+
logger?: OauthLogger;
|
|
47
53
|
}
|
|
48
54
|
/**
|
|
49
55
|
* Creates a PublicOauthClient for authentication.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAsCA,cAAc,wBAAwB,aAAc;AAEpD,cAAc,yBAAyB,wBAAyB;AAYhE,iBAAiB,yBAAyB;;;;CAIxC;;;;CAKA;;;;CAKA;;;;CAKA;;;;CAKA,iBAAiB,WAAW;;;;CAK5B;;;;CAKA;;;;;;;;;;;;;;;CAgBA,eAAe;
|
|
1
|
+
{"mappings":"AAsCA,cAAc,wBAAwB,aAAc;AAEpD,cAAc,mBAAmB,aAAc;AAC/C,cAAc,yBAAyB,wBAAyB;AAYhE,iBAAiB,yBAAyB;;;;CAIxC;;;;CAKA;;;;CAKA;;;;CAKA;;;;CAKA,iBAAiB,WAAW;;;;CAK5B;;;;CAKA;;;;;;;;;;;;;;;CAgBA,eAAe;;;;;CAMf,SAAS;AACV;;;;;;;;;;AAWD,OAAO,iBAAS,wBACdA,kBACAC,aACAC,qBACAC,UAAU,2BACT;;;;;;;;;;;;;;;AAgBH,OAAO,iBAAS,wBACdC,mBACAH,aACAC,qBACAG,sBACAC,oBACAC,wBACAC,mBACAC,iBAAiB,WAAW,OAC5BC,mBACC","names":["clientId: string","url: string","redirectUrl: string","options?: PublicOauthClientOptions","client_id: string","useHistory?: boolean","loginPage?: string","postLoginPage?: string","scopes?: string[]","fetchFn?: typeof globalThis.fetch","ctxPath?: string"],"sources":["../../src/createPublicOauthClient.ts"],"version":3,"file":"createPublicOauthClient.d.ts"}
|
package/build/types/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ export type { TokenStorageType } from "./common.js";
|
|
|
2
2
|
export type { ConfidentialOauthClient } from "./ConfidentialOauthClient.js";
|
|
3
3
|
export { createConfidentialOauthClient } from "./createConfidentialOauthClient.js";
|
|
4
4
|
export { createPublicOauthClient, type PublicOauthClientOptions } from "./createPublicOauthClient.js";
|
|
5
|
+
export type { OauthLogger } from "./Logger.js";
|
|
5
6
|
export type { PublicOauthClient } from "./PublicOauthClient.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,cAAc,wBAAwB;AACtC,cAAc,+BAA+B;AAC7C,SAAS,qCAAqC;AAC9C,SACE,8BACK,gCACA;AACP,cAAc,yBAAyB","names":[],"sources":["../../src/index.ts"],"version":3,"file":"index.d.ts"}
|
|
1
|
+
{"mappings":"AAgBA,cAAc,wBAAwB;AACtC,cAAc,+BAA+B;AAC7C,SAAS,qCAAqC;AAC9C,SACE,8BACK,gCACA;AACP,cAAc,mBAAmB;AACjC,cAAc,yBAAyB","names":[],"sources":["../../src/index.ts"],"version":3,"file":"index.d.ts"}
|
package/build/types/utils.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { TokenStorageType } from "./common.js";
|
|
2
2
|
import type { PublicOauthClientOptions } from "./createPublicOauthClient.js";
|
|
3
|
-
|
|
3
|
+
import type { OauthLogger } from "./Logger.js";
|
|
4
|
+
interface ProcessedPublicOauthClientOptions extends Omit<Required<PublicOauthClientOptions>, "loginPage" | "refreshTokenMarker" | "scopes" | "tokenStorage" | "logger"> {
|
|
4
5
|
loginPage?: string;
|
|
5
6
|
refreshTokenMarker?: string;
|
|
6
7
|
joinedScopes: string;
|
|
7
8
|
tokenStorage: TokenStorageType;
|
|
9
|
+
logger?: OauthLogger;
|
|
8
10
|
}
|
|
9
11
|
export declare function processOptionsAndAssignDefaults(url: string, redirect_uri: string, useHistory?: boolean | PublicOauthClientOptions, loginPage?: string, postLoginPage?: string, scopes?: string[], fetchFn?: typeof globalThis.fetch, ctxPath?: string): ProcessedPublicOauthClientOptions;
|
|
10
12
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAiBA,cAAc,wBAAwB,aAAc;AACpD,cAAc,gCAAgC,8BAA+B;
|
|
1
|
+
{"mappings":"AAiBA,cAAc,wBAAwB,aAAc;AACpD,cAAc,gCAAgC,8BAA+B;AAC7E,cAAc,mBAAmB,aAAc;UAErC,0CACR,KACE,SAAS,2BACT,cAAc,uBAAuB,WAAW,iBAAiB,UAErE;CACE;CACA;CACA;CACA,cAAc;CACd,SAAS;AACV;AAED,OAAO,iBAAS,gCACdA,aACAC,sBACAC,uBAAuB,0BACvBC,oBACAC,wBACAC,mBACAC,iBAAiB,WAAW,OAC5BC,mBACC","names":["url: string","redirect_uri: string","useHistory?: boolean | PublicOauthClientOptions","loginPage?: string","postLoginPage?: string","scopes?: string[]","fetchFn?: typeof globalThis.fetch","ctxPath?: string"],"sources":["../../src/utils.ts"],"version":3,"file":"utils.d.ts"}
|
package/package.json
CHANGED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { describe, expect, it } from "vitest";
|
|
18
|
-
import { createAuthorizationServer } from "./common.js";
|
|
19
|
-
describe("Create authorization server", () => {
|
|
20
|
-
it("works with old multipass ctx path", () => {
|
|
21
|
-
const authServer = createAuthorizationServer("/multipass", "https://stack.palantir.com");
|
|
22
|
-
expect(authServer).toEqual({
|
|
23
|
-
token_endpoint: "https://stack.palantir.com/multipass/api/oauth2/token",
|
|
24
|
-
authorization_endpoint: "https://stack.palantir.com/multipass/api/oauth2/authorize",
|
|
25
|
-
revocation_endpoint: "https://stack.palantir.com/multipass/api/oauth2/revoke_token",
|
|
26
|
-
issuer: "https://stack.palantir.com/multipass"
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
it("works with new multipass ctx path", () => {
|
|
30
|
-
const authServer = createAuthorizationServer("multipass", "https://stack.palantir.com");
|
|
31
|
-
expect(authServer).toEqual({
|
|
32
|
-
token_endpoint: "https://stack.palantir.com/multipass/api/oauth2/token",
|
|
33
|
-
authorization_endpoint: "https://stack.palantir.com/multipass/api/oauth2/authorize",
|
|
34
|
-
revocation_endpoint: "https://stack.palantir.com/multipass/api/oauth2/revoke_token",
|
|
35
|
-
issuer: "https://stack.palantir.com/multipass"
|
|
36
|
-
});
|
|
37
|
-
const authServerCustom = createAuthorizationServer("multipass", "https://stack.palantir.com/foo/first/someStuff");
|
|
38
|
-
expect(authServerCustom).toEqual({
|
|
39
|
-
token_endpoint: "https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/token",
|
|
40
|
-
authorization_endpoint: "https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/authorize",
|
|
41
|
-
revocation_endpoint: "https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/revoke_token",
|
|
42
|
-
issuer: "https://stack.palantir.com/foo/first/someStuff/multipass"
|
|
43
|
-
});
|
|
44
|
-
const authServerCustomWithTrailingSlash = createAuthorizationServer("multipass", "https://stack.palantir.com/foo/first/someStuff/");
|
|
45
|
-
expect(authServerCustomWithTrailingSlash).toEqual({
|
|
46
|
-
token_endpoint: "https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/token",
|
|
47
|
-
authorization_endpoint: "https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/authorize",
|
|
48
|
-
revocation_endpoint: "https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/revoke_token",
|
|
49
|
-
issuer: "https://stack.palantir.com/foo/first/someStuff/multipass"
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
//# sourceMappingURL=AuthorizationServer.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AuthorizationServer.test.js","names":["describe","expect","it","createAuthorizationServer","authServer","toEqual","token_endpoint","authorization_endpoint","revocation_endpoint","issuer","authServerCustom","authServerCustomWithTrailingSlash"],"sources":["AuthorizationServer.test.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { describe, expect, it } from \"vitest\";\n\nimport { createAuthorizationServer } from \"./common.js\";\n\ndescribe(\"Create authorization server\", () => {\n it(\"works with old multipass ctx path\", () => {\n const authServer = createAuthorizationServer(\n \"/multipass\",\n \"https://stack.palantir.com\",\n );\n expect(authServer).toEqual({\n token_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/token\",\n authorization_endpoint:\n \"https://stack.palantir.com/multipass/api/oauth2/authorize\",\n revocation_endpoint:\n \"https://stack.palantir.com/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/multipass\",\n });\n });\n\n it(\"works with new multipass ctx path\", () => {\n const authServer = createAuthorizationServer(\n \"multipass\",\n \"https://stack.palantir.com\",\n );\n expect(authServer).toEqual({\n token_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/token\",\n authorization_endpoint:\n \"https://stack.palantir.com/multipass/api/oauth2/authorize\",\n revocation_endpoint:\n \"https://stack.palantir.com/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/multipass\",\n });\n\n const authServerCustom = createAuthorizationServer(\n \"multipass\",\n \"https://stack.palantir.com/foo/first/someStuff\",\n );\n expect(authServerCustom).toEqual({\n token_endpoint:\n \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/token\",\n authorization_endpoint:\n \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/authorize\",\n revocation_endpoint:\n \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/foo/first/someStuff/multipass\",\n });\n const authServerCustomWithTrailingSlash = createAuthorizationServer(\n \"multipass\",\n \"https://stack.palantir.com/foo/first/someStuff/\",\n );\n expect(authServerCustomWithTrailingSlash).toEqual({\n token_endpoint:\n \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/token\",\n authorization_endpoint:\n \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/authorize\",\n revocation_endpoint:\n \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/foo/first/someStuff/multipass\",\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAE7C,SAASC,yBAAyB,QAAQ,aAAa;AAEvDH,QAAQ,CAAC,6BAA6B,EAAE,MAAM;EAC5CE,EAAE,CAAC,mCAAmC,EAAE,MAAM;IAC5C,MAAME,UAAU,GAAGD,yBAAyB,CAC1C,YAAY,EACZ,4BACF,CAAC;IACDF,MAAM,CAACG,UAAU,CAAC,CAACC,OAAO,CAAC;MACzBC,cAAc,EAAE,uDAAuD;MACvEC,sBAAsB,EACpB,2DAA2D;MAC7DC,mBAAmB,EACjB,8DAA8D;MAChEC,MAAM,EAAE;IACV,CAAC,CAAC;EACJ,CAAC,CAAC;EAEFP,EAAE,CAAC,mCAAmC,EAAE,MAAM;IAC5C,MAAME,UAAU,GAAGD,yBAAyB,CAC1C,WAAW,EACX,4BACF,CAAC;IACDF,MAAM,CAACG,UAAU,CAAC,CAACC,OAAO,CAAC;MACzBC,cAAc,EAAE,uDAAuD;MACvEC,sBAAsB,EACpB,2DAA2D;MAC7DC,mBAAmB,EACjB,8DAA8D;MAChEC,MAAM,EAAE;IACV,CAAC,CAAC;IAEF,MAAMC,gBAAgB,GAAGP,yBAAyB,CAChD,WAAW,EACX,gDACF,CAAC;IACDF,MAAM,CAACS,gBAAgB,CAAC,CAACL,OAAO,CAAC;MAC/BC,cAAc,EACZ,2EAA2E;MAC7EC,sBAAsB,EACpB,+EAA+E;MACjFC,mBAAmB,EACjB,kFAAkF;MACpFC,MAAM,EAAE;IACV,CAAC,CAAC;IACF,MAAME,iCAAiC,GAAGR,yBAAyB,CACjE,WAAW,EACX,iDACF,CAAC;IACDF,MAAM,CAACU,iCAAiC,CAAC,CAACN,OAAO,CAAC;MAChDC,cAAc,EACZ,2EAA2E;MAC7EC,sBAAsB,EACpB,+EAA+E;MACjFC,mBAAmB,EACjB,kFAAkF;MACpFC,MAAM,EAAE;IACV,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { createPublicOauthClient } from "@osdk/oauth";
|
|
18
|
-
import * as oauthModule from "@osdk/oauth";
|
|
19
|
-
import { describe, expect, it, vi } from "vitest";
|
|
20
|
-
import * as utilsModule from "../utils.js";
|
|
21
|
-
const originalCreatePublicOauthClient = oauthModule.createPublicOauthClient;
|
|
22
|
-
const FOUNDRY_CLIENT_ID = "example-foundry-client-id";
|
|
23
|
-
const FOUNDRY_URL = "http://example-foundry-url.com";
|
|
24
|
-
const REDIRECT_URI = "http://localhost:8080/auth/callback";
|
|
25
|
-
vi.stubGlobal("window", {
|
|
26
|
-
location: {
|
|
27
|
-
toString: vi.fn().mockReturnValue("http://example.com")
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
describe("createPublicOauthClient", () => {
|
|
31
|
-
it("should return the same processed options for both client creation methods", async () => {
|
|
32
|
-
const mockProcessOptionsAndAssignDefaults = vi.fn();
|
|
33
|
-
|
|
34
|
-
// Mock processOptionsAndAssignDefaults to call the mock function
|
|
35
|
-
vi.spyOn(utilsModule, "processOptionsAndAssignDefaults").mockImplementation((...args) => {
|
|
36
|
-
mockProcessOptionsAndAssignDefaults(...args);
|
|
37
|
-
return utilsModule.processOptionsAndAssignDefaults(...args);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// Mock createPublicOauthClient to call both the mock and the original function
|
|
41
|
-
vi.spyOn(oauthModule, "createPublicOauthClient").mockImplementation((...args) => {
|
|
42
|
-
const [_client_id, ...rest] = args;
|
|
43
|
-
mockProcessOptionsAndAssignDefaults(...rest);
|
|
44
|
-
return originalCreatePublicOauthClient(...args);
|
|
45
|
-
});
|
|
46
|
-
const authClient = createPublicOauthClient(FOUNDRY_CLIENT_ID, FOUNDRY_URL, REDIRECT_URI, true, undefined, undefined, undefined, fetch, undefined);
|
|
47
|
-
expect(authClient).toBeDefined();
|
|
48
|
-
expect(mockProcessOptionsAndAssignDefaults).toHaveBeenCalledTimes(1);
|
|
49
|
-
const authClientWithOptions = createPublicOauthClient(FOUNDRY_CLIENT_ID, FOUNDRY_URL, REDIRECT_URI, {
|
|
50
|
-
useHistory: true,
|
|
51
|
-
fetchFn: fetch
|
|
52
|
-
});
|
|
53
|
-
expect(authClientWithOptions).toBeDefined();
|
|
54
|
-
expect(mockProcessOptionsAndAssignDefaults).toHaveBeenCalledTimes(2);
|
|
55
|
-
const [result1, result2] = mockProcessOptionsAndAssignDefaults.mock.results;
|
|
56
|
-
expect(result1.value).toEqual(result2.value);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
//# sourceMappingURL=createPublicOauthClient.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createPublicOauthClient.test.js","names":["createPublicOauthClient","oauthModule","describe","expect","it","vi","utilsModule","originalCreatePublicOauthClient","FOUNDRY_CLIENT_ID","FOUNDRY_URL","REDIRECT_URI","stubGlobal","location","toString","fn","mockReturnValue","mockProcessOptionsAndAssignDefaults","spyOn","mockImplementation","args","processOptionsAndAssignDefaults","_client_id","rest","authClient","undefined","fetch","toBeDefined","toHaveBeenCalledTimes","authClientWithOptions","useHistory","fetchFn","result1","result2","mock","results","value","toEqual"],"sources":["createPublicOauthClient.test.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createPublicOauthClient } from \"@osdk/oauth\";\nimport * as oauthModule from \"@osdk/oauth\";\nimport { describe, expect, it, vi } from \"vitest\";\nimport * as utilsModule from \"../utils.js\";\n\nconst originalCreatePublicOauthClient = oauthModule.createPublicOauthClient;\n\nconst FOUNDRY_CLIENT_ID = \"example-foundry-client-id\";\nconst FOUNDRY_URL = \"http://example-foundry-url.com\";\nconst REDIRECT_URI = \"http://localhost:8080/auth/callback\";\n\nvi.stubGlobal(\"window\", {\n location: {\n toString: vi.fn().mockReturnValue(\"http://example.com\"),\n },\n});\n\ntype CreatePublicOauthClientParams = Parameters<typeof createPublicOauthClient>;\n\ntype ProcessedPublicOauthClientOptionsParams = Parameters<\n typeof utilsModule.processOptionsAndAssignDefaults\n>;\n\ntype ProcessedPublicOauthClientOptionsReturn = ReturnType<\n typeof utilsModule.processOptionsAndAssignDefaults\n>;\n\ndescribe(\"createPublicOauthClient\", () => {\n it(\"should return the same processed options for both client creation methods\", async () => {\n const mockProcessOptionsAndAssignDefaults = vi.fn<\n (\n ...args: ProcessedPublicOauthClientOptionsParams\n ) => ProcessedPublicOauthClientOptionsReturn\n >();\n\n // Mock processOptionsAndAssignDefaults to call the mock function\n vi.spyOn(utilsModule, \"processOptionsAndAssignDefaults\").mockImplementation(\n (\n ...args: ProcessedPublicOauthClientOptionsParams\n ) => {\n mockProcessOptionsAndAssignDefaults(...args);\n return utilsModule.processOptionsAndAssignDefaults(...args);\n },\n );\n\n // Mock createPublicOauthClient to call both the mock and the original function\n vi.spyOn(oauthModule, \"createPublicOauthClient\").mockImplementation(\n (\n ...args: CreatePublicOauthClientParams\n ) => {\n const [_client_id, ...rest] = args;\n mockProcessOptionsAndAssignDefaults(...rest);\n return originalCreatePublicOauthClient(...args);\n },\n );\n\n const authClient = createPublicOauthClient(\n FOUNDRY_CLIENT_ID,\n FOUNDRY_URL,\n REDIRECT_URI,\n true,\n undefined,\n undefined,\n undefined,\n fetch,\n undefined,\n );\n\n expect(authClient).toBeDefined();\n expect(mockProcessOptionsAndAssignDefaults).toHaveBeenCalledTimes(1);\n\n const authClientWithOptions = createPublicOauthClient(\n FOUNDRY_CLIENT_ID,\n FOUNDRY_URL,\n REDIRECT_URI,\n {\n useHistory: true,\n fetchFn: fetch,\n },\n );\n\n expect(authClientWithOptions).toBeDefined();\n expect(mockProcessOptionsAndAssignDefaults).toHaveBeenCalledTimes(2);\n\n const [result1, result2] = mockProcessOptionsAndAssignDefaults.mock.results;\n expect(result1.value).toEqual(result2.value);\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,uBAAuB,QAAQ,aAAa;AACrD,OAAO,KAAKC,WAAW,MAAM,aAAa;AAC1C,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,QAAQ;AACjD,OAAO,KAAKC,WAAW,MAAM,aAAa;AAE1C,MAAMC,+BAA+B,GAAGN,WAAW,CAACD,uBAAuB;AAE3E,MAAMQ,iBAAiB,GAAG,2BAA2B;AACrD,MAAMC,WAAW,GAAG,gCAAgC;AACpD,MAAMC,YAAY,GAAG,qCAAqC;AAE1DL,EAAE,CAACM,UAAU,CAAC,QAAQ,EAAE;EACtBC,QAAQ,EAAE;IACRC,QAAQ,EAAER,EAAE,CAACS,EAAE,CAAC,CAAC,CAACC,eAAe,CAAC,oBAAoB;EACxD;AACF,CAAC,CAAC;AAYFb,QAAQ,CAAC,yBAAyB,EAAE,MAAM;EACxCE,EAAE,CAAC,2EAA2E,EAAE,YAAY;IAC1F,MAAMY,mCAAmC,GAAGX,EAAE,CAACS,EAAE,CAI/C,CAAC;;IAEH;IACAT,EAAE,CAACY,KAAK,CAACX,WAAW,EAAE,iCAAiC,CAAC,CAACY,kBAAkB,CACzE,CACE,GAAGC,IAA6C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
|
2
|
-
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
18
|
-
import { common, createAuthorizationServer, readLocal, removeLocal, saveLocal } from "./common.js";
|
|
19
|
-
describe("local functions", () => {
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
vi.stubGlobal("localStorage", {
|
|
22
|
-
setItem: vi.fn(),
|
|
23
|
-
removeItem: vi.fn(),
|
|
24
|
-
getItem: vi.fn()
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
afterEach(() => {
|
|
28
|
-
vi.unstubAllGlobals();
|
|
29
|
-
});
|
|
30
|
-
it("should use the old style keys when there is no refresh token marker", () => {
|
|
31
|
-
const client = {
|
|
32
|
-
client_id: "hi_mom",
|
|
33
|
-
$refreshTokenMarker: undefined
|
|
34
|
-
};
|
|
35
|
-
const oldLocalStorageKey = `@osdk/oauth : refresh : ${client.client_id}`;
|
|
36
|
-
const storage = globalThis.localStorage;
|
|
37
|
-
readLocal(client, storage);
|
|
38
|
-
removeLocal(client, storage);
|
|
39
|
-
saveLocal(client, {}, storage);
|
|
40
|
-
expect(vi.mocked(globalThis.localStorage.getItem)).toBeCalledWith(oldLocalStorageKey);
|
|
41
|
-
expect(vi.mocked(globalThis.localStorage.setItem)).toBeCalledWith(oldLocalStorageKey, expect.anything());
|
|
42
|
-
expect(vi.mocked(globalThis.localStorage.removeItem)).toBeCalledWith(oldLocalStorageKey);
|
|
43
|
-
});
|
|
44
|
-
it("should save the refreshTokenMaker if it exists, as well as the requested scopes", () => {
|
|
45
|
-
const client = {
|
|
46
|
-
client_id: "hi_mom"
|
|
47
|
-
};
|
|
48
|
-
const signIn = vi.fn();
|
|
49
|
-
const refresh = vi.fn();
|
|
50
|
-
const storage = globalThis.localStorage;
|
|
51
|
-
const authServer = createAuthorizationServer("multipass", "https://stack.palantir.com");
|
|
52
|
-
const {
|
|
53
|
-
makeTokenAndSaveRefresh
|
|
54
|
-
} = common(client, authServer, signIn, {}, refresh, "marker marker", "yay:my-fun-scope sad:my-boring-scope", storage);
|
|
55
|
-
makeTokenAndSaveRefresh({
|
|
56
|
-
refresh_token: "refresh",
|
|
57
|
-
access_token: "access",
|
|
58
|
-
token_type: "idk",
|
|
59
|
-
expires_in: 10_000
|
|
60
|
-
}, "signIn");
|
|
61
|
-
expect(globalThis.localStorage.setItem).toBeCalledWith(`@osdk/oauth : refresh : ${client.client_id}`, JSON.stringify({
|
|
62
|
-
refresh_token: "refresh",
|
|
63
|
-
refreshTokenMarker: "marker marker",
|
|
64
|
-
requestedScopes: "yay:my-fun-scope sad:my-boring-scope"
|
|
65
|
-
}));
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
//# sourceMappingURL=common.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common.test.js","names":["afterEach","beforeEach","describe","expect","it","vi","common","createAuthorizationServer","readLocal","removeLocal","saveLocal","stubGlobal","setItem","fn","removeItem","getItem","unstubAllGlobals","client","client_id","$refreshTokenMarker","undefined","oldLocalStorageKey","storage","globalThis","localStorage","mocked","toBeCalledWith","anything","signIn","refresh","authServer","makeTokenAndSaveRefresh","refresh_token","access_token","token_type","expires_in","JSON","stringify","refreshTokenMarker","requestedScopes"],"sources":["common.test.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport {\n common,\n createAuthorizationServer,\n readLocal,\n removeLocal,\n saveLocal,\n} from \"./common.js\";\n\ndescribe(\"local functions\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"localStorage\", {\n setItem: vi.fn(),\n removeItem: vi.fn(),\n getItem: vi.fn(),\n });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n });\n\n it(\"should use the old style keys when there is no refresh token marker\", () => {\n const client = {\n client_id: \"hi_mom\",\n $refreshTokenMarker: undefined,\n };\n\n const oldLocalStorageKey = `@osdk/oauth : refresh : ${client.client_id}`;\n const storage = globalThis.localStorage;\n\n readLocal(client, storage);\n removeLocal(client, storage);\n saveLocal(client, {}, storage);\n\n expect(vi.mocked(globalThis.localStorage.getItem)).toBeCalledWith(\n oldLocalStorageKey,\n );\n\n expect(vi.mocked(globalThis.localStorage.setItem)).toBeCalledWith(\n oldLocalStorageKey,\n expect.anything(),\n );\n\n expect(vi.mocked(globalThis.localStorage.removeItem)).toBeCalledWith(\n oldLocalStorageKey,\n );\n });\n\n it(\"should save the refreshTokenMaker if it exists, as well as the requested scopes\", () => {\n const client = {\n client_id: \"hi_mom\",\n };\n\n const signIn = vi.fn();\n const refresh = vi.fn();\n const storage = globalThis.localStorage;\n\n const authServer = createAuthorizationServer(\n \"multipass\",\n \"https://stack.palantir.com\",\n );\n\n const { makeTokenAndSaveRefresh } = common(\n client,\n authServer,\n signIn,\n {},\n refresh,\n \"marker marker\",\n \"yay:my-fun-scope sad:my-boring-scope\",\n storage,\n );\n\n makeTokenAndSaveRefresh({\n refresh_token: \"refresh\",\n access_token: \"access\",\n token_type: \"idk\",\n expires_in: 10_000,\n }, \"signIn\");\n\n expect(globalThis.localStorage.setItem).toBeCalledWith(\n `@osdk/oauth : refresh : ${client.client_id}`,\n JSON.stringify({\n refresh_token: \"refresh\",\n refreshTokenMarker: \"marker marker\",\n requestedScopes: \"yay:my-fun-scope sad:my-boring-scope\",\n }),\n );\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,QAAQ;AACxE,SACEC,MAAM,EACNC,yBAAyB,EACzBC,SAAS,EACTC,WAAW,EACXC,SAAS,QACJ,aAAa;AAEpBR,QAAQ,CAAC,iBAAiB,EAAE,MAAM;EAChCD,UAAU,CAAC,MAAM;IACfI,EAAE,CAACM,UAAU,CAAC,cAAc,EAAE;MAC5BC,OAAO,EAAEP,EAAE,CAACQ,EAAE,CAAC,CAAC;MAChBC,UAAU,EAAET,EAAE,CAACQ,EAAE,CAAC,CAAC;MACnBE,OAAO,EAAEV,EAAE,CAACQ,EAAE,CAAC;IACjB,CAAC,CAAC;EACJ,CAAC,CAAC;EAEFb,SAAS,CAAC,MAAM;IACdK,EAAE,CAACW,gBAAgB,CAAC,CAAC;EACvB,CAAC,CAAC;EAEFZ,EAAE,CAAC,qEAAqE,EAAE,MAAM;IAC9E,MAAMa,MAAM,GAAG;MACbC,SAAS,EAAE,QAAQ;MACnBC,mBAAmB,EAAEC;IACvB,CAAC;IAED,MAAMC,kBAAkB,GAAG,2BAA2BJ,MAAM,CAACC,SAAS,EAAE;IACxE,MAAMI,OAAO,GAAGC,UAAU,CAACC,YAAY;IAEvChB,SAAS,CAACS,MAAM,E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AO,CAAC,CAACc,cAAc,CACpD,2BAA2BT,MAAM,CAACC,SAAS,EAAE,EAC7CkB,IAAI,CAACC,SAAS,CAAC;MACbL,aAAa,EAAE,SAAS;MACxBM,kBAAkB,EAAE,eAAe;MACnCC,eAAe,EAAE;IACnB,CAAC,CACH,CAAC;EACH,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { describe, expect, it } from "vitest";
|
|
18
|
-
import { createAuthlessClient } from "./createAuthlessClient.js";
|
|
19
|
-
describe(createAuthlessClient, () => {
|
|
20
|
-
it("should return \"PUBLIC\" when called", async () => {
|
|
21
|
-
const authlessClientProvider = createAuthlessClient();
|
|
22
|
-
const result = await authlessClientProvider();
|
|
23
|
-
expect(result).toBe("PUBLIC");
|
|
24
|
-
});
|
|
25
|
-
it("should return a Promise", () => {
|
|
26
|
-
const authlessClientProvider = createAuthlessClient();
|
|
27
|
-
const resultPromise = authlessClientProvider();
|
|
28
|
-
expect(resultPromise).toBeInstanceOf(Promise);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
//# sourceMappingURL=createAuthlessClient.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createAuthlessClient.test.js","names":["describe","expect","it","createAuthlessClient","authlessClientProvider","result","toBe","resultPromise","toBeInstanceOf","Promise"],"sources":["createAuthlessClient.test.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { describe, expect, it } from \"vitest\";\nimport { createAuthlessClient } from \"./createAuthlessClient.js\";\n\ndescribe(createAuthlessClient, () => {\n it(\"should return \\\"PUBLIC\\\" when called\", async () => {\n const authlessClientProvider = createAuthlessClient();\n const result = await authlessClientProvider();\n expect(result).toBe(\"PUBLIC\");\n });\n\n it(\"should return a Promise\", () => {\n const authlessClientProvider = createAuthlessClient();\n const resultPromise = authlessClientProvider();\n expect(resultPromise).toBeInstanceOf(Promise);\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAC7C,SAASC,oBAAoB,QAAQ,2BAA2B;AAEhEH,QAAQ,CAACG,oBAAoB,EAAE,MAAM;EACnCD,EAAE,CAAC,sCAAsC,EAAE,YAAY;IACrD,MAAME,sBAAsB,GAAGD,oBAAoB,CAAC,CAAC;IACrD,MAAME,MAAM,GAAG,MAAMD,sBAAsB,CAAC,CAAC;IAC7CH,MAAM,CAACI,MAAM,CAAC,CAACC,IAAI,CAAC,QAAQ,CAAC;EAC/B,CAAC,CAAC;EAEFJ,EAAE,CAAC,yBAAyB,EAAE,MAAM;IAClC,MAAME,sBAAsB,GAAGD,oBAAoB,CAAC,CAAC;IACrD,MAAMI,aAAa,GAAGH,sBAAsB,CAAC,CAAC;IAC9CH,MAAM,CAACM,aAAa,CAAC,CAACC,cAAc,CAACC,OAAO,CAAC;EAC/C,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|