@logto/js 4.1.0 → 4.1.2
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/sign-in.cjs +10 -3
- package/lib/core/sign-in.d.ts +22 -7
- package/lib/core/sign-in.js +11 -4
- package/lib/index.cjs +1 -0
- package/lib/index.js +1 -1
- package/lib/types/index.d.ts +2 -2
- package/lib/utils/angular.cjs +2 -2
- package/lib/utils/angular.d.ts +6 -0
- package/lib/utils/angular.js +3 -3
- package/lib/utils/scopes.cjs +8 -1
- package/lib/utils/scopes.d.ts +6 -0
- package/lib/utils/scopes.js +8 -2
- package/package.json +10 -17
package/lib/core/sign-in.cjs
CHANGED
|
@@ -11,7 +11,7 @@ const buildPrompt = (prompt) => {
|
|
|
11
11
|
}
|
|
12
12
|
return prompt ?? index.Prompt.Consent;
|
|
13
13
|
};
|
|
14
|
-
const generateSignInUri = ({ authorizationEndpoint, clientId, redirectUri, codeChallenge, state, scopes: scopes$1, resources, prompt, firstScreen, interactionMode, loginHint, directSignIn, extraParams, }) => {
|
|
14
|
+
const generateSignInUri = ({ authorizationEndpoint, clientId, redirectUri, codeChallenge, state, scopes: scopes$1, resources, prompt, firstScreen, interactionMode, loginHint, directSignIn, extraParams, includeReservedScopes = true, }) => {
|
|
15
15
|
const urlSearchParameters = new URLSearchParams({
|
|
16
16
|
[index.QueryKey.ClientId]: clientId,
|
|
17
17
|
[index.QueryKey.RedirectUri]: redirectUri,
|
|
@@ -20,9 +20,11 @@ const generateSignInUri = ({ authorizationEndpoint, clientId, redirectUri, codeC
|
|
|
20
20
|
[index.QueryKey.State]: state,
|
|
21
21
|
[index.QueryKey.ResponseType]: responseType,
|
|
22
22
|
[index.QueryKey.Prompt]: buildPrompt(prompt),
|
|
23
|
-
[index.QueryKey.Scope]: scopes.withDefaultScopes(scopes$1),
|
|
24
|
-
...extraParams,
|
|
25
23
|
});
|
|
24
|
+
const computedScopes = includeReservedScopes ? scopes.withReservedScopes(scopes$1) : scopes$1?.join(' ');
|
|
25
|
+
if (computedScopes) {
|
|
26
|
+
urlSearchParameters.append(index.QueryKey.Scope, computedScopes);
|
|
27
|
+
}
|
|
26
28
|
if (loginHint) {
|
|
27
29
|
urlSearchParameters.append(index.QueryKey.LoginHint, loginHint);
|
|
28
30
|
}
|
|
@@ -39,6 +41,11 @@ const generateSignInUri = ({ authorizationEndpoint, clientId, redirectUri, codeC
|
|
|
39
41
|
else if (interactionMode) {
|
|
40
42
|
urlSearchParameters.append(index.QueryKey.InteractionMode, interactionMode);
|
|
41
43
|
}
|
|
44
|
+
if (extraParams) {
|
|
45
|
+
for (const [key, value] of Object.entries(extraParams)) {
|
|
46
|
+
urlSearchParameters.append(key, value);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
42
49
|
return `${authorizationEndpoint}?${urlSearchParameters.toString()}`;
|
|
43
50
|
};
|
|
44
51
|
|
package/lib/core/sign-in.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { Prompt } from '../consts/index.js';
|
|
2
2
|
import type { FirstScreen, InteractionMode } from '../types/index.js';
|
|
3
|
+
/** @experimental Don't use this type as it's under development. */
|
|
3
4
|
export type DirectSignInOptions = {
|
|
4
5
|
/**
|
|
5
6
|
* The method to be used for the direct sign-in.
|
|
6
7
|
*/
|
|
7
|
-
method: 'social'
|
|
8
|
+
method: 'social';
|
|
8
9
|
/**
|
|
9
10
|
* The target to be used for the direct sign-in.
|
|
10
11
|
*
|
|
11
12
|
* - For `method: 'social'`, it should be the social connector target.
|
|
12
|
-
* - For `method: 'email'`, it should be the email address.
|
|
13
|
-
* - For `method: 'sms'`, it should be the phone number.
|
|
14
13
|
*/
|
|
15
14
|
target: string;
|
|
16
15
|
};
|
|
@@ -23,20 +22,36 @@ export type SignInUriParameters = {
|
|
|
23
22
|
scopes?: string[];
|
|
24
23
|
resources?: string[];
|
|
25
24
|
prompt?: Prompt | Prompt[];
|
|
26
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* The first screen to be shown in the sign-in experience.
|
|
27
|
+
*
|
|
28
|
+
* @experimental Don't use this field as it's under development.
|
|
29
|
+
*/
|
|
27
30
|
firstScreen?: FirstScreen;
|
|
28
|
-
/**
|
|
31
|
+
/** The first screen to be shown in the sign-in experience. */
|
|
29
32
|
interactionMode?: InteractionMode;
|
|
30
33
|
/**
|
|
31
34
|
* Login hint indicates the current user (usually an email address or a phone number).
|
|
35
|
+
*
|
|
36
|
+
* @experimental Don't use this field as it's under development.
|
|
32
37
|
*/
|
|
33
38
|
loginHint?: string;
|
|
34
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Parameters for direct sign-in.
|
|
41
|
+
*
|
|
42
|
+
* @experimental Don't use this field as it's under development.
|
|
43
|
+
*/
|
|
35
44
|
directSignIn?: DirectSignInOptions;
|
|
36
45
|
/**
|
|
37
46
|
* Extra parameters for the authentication request. Note that the parameters should be supported
|
|
38
47
|
* by the authorization server.
|
|
39
48
|
*/
|
|
40
49
|
extraParams?: Record<string, string>;
|
|
50
|
+
/**
|
|
51
|
+
* Whether to include reserved scopes (`openid`, `offline_access` and `profile`) in the scopes.
|
|
52
|
+
*
|
|
53
|
+
* @default true
|
|
54
|
+
*/
|
|
55
|
+
includeReservedScopes?: boolean;
|
|
41
56
|
};
|
|
42
|
-
export declare const generateSignInUri: ({ authorizationEndpoint, clientId, redirectUri, codeChallenge, state, scopes, resources, prompt, firstScreen, interactionMode, loginHint, directSignIn, extraParams, }: SignInUriParameters) => string;
|
|
57
|
+
export declare const generateSignInUri: ({ authorizationEndpoint, clientId, redirectUri, codeChallenge, state, scopes, resources, prompt, firstScreen, interactionMode, loginHint, directSignIn, extraParams, includeReservedScopes, }: SignInUriParameters) => string;
|
package/lib/core/sign-in.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { QueryKey, Prompt } from '../consts/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import { withReservedScopes } from '../utils/scopes.js';
|
|
3
3
|
|
|
4
4
|
const codeChallengeMethod = 'S256';
|
|
5
5
|
const responseType = 'code';
|
|
@@ -9,7 +9,7 @@ const buildPrompt = (prompt) => {
|
|
|
9
9
|
}
|
|
10
10
|
return prompt ?? Prompt.Consent;
|
|
11
11
|
};
|
|
12
|
-
const generateSignInUri = ({ authorizationEndpoint, clientId, redirectUri, codeChallenge, state, scopes, resources, prompt, firstScreen, interactionMode, loginHint, directSignIn, extraParams, }) => {
|
|
12
|
+
const generateSignInUri = ({ authorizationEndpoint, clientId, redirectUri, codeChallenge, state, scopes, resources, prompt, firstScreen, interactionMode, loginHint, directSignIn, extraParams, includeReservedScopes = true, }) => {
|
|
13
13
|
const urlSearchParameters = new URLSearchParams({
|
|
14
14
|
[QueryKey.ClientId]: clientId,
|
|
15
15
|
[QueryKey.RedirectUri]: redirectUri,
|
|
@@ -18,9 +18,11 @@ const generateSignInUri = ({ authorizationEndpoint, clientId, redirectUri, codeC
|
|
|
18
18
|
[QueryKey.State]: state,
|
|
19
19
|
[QueryKey.ResponseType]: responseType,
|
|
20
20
|
[QueryKey.Prompt]: buildPrompt(prompt),
|
|
21
|
-
[QueryKey.Scope]: withDefaultScopes(scopes),
|
|
22
|
-
...extraParams,
|
|
23
21
|
});
|
|
22
|
+
const computedScopes = includeReservedScopes ? withReservedScopes(scopes) : scopes?.join(' ');
|
|
23
|
+
if (computedScopes) {
|
|
24
|
+
urlSearchParameters.append(QueryKey.Scope, computedScopes);
|
|
25
|
+
}
|
|
24
26
|
if (loginHint) {
|
|
25
27
|
urlSearchParameters.append(QueryKey.LoginHint, loginHint);
|
|
26
28
|
}
|
|
@@ -37,6 +39,11 @@ const generateSignInUri = ({ authorizationEndpoint, clientId, redirectUri, codeC
|
|
|
37
39
|
else if (interactionMode) {
|
|
38
40
|
urlSearchParameters.append(QueryKey.InteractionMode, interactionMode);
|
|
39
41
|
}
|
|
42
|
+
if (extraParams) {
|
|
43
|
+
for (const [key, value] of Object.entries(extraParams)) {
|
|
44
|
+
urlSearchParameters.append(key, value);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
40
47
|
return `${authorizationEndpoint}?${urlSearchParameters.toString()}`;
|
|
41
48
|
};
|
|
42
49
|
|
package/lib/index.cjs
CHANGED
|
@@ -35,6 +35,7 @@ exports.isLogtoRequestError = errors.isLogtoRequestError;
|
|
|
35
35
|
exports.decodeIdToken = idToken.decodeIdToken;
|
|
36
36
|
exports.decodeAccessToken = accessToken.decodeAccessToken;
|
|
37
37
|
exports.withDefaultScopes = scopes.withDefaultScopes;
|
|
38
|
+
exports.withReservedScopes = scopes.withReservedScopes;
|
|
38
39
|
exports.isArbitraryObject = arbitraryObject.isArbitraryObject;
|
|
39
40
|
exports.buildAngularAuthConfig = angular.buildAngularAuthConfig;
|
|
40
41
|
exports.ContentType = index.ContentType;
|
package/lib/index.js
CHANGED
|
@@ -8,7 +8,7 @@ export { parseUriParameters, verifyAndParseCodeFromCallbackUri } from './utils/c
|
|
|
8
8
|
export { LogtoError, LogtoRequestError, OidcError, isLogtoRequestError } from './utils/errors.js';
|
|
9
9
|
export { decodeIdToken } from './utils/id-token.js';
|
|
10
10
|
export { decodeAccessToken } from './utils/access-token.js';
|
|
11
|
-
export { withDefaultScopes } from './utils/scopes.js';
|
|
11
|
+
export { withDefaultScopes, withReservedScopes } from './utils/scopes.js';
|
|
12
12
|
export { isArbitraryObject } from './utils/arbitrary-object.js';
|
|
13
13
|
export { buildAngularAuthConfig } from './utils/angular.js';
|
|
14
14
|
export { ContentType, Prompt, QueryKey, TokenGrantType } from './consts/index.js';
|
package/lib/types/index.d.ts
CHANGED
|
@@ -13,12 +13,12 @@ export type Requester = <T>(...args: Parameters<typeof fetch>) => Promise<T>;
|
|
|
13
13
|
*
|
|
14
14
|
* - `signIn`: The authorization request will be initiated with a sign-in page.
|
|
15
15
|
* - `signUp`: The authorization request will be initiated with a sign-up page.
|
|
16
|
-
*
|
|
17
|
-
* @deprecated Use {@link FirstScreen} instead.
|
|
18
16
|
*/
|
|
19
17
|
export type InteractionMode = 'signIn' | 'signUp';
|
|
20
18
|
/**
|
|
21
19
|
* The first screen to be shown in the sign-in experience. Note it's not a part of the OIDC
|
|
22
20
|
* standard, but a Logto-specific extension.
|
|
21
|
+
*
|
|
22
|
+
* @experimental Don't use this type as it's under development.
|
|
23
23
|
*/
|
|
24
24
|
export type FirstScreen = 'signIn' | 'register';
|
package/lib/utils/angular.cjs
CHANGED
|
@@ -28,8 +28,8 @@ var scopes = require('./scopes.cjs');
|
|
|
28
28
|
* about how to use the library.
|
|
29
29
|
*/
|
|
30
30
|
const buildAngularAuthConfig = (logtoConfig) => {
|
|
31
|
-
const { endpoint, appId: clientId, scopes: scopes$1, resource, redirectUri: redirectUrl, postLogoutRedirectUri, prompt = index.Prompt.Consent, } = logtoConfig;
|
|
32
|
-
const scope = scopes.
|
|
31
|
+
const { endpoint, appId: clientId, scopes: scopes$1, resource, redirectUri: redirectUrl, postLogoutRedirectUri, prompt = index.Prompt.Consent, includeReservedScopes = true, } = logtoConfig;
|
|
32
|
+
const scope = includeReservedScopes ? scopes.withReservedScopes(scopes$1) : scopes$1?.join(' ');
|
|
33
33
|
const customParameters = resource ? { resource } : undefined;
|
|
34
34
|
return {
|
|
35
35
|
authority: new URL('/oidc', endpoint).href,
|
package/lib/utils/angular.d.ts
CHANGED
|
@@ -42,6 +42,12 @@ export type LogtoAngularConfig = {
|
|
|
42
42
|
* @default Prompt.Consent
|
|
43
43
|
*/
|
|
44
44
|
prompt?: Prompt | Prompt[];
|
|
45
|
+
/**
|
|
46
|
+
* Whether to include reserved scopes (`openid`, `offline_access` and `profile`) in the scopes.
|
|
47
|
+
*
|
|
48
|
+
* @default true
|
|
49
|
+
*/
|
|
50
|
+
includeReservedScopes?: boolean;
|
|
45
51
|
};
|
|
46
52
|
/**
|
|
47
53
|
* A helper function to build the OpenID Connect configuration for `angular-auth-oidc-client`
|
package/lib/utils/angular.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Prompt } from '../consts/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import { withReservedScopes } from './scopes.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* A helper function to build the OpenID Connect configuration for `angular-auth-oidc-client`
|
|
@@ -26,8 +26,8 @@ import { withDefaultScopes } from './scopes.js';
|
|
|
26
26
|
* about how to use the library.
|
|
27
27
|
*/
|
|
28
28
|
const buildAngularAuthConfig = (logtoConfig) => {
|
|
29
|
-
const { endpoint, appId: clientId, scopes, resource, redirectUri: redirectUrl, postLogoutRedirectUri, prompt = Prompt.Consent, } = logtoConfig;
|
|
30
|
-
const scope =
|
|
29
|
+
const { endpoint, appId: clientId, scopes, resource, redirectUri: redirectUrl, postLogoutRedirectUri, prompt = Prompt.Consent, includeReservedScopes = true, } = logtoConfig;
|
|
30
|
+
const scope = includeReservedScopes ? withReservedScopes(scopes) : scopes?.join(' ');
|
|
31
31
|
const customParameters = resource ? { resource } : undefined;
|
|
32
32
|
return {
|
|
33
33
|
authority: new URL('/oidc', endpoint).href,
|
package/lib/utils/scopes.cjs
CHANGED
|
@@ -7,10 +7,17 @@ var openid = require('../consts/openid.cjs');
|
|
|
7
7
|
* @param originalScopes
|
|
8
8
|
* @return scopes should contain all default scopes (`openid`, `offline_access` and `profile`)
|
|
9
9
|
*/
|
|
10
|
-
const
|
|
10
|
+
const withReservedScopes = (originalScopes) => {
|
|
11
11
|
const reservedScopes = Object.values(openid.ReservedScope);
|
|
12
12
|
const uniqueScopes = new Set([...reservedScopes, openid.UserScope.Profile, ...(originalScopes ?? [])]);
|
|
13
13
|
return Array.from(uniqueScopes).join(' ');
|
|
14
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Alias of {@link withReservedScopes}.
|
|
17
|
+
*
|
|
18
|
+
* @deprecated Use {@link withReservedScopes} instead.
|
|
19
|
+
*/
|
|
20
|
+
const withDefaultScopes = withReservedScopes;
|
|
15
21
|
|
|
16
22
|
exports.withDefaultScopes = withDefaultScopes;
|
|
23
|
+
exports.withReservedScopes = withReservedScopes;
|
package/lib/utils/scopes.d.ts
CHANGED
|
@@ -2,4 +2,10 @@
|
|
|
2
2
|
* @param originalScopes
|
|
3
3
|
* @return scopes should contain all default scopes (`openid`, `offline_access` and `profile`)
|
|
4
4
|
*/
|
|
5
|
+
export declare const withReservedScopes: (originalScopes?: string[]) => string;
|
|
6
|
+
/**
|
|
7
|
+
* Alias of {@link withReservedScopes}.
|
|
8
|
+
*
|
|
9
|
+
* @deprecated Use {@link withReservedScopes} instead.
|
|
10
|
+
*/
|
|
5
11
|
export declare const withDefaultScopes: (originalScopes?: string[]) => string;
|
package/lib/utils/scopes.js
CHANGED
|
@@ -5,10 +5,16 @@ import { ReservedScope, UserScope } from '../consts/openid.js';
|
|
|
5
5
|
* @param originalScopes
|
|
6
6
|
* @return scopes should contain all default scopes (`openid`, `offline_access` and `profile`)
|
|
7
7
|
*/
|
|
8
|
-
const
|
|
8
|
+
const withReservedScopes = (originalScopes) => {
|
|
9
9
|
const reservedScopes = Object.values(ReservedScope);
|
|
10
10
|
const uniqueScopes = new Set([...reservedScopes, UserScope.Profile, ...(originalScopes ?? [])]);
|
|
11
11
|
return Array.from(uniqueScopes).join(' ');
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Alias of {@link withReservedScopes}.
|
|
15
|
+
*
|
|
16
|
+
* @deprecated Use {@link withReservedScopes} instead.
|
|
17
|
+
*/
|
|
18
|
+
const withDefaultScopes = withReservedScopes;
|
|
13
19
|
|
|
14
|
-
export { withDefaultScopes };
|
|
20
|
+
export { withDefaultScopes, withReservedScopes };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/js",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./lib/index.cjs",
|
|
6
6
|
"module": "./lib/index.js",
|
|
@@ -24,26 +24,19 @@
|
|
|
24
24
|
"camelcase-keys": "^7.0.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@
|
|
28
|
-
"@silverhand/
|
|
29
|
-
"@silverhand/ts-config": "^5.0.0",
|
|
30
|
-
"@swc/core": "^1.3.50",
|
|
31
|
-
"@swc/jest": "^0.2.24",
|
|
32
|
-
"@types/jest": "^29.5.1",
|
|
27
|
+
"@silverhand/eslint-config": "^6.0.1",
|
|
28
|
+
"@silverhand/ts-config": "^6.0.0",
|
|
33
29
|
"@types/node": "^20.11.19",
|
|
30
|
+
"@vitest/coverage-v8": "^1.4.0",
|
|
34
31
|
"angular-auth-oidc-client": "^17.0.0",
|
|
35
|
-
"eslint": "^8.
|
|
36
|
-
"
|
|
37
|
-
"jest-environment-jsdom": "^29.5.0",
|
|
38
|
-
"jest-matcher-specific-error": "^1.0.0",
|
|
32
|
+
"eslint": "^8.57.0",
|
|
33
|
+
"happy-dom": "^14.0.0",
|
|
39
34
|
"jose": "^5.2.2",
|
|
40
35
|
"lint-staged": "^15.0.0",
|
|
41
|
-
"nock": "^13.3.0",
|
|
42
36
|
"prettier": "^3.0.0",
|
|
43
37
|
"rollup": "^4.0.0",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"typescript": "^5.3.3"
|
|
38
|
+
"typescript": "^5.3.3",
|
|
39
|
+
"vitest": "^1.4.0"
|
|
47
40
|
},
|
|
48
41
|
"eslintConfig": {
|
|
49
42
|
"extends": "@silverhand"
|
|
@@ -58,7 +51,7 @@
|
|
|
58
51
|
"check": "tsc --noEmit",
|
|
59
52
|
"build": "rm -rf lib/ && tsc -p tsconfig.build.json --noEmit && rollup -c",
|
|
60
53
|
"lint": "eslint --ext .ts src",
|
|
61
|
-
"test": "
|
|
62
|
-
"test:coverage": "
|
|
54
|
+
"test": "vitest",
|
|
55
|
+
"test:coverage": "vitest --silent --no-watch --environment=happy-dom && vitest --silent --coverage"
|
|
63
56
|
}
|
|
64
57
|
}
|