@logto/node 1.0.0-beta.2 → 1.0.0-beta.3
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/README.md +46 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +7 -6
- package/lib/index.js.map +1 -1
- package/lib/module.js +7 -6
- package/lib/module.js.map +1 -1
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Logto Node.js SDK
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@logto/node)
|
|
4
|
+
[](https://github.com/logto-io/js/actions/workflows/main.yml)
|
|
5
|
+
[](https://app.codecov.io/gh/logto-io/js?branch=master)
|
|
6
|
+
|
|
7
|
+
The Logto Node.js SDK written in TypeScript. Check out our [docs](https://docs.logto.io/sdk/JavaScript/node/) for more information.
|
|
8
|
+
|
|
9
|
+
We also provide [文档](https://docs.logto.io/zh-cn/sdk/JavaScript/node/) in Simplified Chinese.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
### Using npm
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @logto/node
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Using yarn
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
yarn add @logto/node
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Using pnpm
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pnpm add @logto/node
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## What is this and how does it work?
|
|
32
|
+
|
|
33
|
+
As the name suggests, Logto Node.js SDK is the foundation of all Logto SDKs that run in Node.js (Express, Next.js, etc.). `@logto/node` extends `@logto/client` and provides a Node.js specific implementation of the client adapters:
|
|
34
|
+
|
|
35
|
+
- Implements `requester` by using package `node-fetch`.
|
|
36
|
+
- Implements `generateCodeChallenge`, `generateCodeVerifier`, `generateState` methods by using `crypto`.
|
|
37
|
+
|
|
38
|
+
Usually you are not expected to use it directly in your application, but instead choosing a framework specific SDK that built on top of it. We have already released a set of official SDKs to accelerate your integration. [Check this out](https://docs.logto.io/docs/recipes/integrate-logto/) and get started!
|
|
39
|
+
|
|
40
|
+
If Logto does not support your traditional web framework and you want to create your own SDK from scratch, we recommend checking out the SDK specification first. You can also refer to our [Express SDK](https://github.com/logto-io/js/tree/master/packages/express) and [Next.js SDK](https://github.com/logto-io/js/tree/master/packages/next) to learn more about the implementation details.
|
|
41
|
+
|
|
42
|
+
## Resources
|
|
43
|
+
|
|
44
|
+
[](https://logto.io/)
|
|
45
|
+
[](https://docs.logto.io/sdk/JavaScript/node/)
|
|
46
|
+
[](https://discord.gg/UEPaF3j5e6)
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";AAEA,eAAe,MAAM,CAAC;IACpB,UAAU,eAAe;QACvB,IAAI,EAAE,YAAY,CAAC;KACpB;CACF;AAED,2BAA2B;IACzB,eAAe,EAAE,OAAO,CAAC;IACzB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AEJF,YAAY,EACV,aAAa,EACb,cAAc,EACd,WAAW,EACX,oBAAoB,EACpB,OAAO,EACP,UAAU,GACX,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEnG,gCAAiC,SAAQ,UAAU;gBACrC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,UAAU,GAAG,SAAS,CAAC;
|
|
1
|
+
{"mappings":";AAEA,eAAe,MAAM,CAAC;IACpB,UAAU,eAAe;QACvB,IAAI,EAAE,YAAY,CAAC;KACpB;CACF;AAED,2BAA2B;IACzB,eAAe,EAAE,OAAO,CAAC;IACzB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AEJF,YAAY,EACV,aAAa,EACb,cAAc,EACd,WAAW,EACX,oBAAoB,EACpB,OAAO,EACP,UAAU,GACX,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEnG,gCAAiC,SAAQ,UAAU;gBACrC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,UAAU,GAAG,SAAS,CAAC;IA6BrF,UAAU,gCAAmC,QAAQ,YAAY,CAAC,CA+BhE;CACH","sources":["packages/node/src/src/types.ts","packages/node/src/src/utils/generators.ts","packages/node/src/src/index.ts","packages/node/src/index.ts"],"sourcesContent":[null,null,null,"import BaseClient, { LogtoConfig, createRequester, ClientAdapter } from '@logto/client';\nimport fetch from 'node-fetch';\n\nimport { LogtoContext } from './types';\nimport { generateCodeChallenge, generateCodeVerifier, generateState } from './utils/generators';\n\nexport type { LogtoContext } from './types';\n\nexport type {\n IdTokenClaims,\n LogtoErrorCode,\n LogtoConfig,\n LogtoClientErrorCode,\n Storage,\n StorageKey,\n} from '@logto/client';\nexport { LogtoError, OidcError, Prompt, LogtoRequestError, LogtoClientError } from '@logto/client';\n\nexport default class LogtoClient extends BaseClient {\n constructor(config: LogtoConfig, adapter: Pick<ClientAdapter, 'navigate' | 'storage'>) {\n super(config, {\n ...adapter,\n requester: createRequester(\n config.appSecret\n ? async (...args: Parameters<typeof fetch>) => {\n const [input, init] = args;\n\n return fetch(input, {\n ...init,\n headers: {\n ...init?.headers,\n\n authorization: `basic ${Buffer.from(\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `${config.appId}:${config.appSecret}`,\n 'utf8'\n ).toString('base64')}`,\n },\n });\n }\n : fetch\n ),\n generateCodeChallenge,\n generateCodeVerifier,\n generateState,\n });\n }\n\n getContext = async (getAccessToken = false): Promise<LogtoContext> => {\n const isAuthenticated = await this.isAuthenticated();\n\n if (!isAuthenticated) {\n return {\n isAuthenticated,\n };\n }\n\n const claims = await this.getIdTokenClaims();\n\n if (!getAccessToken) {\n return {\n isAuthenticated,\n claims,\n };\n }\n\n try {\n const accessToken = await this.getAccessToken();\n\n return {\n isAuthenticated,\n claims: await this.getIdTokenClaims(),\n accessToken,\n };\n } catch {\n return {\n isAuthenticated: false,\n };\n }\n };\n}\n"],"names":[],"version":3,"file":"index.d.ts.map"}
|
package/lib/index.js
CHANGED
|
@@ -42,16 +42,16 @@ const $062ada5067f1da29$export$414b01b1f867308a = async (codeVerifier)=>{
|
|
|
42
42
|
|
|
43
43
|
class $cc9b2db9d73faa66$export$2e2bcd8739ae039 extends (0, ($parcel$interopDefault($gSEHM$logtoclient))) {
|
|
44
44
|
constructor(config, adapter){
|
|
45
|
-
const { appId: appId , appSecret: appSecret } = config;
|
|
46
45
|
super(config, {
|
|
47
46
|
...adapter,
|
|
48
|
-
requester: (0, $gSEHM$logtoclient.createRequester)(appSecret ? async (...args)=>{
|
|
47
|
+
requester: (0, $gSEHM$logtoclient.createRequester)(config.appSecret ? async (...args)=>{
|
|
49
48
|
const [input, init] = args;
|
|
50
49
|
return (0, ($parcel$interopDefault($gSEHM$nodefetch)))(input, {
|
|
51
50
|
...init,
|
|
52
51
|
headers: {
|
|
53
52
|
...init?.headers,
|
|
54
|
-
authorization: `basic ${Buffer.from(
|
|
53
|
+
authorization: `basic ${Buffer.from(// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
54
|
+
`${config.appId}:${config.appSecret}`, "utf8").toString("base64")}`
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
} : (0, ($parcel$interopDefault($gSEHM$nodefetch)))),
|
|
@@ -61,19 +61,20 @@ class $cc9b2db9d73faa66$export$2e2bcd8739ae039 extends (0, ($parcel$interopDefau
|
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
getContext = async (getAccessToken = false)=>{
|
|
64
|
-
const
|
|
64
|
+
const isAuthenticated = await this.isAuthenticated();
|
|
65
65
|
if (!isAuthenticated) return {
|
|
66
66
|
isAuthenticated: isAuthenticated
|
|
67
67
|
};
|
|
68
|
+
const claims = await this.getIdTokenClaims();
|
|
68
69
|
if (!getAccessToken) return {
|
|
69
70
|
isAuthenticated: isAuthenticated,
|
|
70
|
-
claims:
|
|
71
|
+
claims: claims
|
|
71
72
|
};
|
|
72
73
|
try {
|
|
73
74
|
const accessToken = await this.getAccessToken();
|
|
74
75
|
return {
|
|
75
76
|
isAuthenticated: isAuthenticated,
|
|
76
|
-
claims: this.getIdTokenClaims(),
|
|
77
|
+
claims: await this.getIdTokenClaims(),
|
|
77
78
|
accessToken: accessToken
|
|
78
79
|
};
|
|
79
80
|
} catch {
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;ACCA;;AAIA;;GAEG,CACH,MAAM,0CAAoB,GAAG,CAAC,MAAM,GAAG,EAAE,GACvC,CAAA,GAAA,8BAAc,CAAA,CAAC,CAAA,GAAA,4BAAc,CAAA,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,AAAC;AAKxD,MAAM,yCAAa,GAAG,IAAM,0CAAoB,EAAE,AAAC;AAOnD,MAAM,yCAAoB,GAAG,IAAM,0CAAoB,EAAE,AAAC;AAQ1D,MAAM,yCAAqB,GAAG,OAAO,YAAoB,GAAsB;IACpF,MAAM,mBAAmB,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,AAAC;IACnE,MAAM,IAAI,GAAG,CAAA,GAAA,wBAAU,CAAA,CAAC,QAAQ,CAAC,AAAC;IAClC,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;IACjC,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,EAAE,AAAC;IA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AE3B,OAAO,CAAA,GAAA,0CAAK,CAAA,CAAC,KAAK,EAAE;oBAClB,GAAG,IAAI;oBACP,OAAO,EAAE;wBACP,GAAG,IAAI,EAAE,OAAO;wBAEhB,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CACjC,4EAA4E;wBAC5E,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,EACrC,MAAM,CACP,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;qBACvB;iBACF,CAAC,CAAC;aACJ,GACD,CAAA,GAAA,0CAAK,CAAA,CACV;mCACD,yCAAqB;kCACrB,yCAAoB;2BACpB,yCAAa;SACd,CAAC,CAAC;KACJ;IAED,UAAU,GAAG,OAAO,cAAc,GAAG,KAAK,GAA4B;QACpE,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,AAAC;QAErD,IAAI,CAAC,eAAe,EAClB,OAAO;6BACL,eAAe;SAChB,CAAC;QAGJ,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,gBAAgB,EAAE,AAAC;QAE7C,IAAI,CAAC,cAAc,EACjB,OAAO;6BACL,eAAe;oBACf,MAAM;SACP,CAAC;QAGJ,IAAI;YACF,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,AAAC;YAEhD,OAAO;iCACL,eAAe;gBACf,MAAM,EAAE,MAAM,IAAI,CAAC,gBAAgB,EAAE;6BACrC,WAAW;aACZ,CAAC;SACH,CAAC,OAAM;YACN,OAAO;gBACL,eAAe,EAAE,KAAK;aACvB,CAAC;SACH;KACF,CAAC;CACH","sources":["packages/node/src/index.ts","packages/node/src/utils/generators.ts"],"sourcesContent":["import BaseClient, { LogtoConfig, createRequester, ClientAdapter } from '@logto/client';\nimport fetch from 'node-fetch';\n\nimport { LogtoContext } from './types';\nimport { generateCodeChallenge, generateCodeVerifier, generateState } from './utils/generators';\n\nexport type { LogtoContext } from './types';\n\nexport type {\n IdTokenClaims,\n LogtoErrorCode,\n LogtoConfig,\n LogtoClientErrorCode,\n Storage,\n StorageKey,\n} from '@logto/client';\nexport { LogtoError, OidcError, Prompt, LogtoRequestError, LogtoClientError } from '@logto/client';\n\nexport default class LogtoClient extends BaseClient {\n constructor(config: LogtoConfig, adapter: Pick<ClientAdapter, 'navigate' | 'storage'>) {\n super(config, {\n ...adapter,\n requester: createRequester(\n config.appSecret\n ? async (...args: Parameters<typeof fetch>) => {\n const [input, init] = args;\n\n return fetch(input, {\n ...init,\n headers: {\n ...init?.headers,\n\n authorization: `basic ${Buffer.from(\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `${config.appId}:${config.appSecret}`,\n 'utf8'\n ).toString('base64')}`,\n },\n });\n }\n : fetch\n ),\n generateCodeChallenge,\n generateCodeVerifier,\n generateState,\n });\n }\n\n getContext = async (getAccessToken = false): Promise<LogtoContext> => {\n const isAuthenticated = await this.isAuthenticated();\n\n if (!isAuthenticated) {\n return {\n isAuthenticated,\n };\n }\n\n const claims = await this.getIdTokenClaims();\n\n if (!getAccessToken) {\n return {\n isAuthenticated,\n claims,\n };\n }\n\n try {\n const accessToken = await this.getAccessToken();\n\n return {\n isAuthenticated,\n claims: await this.getIdTokenClaims(),\n accessToken,\n };\n } catch {\n return {\n isAuthenticated: false,\n };\n }\n };\n}\n","/** @link [Proof Key for Code Exchange by OAuth Public Clients](https://datatracker.ietf.org/doc/html/rfc7636) */\nimport { randomFillSync, createHash } from 'crypto';\n\nimport { fromUint8Array } from 'js-base64';\n\n/**\n * @param length The length of the raw random data.\n */\nconst generateRandomString = (length = 64) =>\n fromUint8Array(randomFillSync(new Uint8Array(length)), true);\n\n/**\n * Generates random string for state and encodes them in url safe base64\n */\nexport const generateState = () => generateRandomString();\n\n/**\n * Generates code verifier\n *\n * @link [Client Creates a Code Verifier](https://datatracker.ietf.org/doc/html/rfc7636#section-4.1)\n */\nexport const generateCodeVerifier = () => generateRandomString();\n\n/**\n * Calculates the S256 PKCE code challenge for an arbitrary code verifier and encodes it in url safe base64\n *\n * @param {String} codeVerifier Code verifier to calculate the S256 code challenge for\n * @link [Client Creates the Code Challenge](https://datatracker.ietf.org/doc/html/rfc7636#section-4.2)\n */\nexport const generateCodeChallenge = async (codeVerifier: string): Promise<string> => {\n const encodedCodeVerifier = new TextEncoder().encode(codeVerifier);\n const hash = createHash('sha256');\n hash.update(encodedCodeVerifier);\n const codeChallenge = hash.digest();\n\n return fromUint8Array(codeChallenge, true);\n};\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../../../"}
|
package/lib/module.js
CHANGED
|
@@ -27,16 +27,16 @@ const $91cf1946314e24ae$export$414b01b1f867308a = async (codeVerifier)=>{
|
|
|
27
27
|
var $0aca7ca5e7992ee0$require$Buffer = $jetHk$Buffer;
|
|
28
28
|
class $0aca7ca5e7992ee0$export$2e2bcd8739ae039 extends (0, $jetHk$logtoclient) {
|
|
29
29
|
constructor(config, adapter){
|
|
30
|
-
const { appId: appId , appSecret: appSecret } = config;
|
|
31
30
|
super(config, {
|
|
32
31
|
...adapter,
|
|
33
|
-
requester: (0, $jetHk$createRequester)(appSecret ? async (...args)=>{
|
|
32
|
+
requester: (0, $jetHk$createRequester)(config.appSecret ? async (...args)=>{
|
|
34
33
|
const [input, init] = args;
|
|
35
34
|
return (0, $jetHk$nodefetch)(input, {
|
|
36
35
|
...init,
|
|
37
36
|
headers: {
|
|
38
37
|
...init?.headers,
|
|
39
|
-
authorization: `basic ${$0aca7ca5e7992ee0$require$Buffer.from(
|
|
38
|
+
authorization: `basic ${$0aca7ca5e7992ee0$require$Buffer.from(// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
39
|
+
`${config.appId}:${config.appSecret}`, "utf8").toString("base64")}`
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
} : (0, $jetHk$nodefetch)),
|
|
@@ -46,19 +46,20 @@ class $0aca7ca5e7992ee0$export$2e2bcd8739ae039 extends (0, $jetHk$logtoclient) {
|
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
getContext = async (getAccessToken = false)=>{
|
|
49
|
-
const
|
|
49
|
+
const isAuthenticated = await this.isAuthenticated();
|
|
50
50
|
if (!isAuthenticated) return {
|
|
51
51
|
isAuthenticated: isAuthenticated
|
|
52
52
|
};
|
|
53
|
+
const claims = await this.getIdTokenClaims();
|
|
53
54
|
if (!getAccessToken) return {
|
|
54
55
|
isAuthenticated: isAuthenticated,
|
|
55
|
-
claims:
|
|
56
|
+
claims: claims
|
|
56
57
|
};
|
|
57
58
|
try {
|
|
58
59
|
const accessToken = await this.getAccessToken();
|
|
59
60
|
return {
|
|
60
61
|
isAuthenticated: isAuthenticated,
|
|
61
|
-
claims: this.getIdTokenClaims(),
|
|
62
|
+
claims: await this.getIdTokenClaims(),
|
|
62
63
|
accessToken: accessToken
|
|
63
64
|
};
|
|
64
65
|
} catch {
|
package/lib/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;AAAA;;ACCA;;AAIA;;GAEG,CACH,MAAM,0CAAoB,GAAG,CAAC,MAAM,GAAG,EAAE,GACvC,CAAA,GAAA,qBAAc,CAAA,CAAC,CAAA,GAAA,qBAAc,CAAA,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,AAAC;AAKxD,MAAM,yCAAa,GAAG,IAAM,0CAAoB,EAAE,AAAC;AAOnD,MAAM,yCAAoB,GAAG,IAAM,0CAAoB,EAAE,AAAC;AAQ1D,MAAM,yCAAqB,GAAG,OAAO,YAAoB,GAAsB;IACpF,MAAM,mBAAmB,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,AAAC;IACnE,MAAM,IAAI,GAAG,CAAA,GAAA,iBAAU,CAAA,CAAC,QAAQ,CAAC,AAAC;IAClC,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;IACjC,MAAM,aAAa,G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,GAAG,IAAI,AAAC;gBAE3B,OAAO,CAAA,GAAA,gBAAK,CAAA,CAAC,KAAK,EAAE;oBAClB,GAAG,IAAI;oBACP,OAAO,EAAE;wBACP,GAAG,IAAI,EAAE,OAAO;wBAEhB,aAAa,EAAE,CAAC,MAAM,EAAE,iCAAO,IAAI,CACjC,4EAA4E;wBAC5E,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,EACrC,MAAM,CACP,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;qBACvB;iBACF,CAAC,CAAC;aACJ,GACD,CAAA,GAAA,gBAAK,CAAA,CACV;mCACD,yCAAqB;kCACrB,yCAAoB;2BACpB,yCAAa;SACd,CAAC,CAAC;KACJ;IAED,UAAU,GAAG,OAAO,cAAc,GAAG,KAAK,GAA4B;QACpE,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,AAAC;QAErD,IAAI,CAAC,eAAe,EAClB,OAAO;6BACL,eAAe;SAChB,CAAC;QAGJ,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,gBAAgB,EAAE,AAAC;QAE7C,IAAI,CAAC,cAAc,EACjB,OAAO;6BACL,eAAe;oBACf,MAAM;SACP,CAAC;QAGJ,IAAI;YACF,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,AAAC;YAEhD,OAAO;iCACL,eAAe;gBACf,MAAM,EAAE,MAAM,IAAI,CAAC,gBAAgB,EAAE;6BACrC,WAAW;aACZ,CAAC;SACH,CAAC,OAAM;YACN,OAAO;gBACL,eAAe,EAAE,KAAK;aACvB,CAAC;SACH;KACF,CAAC;CACH","sources":["packages/node/src/index.ts","packages/node/src/utils/generators.ts"],"sourcesContent":["import BaseClient, { LogtoConfig, createRequester, ClientAdapter } from '@logto/client';\nimport fetch from 'node-fetch';\n\nimport { LogtoContext } from './types';\nimport { generateCodeChallenge, generateCodeVerifier, generateState } from './utils/generators';\n\nexport type { LogtoContext } from './types';\n\nexport type {\n IdTokenClaims,\n LogtoErrorCode,\n LogtoConfig,\n LogtoClientErrorCode,\n Storage,\n StorageKey,\n} from '@logto/client';\nexport { LogtoError, OidcError, Prompt, LogtoRequestError, LogtoClientError } from '@logto/client';\n\nexport default class LogtoClient extends BaseClient {\n constructor(config: LogtoConfig, adapter: Pick<ClientAdapter, 'navigate' | 'storage'>) {\n super(config, {\n ...adapter,\n requester: createRequester(\n config.appSecret\n ? async (...args: Parameters<typeof fetch>) => {\n const [input, init] = args;\n\n return fetch(input, {\n ...init,\n headers: {\n ...init?.headers,\n\n authorization: `basic ${Buffer.from(\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `${config.appId}:${config.appSecret}`,\n 'utf8'\n ).toString('base64')}`,\n },\n });\n }\n : fetch\n ),\n generateCodeChallenge,\n generateCodeVerifier,\n generateState,\n });\n }\n\n getContext = async (getAccessToken = false): Promise<LogtoContext> => {\n const isAuthenticated = await this.isAuthenticated();\n\n if (!isAuthenticated) {\n return {\n isAuthenticated,\n };\n }\n\n const claims = await this.getIdTokenClaims();\n\n if (!getAccessToken) {\n return {\n isAuthenticated,\n claims,\n };\n }\n\n try {\n const accessToken = await this.getAccessToken();\n\n return {\n isAuthenticated,\n claims: await this.getIdTokenClaims(),\n accessToken,\n };\n } catch {\n return {\n isAuthenticated: false,\n };\n }\n };\n}\n","/** @link [Proof Key for Code Exchange by OAuth Public Clients](https://datatracker.ietf.org/doc/html/rfc7636) */\nimport { randomFillSync, createHash } from 'crypto';\n\nimport { fromUint8Array } from 'js-base64';\n\n/**\n * @param length The length of the raw random data.\n */\nconst generateRandomString = (length = 64) =>\n fromUint8Array(randomFillSync(new Uint8Array(length)), true);\n\n/**\n * Generates random string for state and encodes them in url safe base64\n */\nexport const generateState = () => generateRandomString();\n\n/**\n * Generates code verifier\n *\n * @link [Client Creates a Code Verifier](https://datatracker.ietf.org/doc/html/rfc7636#section-4.1)\n */\nexport const generateCodeVerifier = () => generateRandomString();\n\n/**\n * Calculates the S256 PKCE code challenge for an arbitrary code verifier and encodes it in url safe base64\n *\n * @param {String} codeVerifier Code verifier to calculate the S256 code challenge for\n * @link [Client Creates the Code Challenge](https://datatracker.ietf.org/doc/html/rfc7636#section-4.2)\n */\nexport const generateCodeChallenge = async (codeVerifier: string): Promise<string> => {\n const encodedCodeVerifier = new TextEncoder().encode(codeVerifier);\n const hash = createHash('sha256');\n hash.update(encodedCodeVerifier);\n const codeChallenge = hash.digest();\n\n return fromUint8Array(codeChallenge, true);\n};\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/node",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.3",
|
|
4
4
|
"source": "./src/index.ts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"prepack": "pnpm test"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@logto/client": "^1.0.0-beta.
|
|
32
|
+
"@logto/client": "^1.0.0-beta.3",
|
|
33
33
|
"@silverhand/essentials": "^1.1.6",
|
|
34
34
|
"js-base64": "^3.7.2",
|
|
35
35
|
"node-fetch": "^2.6.7"
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "e227f9b92f76ea7e12c2aac3d5e5b24f2b85e7e8"
|
|
72
72
|
}
|