@logto/js 4.1.1 → 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.
@@ -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
 
@@ -47,5 +47,11 @@ export type SignInUriParameters = {
47
47
  * by the authorization server.
48
48
  */
49
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;
50
56
  };
51
- 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;
@@ -1,5 +1,5 @@
1
1
  import { QueryKey, Prompt } from '../consts/index.js';
2
- import { withDefaultScopes } from '../utils/scopes.js';
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';
@@ -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.withDefaultScopes(scopes$1);
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,
@@ -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`
@@ -1,5 +1,5 @@
1
1
  import { Prompt } from '../consts/index.js';
2
- import { withDefaultScopes } from './scopes.js';
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 = withDefaultScopes(scopes);
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,
@@ -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 withDefaultScopes = (originalScopes) => {
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;
@@ -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;
@@ -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 withDefaultScopes = (originalScopes) => {
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.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
- "@peculiar/webcrypto": "^1.4.5",
28
- "@silverhand/eslint-config": "^5.0.0",
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.44.0",
36
- "jest": "^29.5.0",
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
- "text-encoder": "^0.0.4",
45
- "type-fest": "^4.0.0",
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": "jest",
62
- "test:coverage": "jest --silent --env=jsdom && jest --silent"
54
+ "test": "vitest",
55
+ "test:coverage": "vitest --silent --no-watch --environment=happy-dom && vitest --silent --coverage"
63
56
  }
64
57
  }