@osdk/oauth 1.1.0-beta.8 → 1.2.0-beta.1
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 +18 -0
- package/build/browser/AuthorizationServer.test.js +8 -0
- package/build/browser/AuthorizationServer.test.js.map +1 -1
- package/build/browser/BaseOauthClient.js +0 -15
- package/build/browser/BaseOauthClient.js.map +1 -1
- package/build/browser/ConfidentialOauthClient.js +0 -15
- package/build/browser/ConfidentialOauthClient.js.map +1 -1
- package/build/browser/PublicOauthClient.js +0 -15
- package/build/browser/PublicOauthClient.js.map +1 -1
- package/build/browser/Token.js +0 -15
- package/build/browser/Token.js.map +1 -1
- package/build/browser/__tests__/createPublicOauthClient.test.js +3 -0
- package/build/browser/__tests__/createPublicOauthClient.test.js.map +1 -1
- package/build/browser/common.js +3 -1
- package/build/browser/common.js.map +1 -1
- package/build/browser/common.test.js +1 -0
- package/build/browser/common.test.js.map +1 -1
- package/build/browser/createConfidentialOauthClient.js +2 -0
- package/build/browser/createConfidentialOauthClient.js.map +1 -1
- package/build/browser/createPublicOauthClient.js +30 -0
- package/build/browser/createPublicOauthClient.js.map +1 -1
- package/build/browser/index.js +1 -0
- package/build/browser/index.js.map +1 -1
- package/build/browser/publicOauth.test.js +1 -0
- package/build/browser/publicOauth.test.js.map +1 -1
- package/build/browser/throwIfError.js +1 -0
- package/build/browser/throwIfError.js.map +1 -1
- package/build/browser/utils.js +2 -0
- package/build/browser/utils.js.map +1 -1
- package/build/cjs/index.cjs +1299 -0
- package/build/cjs/index.cjs.map +1 -0
- package/build/{browser/createPublicOauthClient.d.ts → cjs/index.d.cts} +44 -5
- package/build/esm/AuthorizationServer.test.js +8 -0
- package/build/esm/AuthorizationServer.test.js.map +1 -1
- package/build/esm/BaseOauthClient.js +0 -15
- package/build/esm/BaseOauthClient.js.map +1 -1
- package/build/esm/ConfidentialOauthClient.js +0 -15
- package/build/esm/ConfidentialOauthClient.js.map +1 -1
- package/build/esm/PublicOauthClient.js +0 -15
- package/build/esm/PublicOauthClient.js.map +1 -1
- package/build/esm/Token.js +0 -15
- package/build/esm/Token.js.map +1 -1
- package/build/esm/__tests__/createPublicOauthClient.test.js +3 -0
- package/build/esm/__tests__/createPublicOauthClient.test.js.map +1 -1
- package/build/esm/common.js +3 -1
- package/build/esm/common.js.map +1 -1
- package/build/esm/common.test.js +1 -0
- package/build/esm/common.test.js.map +1 -1
- package/build/esm/createConfidentialOauthClient.js +2 -0
- package/build/esm/createConfidentialOauthClient.js.map +1 -1
- package/build/esm/createPublicOauthClient.js +30 -0
- package/build/esm/createPublicOauthClient.js.map +1 -1
- package/build/esm/index.js +1 -0
- package/build/esm/index.js.map +1 -1
- package/build/esm/publicOauth.test.js +1 -0
- package/build/esm/publicOauth.test.js.map +1 -1
- package/build/esm/throwIfError.js +1 -0
- package/build/esm/throwIfError.js.map +1 -1
- package/build/esm/utils.js +2 -0
- package/build/esm/utils.js.map +1 -1
- package/build/types/AuthorizationServer.test.d.ts +1 -0
- package/build/types/AuthorizationServer.test.d.ts.map +1 -0
- package/build/types/BaseOauthClient.d.ts +14 -0
- package/build/types/BaseOauthClient.d.ts.map +1 -0
- package/build/{browser → types}/ConfidentialOauthClient.d.ts +1 -3
- package/build/types/ConfidentialOauthClient.d.ts.map +1 -0
- package/build/{browser → types}/PublicOauthClient.d.ts +1 -2
- package/build/types/PublicOauthClient.d.ts.map +1 -0
- package/build/types/Token.d.ts +6 -0
- package/build/types/Token.d.ts.map +1 -0
- package/build/types/__tests__/createPublicOauthClient.test.d.ts +1 -0
- package/build/types/__tests__/createPublicOauthClient.test.d.ts.map +1 -0
- package/build/{browser → types}/common.d.ts +15 -16
- package/build/types/common.d.ts.map +1 -0
- package/build/types/common.test.d.ts +1 -0
- package/build/types/common.test.d.ts.map +1 -0
- package/build/{browser → types}/createConfidentialOauthClient.d.ts +8 -9
- package/build/types/createConfidentialOauthClient.d.ts.map +1 -0
- package/build/types/createPublicOauthClient.d.ts +56 -0
- package/build/types/createPublicOauthClient.d.ts.map +1 -0
- package/build/{browser → types}/index.d.ts +1 -2
- package/build/types/index.d.ts.map +1 -0
- package/build/types/publicOauth.test.d.ts +1 -0
- package/build/types/publicOauth.test.d.ts.map +1 -0
- package/build/{browser → types}/throwIfError.d.ts +0 -1
- package/build/types/throwIfError.d.ts.map +1 -0
- package/build/{esm → types}/utils.d.ts +2 -3
- package/build/types/utils.d.ts.map +1 -0
- package/package.json +22 -10
- package/build/browser/AuthorizationServer.test.d.ts +0 -2
- package/build/browser/AuthorizationServer.test.d.ts.map +0 -1
- package/build/browser/BaseOauthClient.d.ts +0 -15
- package/build/browser/BaseOauthClient.d.ts.map +0 -1
- package/build/browser/ConfidentialOauthClient.d.ts.map +0 -1
- package/build/browser/PublicOauthClient.d.ts.map +0 -1
- package/build/browser/Token.d.ts +0 -7
- package/build/browser/Token.d.ts.map +0 -1
- package/build/browser/__tests__/createPublicOauthClient.test.d.ts +0 -2
- package/build/browser/__tests__/createPublicOauthClient.test.d.ts.map +0 -1
- package/build/browser/common.d.ts.map +0 -1
- package/build/browser/common.test.d.ts +0 -2
- package/build/browser/common.test.d.ts.map +0 -1
- package/build/browser/createConfidentialOauthClient.d.ts.map +0 -1
- package/build/browser/createPublicOauthClient.d.ts.map +0 -1
- package/build/browser/index.d.ts.map +0 -1
- package/build/browser/publicOauth.test.d.ts +0 -2
- package/build/browser/publicOauth.test.d.ts.map +0 -1
- package/build/browser/throwIfError.d.ts.map +0 -1
- package/build/browser/utils.d.ts +0 -8
- package/build/browser/utils.d.ts.map +0 -1
- package/build/esm/AuthorizationServer.test.d.ts +0 -2
- package/build/esm/AuthorizationServer.test.d.ts.map +0 -1
- package/build/esm/BaseOauthClient.d.ts +0 -15
- package/build/esm/BaseOauthClient.d.ts.map +0 -1
- package/build/esm/ConfidentialOauthClient.d.ts +0 -4
- package/build/esm/ConfidentialOauthClient.d.ts.map +0 -1
- package/build/esm/PublicOauthClient.d.ts +0 -6
- package/build/esm/PublicOauthClient.d.ts.map +0 -1
- package/build/esm/Token.d.ts +0 -7
- package/build/esm/Token.d.ts.map +0 -1
- package/build/esm/__tests__/createPublicOauthClient.test.d.ts +0 -2
- package/build/esm/__tests__/createPublicOauthClient.test.d.ts.map +0 -1
- package/build/esm/common.d.ts +0 -34
- package/build/esm/common.d.ts.map +0 -1
- package/build/esm/common.test.d.ts +0 -2
- package/build/esm/common.test.d.ts.map +0 -1
- package/build/esm/createConfidentialOauthClient.d.ts +0 -12
- package/build/esm/createConfidentialOauthClient.d.ts.map +0 -1
- package/build/esm/createPublicOauthClient.d.ts +0 -57
- package/build/esm/createPublicOauthClient.d.ts.map +0 -1
- package/build/esm/index.d.ts +0 -4
- package/build/esm/index.d.ts.map +0 -1
- package/build/esm/publicOauth.test.d.ts +0 -2
- package/build/esm/publicOauth.test.d.ts.map +0 -1
- package/build/esm/throwIfError.d.ts +0 -6
- package/build/esm/throwIfError.d.ts.map +0 -1
- package/build/esm/utils.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @osdk/oauth
|
|
2
2
|
|
|
3
|
+
## 1.1.0-beta.11
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 9df2d99: Fixes CJS generation for OAuth
|
|
8
|
+
|
|
9
|
+
## 1.1.0-beta.10
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 44e62f6: Updating fetch for auth and other packages.
|
|
14
|
+
|
|
15
|
+
## 1.1.0-beta.9
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- c691c8b: Package now has experimental support for commonjs
|
|
20
|
+
|
|
3
21
|
## 1.1.0-beta.8
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
|
|
16
17
|
import { describe, expect, it } from "vitest";
|
|
17
18
|
import { createAuthorizationServer } from "./common.js";
|
|
18
19
|
describe("Create authorization server", () => {
|
|
@@ -40,6 +41,13 @@ describe("Create authorization server", () => {
|
|
|
40
41
|
revocation_endpoint: "https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/revoke_token",
|
|
41
42
|
issuer: "https://stack.palantir.com/foo/first/someStuff/multipass"
|
|
42
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
|
+
});
|
|
43
51
|
});
|
|
44
52
|
});
|
|
45
53
|
//# sourceMappingURL=AuthorizationServer.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthorizationServer.test.js","names":["describe","expect","it","createAuthorizationServer","authServer","toEqual","token_endpoint","authorization_endpoint","revocation_endpoint","issuer","authServerCustom"],"sources":["AuthorizationServer.test.
|
|
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,17 +1,2 @@
|
|
|
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
1
|
export {};
|
|
17
2
|
//# sourceMappingURL=BaseOauthClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseOauthClient.js","names":[],"sources":["BaseOauthClient.
|
|
1
|
+
{"version":3,"file":"BaseOauthClient.js","names":[],"sources":["BaseOauthClient.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 { Token } from \"./Token.js\";\n\nexport type Events = {\n signIn: CustomEvent<Token>;\n signOut: Event;\n refresh: CustomEvent<Token>;\n};\n\nexport interface BaseOauthClient<K extends keyof Events & string> {\n (): Promise<string>;\n\n getTokenOrUndefined: () => string | undefined;\n signIn: () => Promise<Token>;\n signOut: () => Promise<void>;\n\n addEventListener: <T extends K>(\n type: T,\n listener: ((evt: Events[T]) => void) | null,\n options?: boolean | AddEventListenerOptions,\n ) => void;\n\n removeEventListener: <T extends K>(\n type: T,\n callback: ((evt: Events[T]) => void) | null,\n options?: EventListenerOptions | boolean,\n ) => void;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,17 +1,2 @@
|
|
|
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
1
|
export {};
|
|
17
2
|
//# sourceMappingURL=ConfidentialOauthClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfidentialOauthClient.js","names":[],"sources":["ConfidentialOauthClient.
|
|
1
|
+
{"version":3,"file":"ConfidentialOauthClient.js","names":[],"sources":["ConfidentialOauthClient.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 { BaseOauthClient } from \"./BaseOauthClient.js\";\n\nexport interface ConfidentialOauthClient\n extends BaseOauthClient<\"signIn\" | \"signOut\">\n{\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,17 +1,2 @@
|
|
|
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
1
|
export {};
|
|
17
2
|
//# sourceMappingURL=PublicOauthClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PublicOauthClient.js","names":[],"sources":["PublicOauthClient.
|
|
1
|
+
{"version":3,"file":"PublicOauthClient.js","names":[],"sources":["PublicOauthClient.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 { BaseOauthClient } from \"./BaseOauthClient.js\";\nimport type { Token } from \"./Token.js\";\n\nexport interface PublicOauthClient\n extends BaseOauthClient<\"signIn\" | \"signOut\" | \"refresh\">\n{\n refresh: () => Promise<Token | undefined>;\n}\n"],"mappings":"","ignoreList":[]}
|
package/build/browser/Token.js
CHANGED
|
@@ -1,17 +1,2 @@
|
|
|
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
1
|
export {};
|
|
17
2
|
//# sourceMappingURL=Token.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Token.js","names":[],"sources":["Token.
|
|
1
|
+
{"version":3,"file":"Token.js","names":[],"sources":["Token.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 Token {\n readonly access_token: string;\n readonly expires_in: number;\n readonly refresh_token?: string;\n readonly expires_at: number;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
|
|
16
17
|
import { createPublicOauthClient } from "@osdk/oauth";
|
|
17
18
|
import * as oauthModule from "@osdk/oauth";
|
|
18
19
|
import { describe, expect, it, vi } from "vitest";
|
|
@@ -29,11 +30,13 @@ vi.stubGlobal("window", {
|
|
|
29
30
|
describe("createPublicOauthClient", () => {
|
|
30
31
|
it("should return the same processed options for both client creation methods", async () => {
|
|
31
32
|
const mockProcessOptionsAndAssignDefaults = vi.fn();
|
|
33
|
+
|
|
32
34
|
// Mock processOptionsAndAssignDefaults to call the mock function
|
|
33
35
|
vi.spyOn(utilsModule, "processOptionsAndAssignDefaults").mockImplementation((...args) => {
|
|
34
36
|
mockProcessOptionsAndAssignDefaults(...args);
|
|
35
37
|
return utilsModule.processOptionsAndAssignDefaults(...args);
|
|
36
38
|
});
|
|
39
|
+
|
|
37
40
|
// Mock createPublicOauthClient to call both the mock and the original function
|
|
38
41
|
vi.spyOn(oauthModule, "createPublicOauthClient").mockImplementation((...args) => {
|
|
39
42
|
const [_client_id, ...rest] = args;
|
|
@@ -1 +1 @@
|
|
|
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.
|
|
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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KAAK,EACLD,SACF,CAAC;IAEDrB,MAAM,CAACoB,UAAU,CAAC,CAACG,WAAW,CAAC,CAAC;IAChCvB,MAAM,CAACa,mCAAmC,CAAC,CAACW,qBAAqB,CAAC,CAAC,CAAC;IAEpE,MAAMC,qBAAqB,GAAG5B,uBAAuB,CACnDQ,iBAAiB,EACjBC,WAAW,EACXC,YAAY,EACZ;MACEmB,UAAU,EAAE,IAAI;MAChBC,OAAO,EAAEL;IACX,CACF,CAAC;IAEDtB,MAAM,CAACyB,qBAAqB,CAAC,CAACF,WAAW,CAAC,CAAC;IAC3CvB,MAAM,CAACa,mCAAmC,CAAC,CAACW,qBAAqB,CAAC,CAAC,CAAC;IAEpE,MAAM,CAACI,OAAO,EAAEC,OAAO,CAAC,GAAGhB,mCAAmC,CAACiB,IAAI,CAACC,OAAO;IAC3E/B,MAAM,CAAC4B,OAAO,CAACI,KAAK,CAAC,CAACC,OAAO,CAACJ,OAAO,CAACG,KAAK,CAAC;EAC9C,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
package/build/browser/common.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
|
|
16
17
|
import { processRevocationResponse, revocationRequest } from "oauth4webapi";
|
|
17
18
|
import invariant from "tiny-invariant";
|
|
18
19
|
import { TypedEventTarget } from "typescript-event-target";
|
|
@@ -116,6 +117,7 @@ export function common(client, as, _signIn, oauthHttpOptions, refresh, refreshTo
|
|
|
116
117
|
!token ? process.env.NODE_ENV !== "production" ? invariant(false, "not signed in") : invariant(false) : void 0;
|
|
117
118
|
const result = await processRevocationResponse(await revocationRequest(as, client, token.access_token, oauthHttpOptions));
|
|
118
119
|
rmTimeout();
|
|
120
|
+
|
|
119
121
|
// Clean up
|
|
120
122
|
removeLocal(client);
|
|
121
123
|
token = undefined;
|
|
@@ -133,7 +135,7 @@ export function common(client, as, _signIn, oauthHttpOptions, refresh, refreshTo
|
|
|
133
135
|
};
|
|
134
136
|
}
|
|
135
137
|
export function createAuthorizationServer(ctxPath, url) {
|
|
136
|
-
const issuer = `${new URL(ctxPath, url + "/")}`;
|
|
138
|
+
const issuer = `${new URL(ctxPath, url.endsWith("/") ? url : url + "/")}`;
|
|
137
139
|
return {
|
|
138
140
|
token_endpoint: `${issuer}/api/oauth2/token`,
|
|
139
141
|
authorization_endpoint: `${issuer}/api/oauth2/authorize`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","names":["processRevocationResponse","revocationRequest","invariant","TypedEventTarget","throwIfError","CustomEvent","globalThis","localStorageKey","client","client_id","saveLocal","x","localStorage","setItem","JSON","stringify","removeLocal","removeItem","readLocal","parse","getItem","saveSession","sessionStorage","removeSession","readSession","common","as","_signIn","oauthHttpOptions","refresh","refreshTokenMarker","token","eventTarget","makeTokenAndSaveRefresh","resp","type","refresh_token","expires_in","access_token","process","env","NODE_ENV","expires_at","Date","now","dispatchTypedEvent","detail","refreshTimeout","rmTimeout","clearTimeout","restartRefreshTimer","evt","setTimeout","pendingSignIn","signIn","undefined","addEventListener","getTokenOrUndefined","getToken","Object","assign","signOut","result","Event","bind","removeEventListener","createAuthorizationServer","ctxPath","url","issuer","URL","token_endpoint","authorization_endpoint","revocation_endpoint"],"sources":["common.js"],"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 */\nimport { processRevocationResponse, revocationRequest } from \"oauth4webapi\";\nimport invariant from \"tiny-invariant\";\nimport { TypedEventTarget } from \"typescript-event-target\";\nimport { throwIfError } from \"./throwIfError.js\";\n// Node 18 is supposed to have a `CustomEvent` but it is not exposed on `globalThis`\n// which creates a problem for making a single codebase for node and browser. This polyfill works around it\nconst CustomEvent = process.env.TARGET === \"browser\"\n ? globalThis.CustomEvent\n : globalThis.CustomEvent\n ?? class CustomEvent extends Event {\n #detail;\n constructor(type, options) {\n super(type, options);\n this.#detail = options?.detail ?? null;\n }\n get detail() {\n return this.#detail;\n }\n };\nfunction localStorageKey(client) {\n return `@osdk/oauth : refresh : ${client.client_id}`;\n}\nexport function saveLocal(client, x) {\n // MUST `localStorage?` as nodejs does not have localStorage\n globalThis.localStorage?.setItem(localStorageKey(client), JSON.stringify(x));\n}\nexport function removeLocal(client) {\n // MUST `localStorage?` as nodejs does not have localStorage\n globalThis.localStorage?.removeItem(localStorageKey(client));\n}\nexport function readLocal(client) {\n return JSON.parse(\n // MUST `localStorage?` as nodejs does not have localStorage\n globalThis.localStorage?.getItem(localStorageKey(client))\n ?? \"{}\");\n}\nexport function saveSession(client, x) {\n // MUST `sessionStorage?` as nodejs does not have sessionStorage\n globalThis.sessionStorage?.setItem(localStorageKey(client), JSON.stringify(x));\n}\nexport function removeSession(client) {\n // MUST `sessionStorage?` as nodejs does not have sessionStorage\n globalThis.sessionStorage?.removeItem(localStorageKey(client));\n}\nexport function readSession(client) {\n return JSON.parse(\n // MUST `sessionStorage?` as nodejs does not have sessionStorage\n globalThis.sessionStorage?.getItem(localStorageKey(client))\n ?? \"{}\");\n}\nexport function common(client, as, _signIn, oauthHttpOptions, refresh, refreshTokenMarker) {\n let token;\n const eventTarget = new TypedEventTarget();\n function makeTokenAndSaveRefresh(resp, type) {\n const { refresh_token, expires_in, access_token } = resp;\n invariant(expires_in != null);\n saveLocal(client, {\n refresh_token,\n refreshTokenMarker,\n });\n token = {\n refresh_token,\n expires_in,\n access_token,\n expires_at: Date.now() + expires_in * 1000,\n };\n eventTarget.dispatchTypedEvent(type, new CustomEvent(type, { detail: token }));\n return token;\n }\n let refreshTimeout;\n function rmTimeout() {\n if (refreshTimeout)\n clearTimeout(refreshTimeout);\n }\n function restartRefreshTimer(evt) {\n if (refresh) {\n rmTimeout();\n refreshTimeout = setTimeout(refresh, evt.detail.expires_in * 1000 - 60 * 1000);\n }\n }\n async function signOut() {\n invariant(token, \"not signed in\");\n const result = await processRevocationResponse(await revocationRequest(as, client, token.access_token, oauthHttpOptions));\n rmTimeout();\n // Clean up\n removeLocal(client);\n token = undefined;\n throwIfError(result);\n eventTarget.dispatchTypedEvent(\"signOut\", new Event(\"signOut\"));\n }\n let pendingSignIn;\n async function signIn() {\n if (pendingSignIn) {\n return pendingSignIn;\n }\n try {\n pendingSignIn = _signIn();\n return await pendingSignIn;\n }\n finally {\n pendingSignIn = undefined;\n }\n }\n eventTarget.addEventListener(\"signIn\", restartRefreshTimer);\n eventTarget.addEventListener(\"refresh\", restartRefreshTimer);\n function getTokenOrUndefined() {\n if (!token || Date.now() >= token.expires_at) {\n return undefined;\n }\n return token?.access_token;\n }\n const getToken = Object.assign(async function getToken() {\n if (!token || Date.now() >= token.expires_at) {\n token = await signIn();\n }\n return token?.access_token;\n }, {\n signIn,\n refresh,\n signOut,\n rmTimeout,\n getTokenOrUndefined,\n addEventListener: eventTarget.addEventListener.bind(eventTarget),\n removeEventListener: eventTarget.removeEventListener.bind(eventTarget),\n });\n return { getToken, makeTokenAndSaveRefresh };\n}\nexport function createAuthorizationServer(ctxPath, url) {\n const issuer = `${new URL(ctxPath, url + \"/\")}`;\n return {\n token_endpoint: `${issuer}/api/oauth2/token`,\n authorization_endpoint: `${issuer}/api/oauth2/authorize`,\n revocation_endpoint: `${issuer}/api/oauth2/revoke_token`,\n issuer,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,yBAAyB,EAAEC,iBAAiB,QAAQ,cAAc;AAC3E,OAAOC,SAAS,MAAM,gBAAgB;AAC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mBAAmB;IACnBD,gBAAgB,EAAExB,WAAW,CAACwB,gBAAgB,CAACQ,IAAI,CAAChC,WAAW,CAAC;IAChEiC,mBAAmB,EAAEjC,WAAW,CAACiC,mBAAmB,CAACD,IAAI,CAAChC,WAAW;EACzE,CAAC,CAAC;EACF,OAAO;IAAE0B,QAAQ;IAAEzB;EAAwB,CAAC;AAChD;AACA,OAAO,SAASiC,yBAAyBA,CAACC,OAAO,EAAEC,GAAG,EAAE;EACpD,MAAMC,MAAM,GAAG,GAAG,IAAIC,GAAG,CAACH,OAAO,EAAEC,GAAG,GAAG,GAAG,CAAC,EAAE;EAC/C,OAAO;IACHG,cAAc,EAAE,GAAGF,MAAM,mBAAmB;IAC5CG,sBAAsB,EAAE,GAAGH,MAAM,uBAAuB;IACxDI,mBAAmB,EAAE,GAAGJ,MAAM,0BAA0B;IACxDA;EACJ,CAAC;AACL","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"common.js","names":["processRevocationResponse","revocationRequest","invariant","TypedEventTarget","throwIfError","CustomEvent","globalThis","localStorageKey","client","client_id","saveLocal","x","localStorage","setItem","JSON","stringify","removeLocal","removeItem","readLocal","parse","getItem","saveSession","sessionStorage","removeSession","readSession","common","as","_signIn","oauthHttpOptions","refresh","refreshTokenMarker","token","eventTarget","makeTokenAndSaveRefresh","resp","type","refresh_token","expires_in","access_token","process","env","NODE_ENV","expires_at","Date","now","dispatchTypedEvent","detail","refreshTimeout","rmTimeout","clearTimeout","restartRefreshTimer","evt","setTimeout","pendingSignIn","signIn","undefined","addEventListener","getTokenOrUndefined","getToken","Object","assign","signOut","result","Event","bind","removeEventListener","createAuthorizationServer","ctxPath","url","issuer","URL","endsWith","token_endpoint","authorization_endpoint","revocation_endpoint"],"sources":["common.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 {\n AuthorizationServer,\n Client,\n HttpRequestOptions,\n OAuth2TokenEndpointResponse,\n} from \"oauth4webapi\";\nimport { processRevocationResponse, revocationRequest } from \"oauth4webapi\";\nimport invariant from \"tiny-invariant\";\nimport { TypedEventTarget } from \"typescript-event-target\";\nimport type { BaseOauthClient, Events } from \"./BaseOauthClient.js\";\nimport { throwIfError } from \"./throwIfError.js\";\nimport type { Token } from \"./Token.js\";\n\n// Node 18 is supposed to have a `CustomEvent` but it is not exposed on `globalThis`\n// which creates a problem for making a single codebase for node and browser. This polyfill works around it\nconst CustomEvent = process.env.TARGET === \"browser\"\n ? globalThis.CustomEvent\n : globalThis.CustomEvent\n ?? class CustomEvent<T> extends Event {\n #detail: T | null;\n\n constructor(type: string, options: EventInit & { detail: T }) {\n super(type, options);\n this.#detail = options?.detail ?? null;\n }\n\n get detail() {\n return this.#detail;\n }\n };\n\ndeclare const process: {\n env: Record<string, string | undefined>;\n};\n\nexport interface LocalStorageState {\n refresh_token?: string;\n refreshTokenMarker?: string;\n}\n\nexport type SessionStorageState =\n // when we are going to the login page\n | {\n codeVerifier?: never;\n state?: never;\n oldUrl: string;\n }\n // when we are redirecting to oauth login\n | {\n codeVerifier: string;\n state: string;\n oldUrl: string;\n }\n // when we have the refresh token\n | {\n codeVerifier?: never;\n state?: never;\n oldUrl?: never;\n };\n\nfunction localStorageKey(client: Client) {\n return `@osdk/oauth : refresh : ${client.client_id}`;\n}\n\nexport function saveLocal(client: Client, x: LocalStorageState): void {\n // MUST `localStorage?` as nodejs does not have localStorage\n globalThis.localStorage?.setItem(\n localStorageKey(client),\n JSON.stringify(x),\n );\n}\n\nexport function removeLocal(client: Client): void {\n // MUST `localStorage?` as nodejs does not have localStorage\n globalThis.localStorage?.removeItem(\n localStorageKey(client),\n );\n}\n\nexport function readLocal(client: Client): LocalStorageState {\n return JSON.parse(\n // MUST `localStorage?` as nodejs does not have localStorage\n globalThis.localStorage?.getItem(\n localStorageKey(client),\n )\n ?? \"{}\",\n );\n}\n\nexport function saveSession(client: Client, x: SessionStorageState): void {\n // MUST `sessionStorage?` as nodejs does not have sessionStorage\n globalThis.sessionStorage?.setItem(\n localStorageKey(client),\n JSON.stringify(x),\n );\n}\n\nexport function removeSession(client: Client): void {\n // MUST `sessionStorage?` as nodejs does not have sessionStorage\n globalThis.sessionStorage?.removeItem(\n localStorageKey(client),\n );\n}\n\nexport function readSession(client: Client): SessionStorageState {\n return JSON.parse(\n // MUST `sessionStorage?` as nodejs does not have sessionStorage\n globalThis.sessionStorage?.getItem(\n localStorageKey(client),\n )\n ?? \"{}\",\n );\n}\n\nexport function common<\n R extends undefined | (() => Promise<Token | undefined>),\n>(\n client: Client,\n as: AuthorizationServer,\n _signIn: () => Promise<Token>,\n oauthHttpOptions: HttpRequestOptions,\n refresh: R,\n refreshTokenMarker: string | undefined,\n): {\n getToken: BaseOauthClient<keyof Events & string> & { refresh: R };\n makeTokenAndSaveRefresh: (\n resp: OAuth2TokenEndpointResponse,\n type: \"signIn\" | \"refresh\",\n ) => Token;\n} {\n let token: Token | undefined;\n const eventTarget = new TypedEventTarget<Events>();\n\n function makeTokenAndSaveRefresh(\n resp: OAuth2TokenEndpointResponse,\n type: \"signIn\" | \"refresh\",\n ): Token {\n const { refresh_token, expires_in, access_token } = resp;\n invariant(expires_in != null);\n saveLocal(client, {\n refresh_token,\n refreshTokenMarker,\n });\n token = {\n refresh_token,\n expires_in,\n access_token,\n expires_at: Date.now() + expires_in * 1000,\n };\n\n eventTarget.dispatchTypedEvent(\n type,\n new CustomEvent(\n type,\n { detail: token },\n ),\n );\n return token;\n }\n\n let refreshTimeout: ReturnType<typeof setTimeout>;\n function rmTimeout() {\n if (refreshTimeout) clearTimeout(refreshTimeout);\n }\n function restartRefreshTimer(evt: CustomEvent<Token>) {\n if (refresh) {\n rmTimeout();\n refreshTimeout = setTimeout(\n refresh,\n evt.detail.expires_in * 1000 - 60 * 1000,\n );\n }\n }\n\n async function signOut() {\n invariant(token, \"not signed in\");\n\n const result = await processRevocationResponse(\n await revocationRequest(\n as,\n client,\n token.access_token,\n oauthHttpOptions,\n ),\n );\n\n rmTimeout();\n\n // Clean up\n removeLocal(client);\n token = undefined;\n throwIfError(result);\n eventTarget.dispatchTypedEvent(\"signOut\", new Event(\"signOut\"));\n }\n\n let pendingSignIn: Promise<Token> | undefined;\n async function signIn() {\n if (pendingSignIn) {\n return pendingSignIn;\n }\n try {\n pendingSignIn = _signIn();\n return await pendingSignIn;\n } finally {\n pendingSignIn = undefined;\n }\n }\n\n eventTarget.addEventListener(\"signIn\", restartRefreshTimer);\n eventTarget.addEventListener(\"refresh\", restartRefreshTimer);\n\n function getTokenOrUndefined() {\n if (!token || Date.now() >= token.expires_at) {\n return undefined;\n }\n return token?.access_token;\n }\n\n const getToken = Object.assign(async function getToken() {\n if (!token || Date.now() >= token.expires_at) {\n token = await signIn();\n }\n return token?.access_token;\n }, {\n signIn,\n refresh,\n signOut,\n rmTimeout,\n getTokenOrUndefined,\n addEventListener: eventTarget.addEventListener.bind(\n eventTarget,\n ) as typeof eventTarget.addEventListener,\n removeEventListener: eventTarget.removeEventListener.bind(\n eventTarget,\n ) as typeof eventTarget.removeEventListener,\n });\n\n return { getToken, makeTokenAndSaveRefresh };\n}\n\nexport function createAuthorizationServer(\n ctxPath: string,\n url: string,\n): Required<\n Pick<\n AuthorizationServer,\n | \"issuer\"\n | \"token_endpoint\"\n | \"authorization_endpoint\"\n | \"revocation_endpoint\"\n >\n> {\n const issuer = `${new URL(ctxPath, url.endsWith(\"/\") ? url : url + \"/\")}`;\n return {\n token_endpoint: `${issuer}/api/oauth2/token`,\n authorization_endpoint: `${issuer}/api/oauth2/authorize`,\n revocation_endpoint: `${issuer}/api/oauth2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,CAAC;;MAEX;MACAhC,WAAW,CAACR,MAAM,CAAC;MACnBuB,KAAK,GAAGwB,SAAS;MACjBnD,YAAY,CAAC0D,MAAM,CAAC;MACpB9B,WAAW,CAACa,kBAAkB,CAAC,SAAS,EAAE,IAAIkB,KAAK,CAAC,SAAS,CAAC,CAAC;IACjE,CAiCS;IACPf,SAAS;IACTS,mBAAmB;IACnBD,gBAAgB,EAAExB,WAAW,CAACwB,gBAAgB,CAACQ,IAAI,CACjDhC,WACF,CAAwC;IACxCiC,mBAAmB,EAAEjC,WAAW,CAACiC,mBAAmB,CAACD,IAAI,CACvDhC,WACF;EACF,CAAC,CAAC;EAEF,OAAO;IAAE0B,QAAQ;IAAEzB;EAAwB,CAAC;AAC9C;AAEA,OAAO,SAASiC,yBAAyBA,CACvCC,OAAe,EACfC,GAAW,EASX;EACA,MAAMC,MAAM,GAAG,GAAG,IAAIC,GAAG,CAACH,OAAO,EAAEC,GAAG,CAACG,QAAQ,CAAC,GAAG,CAAC,GAAGH,GAAG,GAAGA,GAAG,GAAG,GAAG,CAAC,EAAE;EACzE,OAAO;IACLI,cAAc,EAAE,GAAGH,MAAM,mBAAmB;IAC5CI,sBAAsB,EAAE,GAAGJ,MAAM,uBAAuB;IACxDK,mBAAmB,EAAE,GAAGL,MAAM,0BAA0B;IACxDA;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
|
|
16
17
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
17
18
|
import { common, createAuthorizationServer, readLocal, removeLocal, saveLocal } from "./common.js";
|
|
18
19
|
describe("local functions", () => {
|
|
@@ -1 +1 @@
|
|
|
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","mocked","globalThis","localStorage","toBeCalledWith","anything","signIn","refresh","authServer","makeTokenAndSaveRefresh","refresh_token","access_token","token_type","expires_in","JSON","stringify","refreshTokenMarker"],"sources":["common.test.
|
|
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","mocked","globalThis","localStorage","toBeCalledWith","anything","signIn","refresh","authServer","makeTokenAndSaveRefresh","refresh_token","access_token","token_type","expires_in","JSON","stringify","refreshTokenMarker"],"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\n readLocal(client);\n removeLocal(client);\n saveLocal(client, {});\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\", () => {\n const client = {\n client_id: \"hi_mom\",\n };\n\n const signIn = vi.fn();\n const refresh = vi.fn();\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 );\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 }),\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,SA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BC,aAAa,EAAE,SAAS;MACxBC,YAAY,EAAE,QAAQ;MACtBC,UAAU,EAAE,KAAK;MACjBC,UAAU,EAAE;IACd,CAAC,EAAE,QAAQ,CAAC;IAEZ/B,MAAM,CAACoB,UAAU,CAACC,YAAY,CAACZ,OAAO,CAAC,CAACa,cAAc,CACpD,2BAA2BR,MAAM,CAACC,SAAS,EAAE,EAC7CiB,IAAI,CAACC,SAAS,CAAC;MACbL,aAAa,EAAE,SAAS;MACxBM,kBAAkB,EAAE;IACtB,CAAC,CACH,CAAC;EACH,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -13,9 +13,11 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
|
|
16
17
|
import { clientCredentialsGrantRequest, customFetch, processClientCredentialsResponse } from "oauth4webapi";
|
|
17
18
|
import { common, createAuthorizationServer } from "./common.js";
|
|
18
19
|
import { throwIfError } from "./throwIfError.js";
|
|
20
|
+
|
|
19
21
|
/**
|
|
20
22
|
* @param client_id
|
|
21
23
|
* @param client_secret
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createConfidentialOauthClient.js","names":["clientCredentialsGrantRequest","customFetch","processClientCredentialsResponse","common","createAuthorizationServer","throwIfError","createConfidentialOauthClient","client_id","client_secret","url","scopes","fetchFn","globalThis","fetch","ctxPath","client","authServer","oauthHttpOptions","getToken","makeTokenAndSaveRefresh","URLSearchParams","scope","join","undefined"],"sources":["createConfidentialOauthClient.
|
|
1
|
+
{"version":3,"file":"createConfidentialOauthClient.js","names":["clientCredentialsGrantRequest","customFetch","processClientCredentialsResponse","common","createAuthorizationServer","throwIfError","createConfidentialOauthClient","client_id","client_secret","url","scopes","fetchFn","globalThis","fetch","ctxPath","client","authServer","oauthHttpOptions","getToken","makeTokenAndSaveRefresh","URLSearchParams","scope","join","undefined"],"sources":["createConfidentialOauthClient.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 clientCredentialsGrantRequest,\n customFetch,\n processClientCredentialsResponse,\n} from \"oauth4webapi\";\nimport { common, createAuthorizationServer } from \"./common.js\";\nimport type { ConfidentialOauthClient } from \"./ConfidentialOauthClient.js\";\nimport { throwIfError } from \"./throwIfError.js\";\n\n/**\n * @param client_id\n * @param client_secret\n * @param url the base url of your foundry server\n * @param scopes\n * @param fetchFn\n * @param ctxPath\n * @returns which can be used as a token provider\n */\nexport function createConfidentialOauthClient(\n client_id: string,\n client_secret: string,\n url: string,\n scopes: string[] = [\"api:read-data\", \"api:write-data\"],\n fetchFn: typeof globalThis.fetch = globalThis.fetch,\n ctxPath: string = \"multipass\",\n): ConfidentialOauthClient {\n const client: Client = { client_id, client_secret };\n const authServer = createAuthorizationServer(ctxPath, url);\n const oauthHttpOptions: HttpRequestOptions = { [customFetch]: fetchFn };\n\n const { getToken, makeTokenAndSaveRefresh } = common(\n client,\n authServer,\n _signIn,\n oauthHttpOptions,\n undefined,\n undefined,\n );\n\n async function _signIn() {\n return makeTokenAndSaveRefresh(\n throwIfError(\n await processClientCredentialsResponse(\n authServer,\n client,\n await clientCredentialsGrantRequest(\n authServer,\n client,\n new URLSearchParams({ scope: scopes.join(\" \") }),\n oauthHttpOptions,\n ),\n ),\n ),\n \"signIn\",\n );\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,WAAW,EACXC,gCAAgC,QAC3B,cAAc;AACrB,SAASC,MAAM,EAAEC,yBAAyB,QAAQ,aAAa;AAE/D,SAASC,YAAY,QAAQ,mBAAmB;;AAEhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,6BAA6BA,CAC3CC,SAAiB,EACjBC,aAAqB,EACrBC,GAAW,EACXC,MAAgB,GAAG,CAAC,eAAe,EAAE,gBAAgB,CAAC,EACtDC,OAAgC,GAAGC,UAAU,CAACC,KAAK,EACnDC,OAAe,GAAG,WAAW,EACJ;EACzB,MAAMC,MAAc,GAAG;IAAER,SAAS;IAAEC;EAAc,CAAC;EACnD,MAAMQ,UAAU,GAAGZ,yBAAyB,CAACU,OAAO,EAAEL,GAAG,CAAC;EAC1D,MAAMQ,gBAAoC,GAAG;IAAE,CAAChB,WAAW,GAAGU;EAAQ,CAAC;EAEvE,MAAM;IAAEO,QAAQ;IAAEC;EAAwB,CAAC,GAAGhB,MAAM,CAClDY,MAAM,EACNC,UAAU,EAOZ,kBAAyB;IACvB,OAAOG,uBAAuB,CAC5Bd,YAAY,CACV,MAAMH,gCAAgC,CACpCc,UAAU,EACVD,MAAM,EACN,MAAMf,6BAA6B,CACjCgB,UAAU,EACVD,MAAM,EACN,IAAIK,eAAe,CAAC;MAAEC,KAAK,EAAEX,MAAM,CAACY,IAAI,CAAC,GAAG;IAAE,CAAC,CAAC,EAChDL,gBACF,CACF,CACF,CAAC,EACD,QACF,CAAC;EACH,CAAC,EArBCA,gBAAgB,EAChBM,SAAS,EACTA,SACF,CAAC;EAoBD,OAAOL,QAAQ;AACjB","ignoreList":[]}
|
|
@@ -13,11 +13,38 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
|
|
16
17
|
import delay from "delay";
|
|
17
18
|
import { authorizationCodeGrantRequest, calculatePKCECodeChallenge, customFetch, generateRandomCodeVerifier, generateRandomState, processAuthorizationCodeOAuth2Response, refreshTokenGrantRequest, validateAuthResponse } from "oauth4webapi";
|
|
18
19
|
import { common, createAuthorizationServer, readLocal, readSession, removeLocal, removeSession, saveLocal, saveSession } from "./common.js";
|
|
19
20
|
import { throwIfError } from "./throwIfError.js";
|
|
20
21
|
import { processOptionsAndAssignDefaults } from "./utils.js";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Creates a PublicOauthClient for authentication.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} clientId - The client_id from the OAuth configuration on the server
|
|
27
|
+
* @param {string} url - The base URL of your Foundry server
|
|
28
|
+
* @param {string} redirectUrl - The URL configured for redirect in the OAuth configuration on the server
|
|
29
|
+
* @param {PublicOauthClientOptions} options - Additional options for the client
|
|
30
|
+
* @returns {PublicOauthClient} A client that can be used as a token provider
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Creates a PublicOauthClient for authentication.
|
|
35
|
+
*
|
|
36
|
+
* @param {string} clientId - The client_id from the OAuth configuration on the server
|
|
37
|
+
* @param {string} url - The base URL of your Foundry server
|
|
38
|
+
* @param {string} redirectUrl - The URL configured for redirect in the OAuth configuration on the server
|
|
39
|
+
* @param {boolean} useHistory - If true, uses `history.replaceState()`, otherwise uses `window.location.assign()` (defaults to true)
|
|
40
|
+
* @param {string} loginPage - Custom landing page URL prior to logging in
|
|
41
|
+
* @param {string} postLoginPage - URL to return to after completed authentication cycle (defaults to `window.location.toString()`)
|
|
42
|
+
* @param {string[]} scopes - OAuth scopes to request. If not provided, defaults to `["api:read-data", "api:write-data"]`
|
|
43
|
+
* @param {typeof globalThis.fetch} fetchFn - Custom fetch function to use for requests (defaults to `globalThis.fetch`)
|
|
44
|
+
* @param {string} ctxPath - Context path for the authorization server (defaults to "multipass")
|
|
45
|
+
* @returns {PublicOauthClient} A client that can be used as a token provider
|
|
46
|
+
*/
|
|
47
|
+
|
|
21
48
|
export function createPublicOauthClient(client_id, url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath) {
|
|
22
49
|
let refreshTokenMarker;
|
|
23
50
|
({
|
|
@@ -49,6 +76,7 @@ export function createPublicOauthClient(client_id, url, redirect_uri, useHistory
|
|
|
49
76
|
// 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
|
|
50
77
|
?? (await initiateLoginRedirect());
|
|
51
78
|
}, oauthHttpOptions, maybeRefresh.bind(globalThis, true), refreshTokenMarker);
|
|
79
|
+
|
|
52
80
|
// as an arrow function, `useHistory` is known to be a boolean
|
|
53
81
|
const go = async x => {
|
|
54
82
|
if (useHistory) {
|
|
@@ -111,6 +139,7 @@ export function createPublicOauthClient(client_id, url, redirect_uri, useHistory
|
|
|
111
139
|
throw e;
|
|
112
140
|
}
|
|
113
141
|
}
|
|
142
|
+
|
|
114
143
|
// As an arrow function, `scopes` and `postLoginPage` are known at compile time
|
|
115
144
|
const initiateLoginRedirect = async () => {
|
|
116
145
|
if (loginPage && window.location.href !== loginPage && window.location.pathname !== loginPage) {
|
|
@@ -139,6 +168,7 @@ export function createPublicOauthClient(client_id, url, redirect_uri, useHistory
|
|
|
139
168
|
code_challenge_method: "S256",
|
|
140
169
|
scope: ["offline_access", ...scopes].join(" ")
|
|
141
170
|
})}`);
|
|
171
|
+
|
|
142
172
|
// Give time for redirect to happen
|
|
143
173
|
await delay(1000);
|
|
144
174
|
throw new Error("Unable to redirect");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPublicOauthClient.js","names":["delay","authorizationCodeGrantRequest","calculatePKCECodeChallenge","customFetch","generateRandomCodeVerifier","generateRandomState","processAuthorizationCodeOAuth2Response","refreshTokenGrantRequest","validateAuthResponse","common","createAuthorizationServer","readLocal","readSession","removeLocal","removeSession","saveLocal","saveSession","throwIfError","processOptionsAndAssignDefaults","createPublicOauthClient","client_id","url","redirect_uri","useHistory","loginPage","postLoginPage","scopes","fetchFn","ctxPath","refreshTokenMarker","client","token_endpoint_auth_method","authServer","oauthHttpOptions","makeTokenAndSaveRefresh","getToken","_signIn","maybeRefresh","maybeHandleAuthReturn","initiateLoginRedirect","bind","globalThis","go","x","window","history","replaceState","location","assign","Error","expectRefreshToken","refresh_token","lastRefreshTokenMarker","result","pathname","URL","oldUrl","e","process","env","NODE_ENV","console","warn","state","codeVerifier","ret","href","toString","authorization_endpoint","URLSearchParams","response_type","code_challenge","code_challenge_method","scope","join"],"sources":["createPublicOauthClient.js"],"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 */\nimport delay from \"delay\";\nimport { authorizationCodeGrantRequest, calculatePKCECodeChallenge, customFetch, generateRandomCodeVerifier, generateRandomState, processAuthorizationCodeOAuth2Response, refreshTokenGrantRequest, validateAuthResponse, } from \"oauth4webapi\";\nimport { common, createAuthorizationServer, readLocal, readSession, removeLocal, removeSession, saveLocal, saveSession, } from \"./common.js\";\nimport { throwIfError } from \"./throwIfError.js\";\nimport { processOptionsAndAssignDefaults } from \"./utils.js\";\nexport function createPublicOauthClient(client_id, url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath) {\n let refreshTokenMarker;\n ({\n useHistory,\n loginPage,\n postLoginPage,\n scopes,\n fetchFn,\n ctxPath,\n refreshTokenMarker,\n } = processOptionsAndAssignDefaults(url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath));\n const client = {\n client_id,\n token_endpoint_auth_method: \"none\",\n };\n const authServer = createAuthorizationServer(ctxPath, url);\n const oauthHttpOptions = { [customFetch]: fetchFn };\n const { makeTokenAndSaveRefresh, getToken } = common(client, authServer, _signIn, oauthHttpOptions, maybeRefresh.bind(globalThis, true), refreshTokenMarker);\n // as an arrow function, `useHistory` is known to be a boolean\n const go = async (x) => {\n if (useHistory) {\n window.history.replaceState({}, \"\", x);\n return;\n }\n else\n window.location.assign(x);\n await delay(1000);\n throw new Error(\"Unable to redirect\");\n };\n async function maybeRefresh(expectRefreshToken) {\n const { refresh_token, refreshTokenMarker: lastRefreshTokenMarker } = readLocal(client);\n if (!refresh_token || lastRefreshTokenMarker !== refreshTokenMarker) {\n if (expectRefreshToken)\n throw new Error(\"No refresh token found\");\n return;\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(throwIfError(await processAuthorizationCodeOAuth2Response(authServer, client, await refreshTokenGrantRequest(authServer, client, refresh_token, oauthHttpOptions))), \"refresh\");\n if (result && window.location.pathname === new URL(redirect_uri).pathname) {\n const { oldUrl } = readSession(client);\n // don't block on the redirect\n void go(oldUrl ?? \"/\");\n }\n return result;\n }\n catch (e) {\n if (process.env.NODE_ENV !== \"production\") {\n // eslint-disable-next-line no-console\n console.warn(\"Failed to get OAuth2 refresh token. Removing refresh token\", e);\n }\n removeLocal(client);\n if (expectRefreshToken) {\n throw new Error(\"Could not refresh token\");\n }\n }\n }\n async function maybeHandleAuthReturn() {\n const { state, oldUrl, codeVerifier } = readSession(client);\n if (!codeVerifier)\n return;\n try {\n const ret = makeTokenAndSaveRefresh(throwIfError(await processAuthorizationCodeOAuth2Response(authServer, client, await authorizationCodeGrantRequest(authServer, client, throwIfError(validateAuthResponse(authServer, client, new URL(window.location.href), state)), redirect_uri, codeVerifier, oauthHttpOptions))), \"signIn\");\n void go(oldUrl);\n return ret;\n }\n catch (e) {\n if (process.env.NODE_ENV !== \"production\") {\n // eslint-disable-next-line no-console\n console.warn(\"Failed to get OAuth2 token using PKCE, removing PKCE and starting a new auth flow\", e);\n }\n removeLocal(client);\n removeSession(client);\n throw e;\n }\n }\n // As an arrow function, `scopes` and `postLoginPage` are known at compile time\n const initiateLoginRedirect = async () => {\n if (loginPage\n && window.location.href !== loginPage\n && window.location.pathname !== loginPage) {\n saveLocal(client, {});\n saveSession(client, { oldUrl: postLoginPage });\n await go(loginPage);\n return;\n }\n const state = generateRandomState();\n const codeVerifier = generateRandomCodeVerifier();\n const oldUrl = readSession(client).oldUrl ?? window.location.toString();\n saveLocal(client, {});\n saveSession(client, { codeVerifier, state, oldUrl });\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: [\"offline_access\", ...scopes].join(\" \"),\n })}`);\n // Give time for redirect to happen\n await delay(1000);\n throw new Error(\"Unable to redirect\");\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();\n }\n return getToken;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,6BAA6B,EAAEC,0BAA0B,EAAEC,WAAW,EAAEC,0BAA0B,EAAEC,mBAAmB,EAAEC,sCAAsC,EAAEC,wBAAwB,EAAEC,oBAAoB,QAAS,cAAc;AAC/O,SAASC,MAAM,EAAEC,yBAAyB,EAAEC,SAAS,EAAEC,WAAW,EAAEC,WAAW,EAAEC,aAAa,EAAEC,SAAS,EAAEC,WAAW,QAAS,aAAa;AAC5I,SAASC,YAAY,QAAQ,mBAAmB;AAChD,SAASC,+BAA+B,QAAQ,YAAY;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AC,CAAC;IACjD,MAAMoD,MAAM,GAAG5C,WAAW,CAACkB,MAAM,CAAC,CAAC0B,MAAM,IAAIZ,MAAM,CAACG,QAAQ,CAACoB,QAAQ,CAAC,CAAC;IACvEpD,SAAS,CAACe,MAAM,EAAE,CAAC,CAAC,CAAC;IACrBd,WAAW,CAACc,MAAM,EAAE;MAAEkC,YAAY;MAAED,KAAK;MAAEP;IAAO,CAAC,CAAC;IACpDZ,MAAM,CAACG,QAAQ,CAACC,MAAM,CAAC,GAAGhB,UAAU,CAC/BoC,sBAAsB,IAAI,IAAIC,eAAe,CAAC;MAC/CjD,SAAS;MACTkD,aAAa,EAAE,MAAM;MACrBP,KAAK;MACLzC,YAAY;MACZiD,cAAc,EAAE,MAAMrE,0BAA0B,CAAC8D,YAAY,CAAC;MAC9DQ,qBAAqB,EAAE,MAAM;MAC7BC,KAAK,EAAE,CAAC,gBAAgB,EAAE,GAAG/C,MAAM,CAAC,CAACgD,IAAI,CAAC,GAAG;IACjD,CAAC,CAAC,EAAE,CAAC;IACL;IACA,MAAM1E,KAAK,CAAC,IAAI,CAAC;IACjB,MAAM,IAAIiD,KAAK,CAAC,oBAAoB,CAAC;EACzC,CAAC;EAUD,OAAOd,QAAQ;AACnB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"createPublicOauthClient.js","names":["delay","authorizationCodeGrantRequest","calculatePKCECodeChallenge","customFetch","generateRandomCodeVerifier","generateRandomState","processAuthorizationCodeOAuth2Response","refreshTokenGrantRequest","validateAuthResponse","common","createAuthorizationServer","readLocal","readSession","removeLocal","removeSession","saveLocal","saveSession","throwIfError","processOptionsAndAssignDefaults","createPublicOauthClient","client_id","url","redirect_uri","useHistory","loginPage","postLoginPage","scopes","fetchFn","ctxPath","refreshTokenMarker","client","token_endpoint_auth_method","authServer","oauthHttpOptions","makeTokenAndSaveRefresh","getToken","_signIn","maybeRefresh","maybeHandleAuthReturn","initiateLoginRedirect","bind","globalThis","go","x","window","history","replaceState","location","assign","Error","expectRefreshToken","refresh_token","lastRefreshTokenMarker","result","pathname","URL","oldUrl","e","process","env","NODE_ENV","console","warn","state","codeVerifier","ret","href","toString","authorization_endpoint","URLSearchParams","response_type","code_challenge","code_challenge_method","scope","join"],"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 delay from \"delay\";\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 readLocal,\n readSession,\n removeLocal,\n removeSession,\n saveLocal,\n saveSession,\n} from \"./common.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\"]`\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/**\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\"]`\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 ({\n useHistory,\n loginPage,\n postLoginPage,\n scopes,\n fetchFn,\n ctxPath,\n refreshTokenMarker,\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 { makeTokenAndSaveRefresh, getToken } = common(\n client,\n authServer,\n _signIn,\n oauthHttpOptions,\n maybeRefresh.bind(globalThis, true),\n refreshTokenMarker,\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 const { refresh_token, refreshTokenMarker: lastRefreshTokenMarker } =\n readLocal(client);\n\n if (!refresh_token || lastRefreshTokenMarker !== refreshTokenMarker) {\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);\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);\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, {});\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, {});\n saveSession(client, { codeVerifier, state, oldUrl });\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: [\"offline_access\", ...scopes].join(\" \"),\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;;AAEA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SACEC,6BAA6B,EAC7BC,0BAA0B,EAC1BC,WAAW,EACXC,0BAA0B,EAC1BC,mBAAmB,EACnBC,sCAAsC,EACtCC,wBAAwB,EACxBC,oBAAoB,QACf,cAAc;AACrB,SACEC,MAAM,EACNC,yBAAyB,EACzBC,SAAS,EACTC,WAAW,EACXC,WAAW,EACXC,aAAa,EACbC,SAAS,EACTC,WAAW,QACN,aAAa;AAEpB,SAASC,YAAY,QAAQ,mBAAmB;AAEhD,SAASC,+BAA+B,QAAQ,YAAY;;AA8C5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA,OAAO,SAASC,uBAAuBA,CACrCC,SAAiB,EACjBC,GAAW,EACXC,YAAoB,EACpBC,UAA+C,EAC/CC,SAAkB,EAClBC,aAAsB,EACtBC,MAAiB,EACjBC,OAAiC,EACjCC,OAAgB,EACG;EACnB,IAAIC,kBAAsC;EAC1C,CAAC;IACCN,UAAU;IACVC,SAAS;IACTC,aAAa;IACbC,MAAM;IACNC,OAAO;IACPC,OAAO;IACPC;EACF,CAAC,GAAGX,+BAA+B,CACjCG,GAAG,EACHC,YAAY,EACZC,UAAU,EACVC,SAAS,EACTC,aAAa,EACbC,MAAM,EACNC,OAAO,EACPC,OACF,CAAC;EAED,MAAME,MAAc,GAAG;IACrBV,SAAS;IACTW,0BAA0B,EAAE;EAC9B,CAAC;EACD,MAA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AAE,MAAM;MAC7BC,KAAK,EAAE,CAAC,gBAAgB,EAAE,GAAG/C,MAAM,CAAC,CAACgD,IAAI,CAAC,GAAG;IAC/C,CAAC,CAAC,EAAE,CAAC;;IAEL;IACA,MAAM1E,KAAK,CAAC,IAAI,CAAC;IACjB,MAAM,IAAIiD,KAAK,CAAC,oBAAoB,CAAC;EACvC,CAAC;EAYD,OAAOd,QAAQ;AACjB","ignoreList":[]}
|
package/build/browser/index.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
|
|
16
17
|
export { createConfidentialOauthClient } from "./createConfidentialOauthClient.js";
|
|
17
18
|
export { createPublicOauthClient } from "./createPublicOauthClient.js";
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["createConfidentialOauthClient","createPublicOauthClient"],"sources":["index.
|
|
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 { createConfidentialOauthClient } from \"./createConfidentialOauthClient.js\";\nexport { createPublicOauthClient } 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;;AAEA,SAASA,6BAA6B,QAAQ,oCAAoC;AAClF,SAASC,uBAAuB,QAAQ,8BAA8B","ignoreList":[]}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
|
|
16
17
|
/* eslint-disable @typescript-eslint/consistent-type-imports */
|
|
17
18
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
18
19
|
import * as commonJs from "./common.js";
|