@logto/js 3.0.2 → 4.0.0-alpha.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/lib/core/fetch-token.cjs +2 -2
- package/lib/core/fetch-token.js +2 -2
- package/lib/core/revoke.cjs +1 -1
- package/lib/core/revoke.js +1 -1
- package/lib/core/sign-in.cjs +0 -2
- package/lib/core/sign-in.js +0 -2
- package/lib/index.cjs +0 -1
- package/lib/index.js +1 -1
- package/lib/utils/id-token.cjs +0 -9
- package/lib/utils/id-token.d.ts +0 -2
- package/lib/utils/id-token.js +1 -9
- package/package.json +3 -3
package/lib/core/fetch-token.cjs
CHANGED
|
@@ -20,7 +20,7 @@ const fetchTokenByAuthorizationCode = async ({ clientId, tokenEndpoint, redirect
|
|
|
20
20
|
const snakeCaseCodeTokenResponse = await requester(tokenEndpoint, {
|
|
21
21
|
method: 'POST',
|
|
22
22
|
headers: index.ContentType.formUrlEncoded,
|
|
23
|
-
body: parameters,
|
|
23
|
+
body: parameters.toString(),
|
|
24
24
|
});
|
|
25
25
|
return camelcaseKeys__default.default(snakeCaseCodeTokenResponse);
|
|
26
26
|
};
|
|
@@ -48,7 +48,7 @@ const fetchTokenByRefreshToken = async (params, requester) => {
|
|
|
48
48
|
const snakeCaseRefreshTokenTokenResponse = await requester(tokenEndpoint, {
|
|
49
49
|
method: 'POST',
|
|
50
50
|
headers: index.ContentType.formUrlEncoded,
|
|
51
|
-
body: parameters,
|
|
51
|
+
body: parameters.toString(),
|
|
52
52
|
});
|
|
53
53
|
return camelcaseKeys__default.default(snakeCaseRefreshTokenTokenResponse);
|
|
54
54
|
};
|
package/lib/core/fetch-token.js
CHANGED
|
@@ -14,7 +14,7 @@ const fetchTokenByAuthorizationCode = async ({ clientId, tokenEndpoint, redirect
|
|
|
14
14
|
const snakeCaseCodeTokenResponse = await requester(tokenEndpoint, {
|
|
15
15
|
method: 'POST',
|
|
16
16
|
headers: ContentType.formUrlEncoded,
|
|
17
|
-
body: parameters,
|
|
17
|
+
body: parameters.toString(),
|
|
18
18
|
});
|
|
19
19
|
return camelcaseKeys(snakeCaseCodeTokenResponse);
|
|
20
20
|
};
|
|
@@ -42,7 +42,7 @@ const fetchTokenByRefreshToken = async (params, requester) => {
|
|
|
42
42
|
const snakeCaseRefreshTokenTokenResponse = await requester(tokenEndpoint, {
|
|
43
43
|
method: 'POST',
|
|
44
44
|
headers: ContentType.formUrlEncoded,
|
|
45
|
-
body: parameters,
|
|
45
|
+
body: parameters.toString(),
|
|
46
46
|
});
|
|
47
47
|
return camelcaseKeys(snakeCaseRefreshTokenTokenResponse);
|
|
48
48
|
};
|
package/lib/core/revoke.cjs
CHANGED
package/lib/core/revoke.js
CHANGED
package/lib/core/sign-in.cjs
CHANGED
package/lib/core/sign-in.js
CHANGED
package/lib/index.cjs
CHANGED
|
@@ -32,7 +32,6 @@ exports.LogtoRequestError = errors.LogtoRequestError;
|
|
|
32
32
|
exports.OidcError = errors.OidcError;
|
|
33
33
|
exports.isLogtoRequestError = errors.isLogtoRequestError;
|
|
34
34
|
exports.decodeIdToken = idToken.decodeIdToken;
|
|
35
|
-
exports.verifyIdToken = idToken.verifyIdToken;
|
|
36
35
|
exports.decodeAccessToken = accessToken.decodeAccessToken;
|
|
37
36
|
exports.withDefaultScopes = scopes.withDefaultScopes;
|
|
38
37
|
exports.isArbitraryObject = arbitraryObject.isArbitraryObject;
|
package/lib/index.js
CHANGED
|
@@ -6,7 +6,7 @@ export { generateSignOutUri } from './core/sign-out.js';
|
|
|
6
6
|
export { fetchUserInfo } from './core/user-info.js';
|
|
7
7
|
export { parseUriParameters, verifyAndParseCodeFromCallbackUri } from './utils/callback-uri.js';
|
|
8
8
|
export { LogtoError, LogtoRequestError, OidcError, isLogtoRequestError } from './utils/errors.js';
|
|
9
|
-
export { decodeIdToken
|
|
9
|
+
export { decodeIdToken } from './utils/id-token.js';
|
|
10
10
|
export { decodeAccessToken } from './utils/access-token.js';
|
|
11
11
|
export { withDefaultScopes } from './utils/scopes.js';
|
|
12
12
|
export { isArbitraryObject } from './utils/arbitrary-object.js';
|
package/lib/utils/id-token.cjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var essentials = require('@silverhand/essentials');
|
|
4
|
-
var jose = require('jose');
|
|
5
4
|
var arbitraryObject = require('./arbitrary-object.cjs');
|
|
6
5
|
var errors = require('./errors.cjs');
|
|
7
6
|
|
|
8
|
-
const issuedAtTimeTolerance = 300; // 5 minutes
|
|
9
7
|
/* eslint-disable complexity */
|
|
10
8
|
/**
|
|
11
9
|
* @link [ID Token](https://openid.net/specs/openid-connect-core-1_0.html#IDToken)
|
|
@@ -42,12 +40,6 @@ function assertIdTokenClaims(data) {
|
|
|
42
40
|
}
|
|
43
41
|
}
|
|
44
42
|
/* eslint-enable complexity */
|
|
45
|
-
const verifyIdToken = async (idToken, clientId, issuer, jwks) => {
|
|
46
|
-
const result = await jose.jwtVerify(idToken, jwks, { audience: clientId, issuer });
|
|
47
|
-
if (Math.abs((result.payload.iat ?? 0) - Date.now() / 1000) > issuedAtTimeTolerance) {
|
|
48
|
-
throw new errors.LogtoError('id_token.invalid_iat');
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
43
|
const decodeIdToken = (token) => {
|
|
52
44
|
const { 1: encodedPayload } = token.split('.');
|
|
53
45
|
if (!encodedPayload) {
|
|
@@ -60,4 +52,3 @@ const decodeIdToken = (token) => {
|
|
|
60
52
|
};
|
|
61
53
|
|
|
62
54
|
exports.decodeIdToken = decodeIdToken;
|
|
63
|
-
exports.verifyIdToken = verifyIdToken;
|
package/lib/utils/id-token.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Nullable } from '@silverhand/essentials';
|
|
2
|
-
import type { JWTVerifyGetKey } from 'jose';
|
|
3
2
|
export type IdTokenClaims = {
|
|
4
3
|
/** Issuer of this token. */
|
|
5
4
|
iss: string;
|
|
@@ -42,5 +41,4 @@ export type IdTokenClaims = {
|
|
|
42
41
|
/** Roles that the user has for API resources. */
|
|
43
42
|
roles?: string[];
|
|
44
43
|
} & Record<string, unknown>;
|
|
45
|
-
export declare const verifyIdToken: (idToken: string, clientId: string, issuer: string, jwks: JWTVerifyGetKey) => Promise<void>;
|
|
46
44
|
export declare const decodeIdToken: (token: string) => IdTokenClaims;
|
package/lib/utils/id-token.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { urlSafeBase64 } from '@silverhand/essentials';
|
|
2
|
-
import { jwtVerify } from 'jose';
|
|
3
2
|
import { isArbitraryObject } from './arbitrary-object.js';
|
|
4
3
|
import { LogtoError } from './errors.js';
|
|
5
4
|
|
|
6
|
-
const issuedAtTimeTolerance = 300; // 5 minutes
|
|
7
5
|
/* eslint-disable complexity */
|
|
8
6
|
/**
|
|
9
7
|
* @link [ID Token](https://openid.net/specs/openid-connect-core-1_0.html#IDToken)
|
|
@@ -40,12 +38,6 @@ function assertIdTokenClaims(data) {
|
|
|
40
38
|
}
|
|
41
39
|
}
|
|
42
40
|
/* eslint-enable complexity */
|
|
43
|
-
const verifyIdToken = async (idToken, clientId, issuer, jwks) => {
|
|
44
|
-
const result = await jwtVerify(idToken, jwks, { audience: clientId, issuer });
|
|
45
|
-
if (Math.abs((result.payload.iat ?? 0) - Date.now() / 1000) > issuedAtTimeTolerance) {
|
|
46
|
-
throw new LogtoError('id_token.invalid_iat');
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
41
|
const decodeIdToken = (token) => {
|
|
50
42
|
const { 1: encodedPayload } = token.split('.');
|
|
51
43
|
if (!encodedPayload) {
|
|
@@ -57,4 +49,4 @@ const decodeIdToken = (token) => {
|
|
|
57
49
|
return idTokenClaims;
|
|
58
50
|
};
|
|
59
51
|
|
|
60
|
-
export { decodeIdToken
|
|
52
|
+
export { decodeIdToken };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./lib/index.cjs",
|
|
6
6
|
"module": "./lib/index.js",
|
|
@@ -21,8 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@silverhand/essentials": "^2.8.7",
|
|
24
|
-
"camelcase-keys": "^7.0.1"
|
|
25
|
-
"jose": "^5.0.0"
|
|
24
|
+
"camelcase-keys": "^7.0.1"
|
|
26
25
|
},
|
|
27
26
|
"devDependencies": {
|
|
28
27
|
"@silverhand/eslint-config": "^5.0.0",
|
|
@@ -35,6 +34,7 @@
|
|
|
35
34
|
"jest": "^29.5.0",
|
|
36
35
|
"jest-environment-jsdom": "^29.5.0",
|
|
37
36
|
"jest-matcher-specific-error": "^1.0.0",
|
|
37
|
+
"jose": "^5.0.0",
|
|
38
38
|
"lint-staged": "^15.0.0",
|
|
39
39
|
"nock": "^13.3.0",
|
|
40
40
|
"prettier": "^3.0.0",
|