@logto/js 4.0.0 → 4.1.0

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.
@@ -22,6 +22,7 @@ exports.QueryKey = void 0;
22
22
  QueryKey["GrantType"] = "grant_type";
23
23
  QueryKey["IdToken"] = "id_token";
24
24
  QueryKey["IdTokenHint"] = "id_token_hint";
25
+ QueryKey["LoginHint"] = "login_hint";
25
26
  QueryKey["PostLogoutRedirectUri"] = "post_logout_redirect_uri";
26
27
  QueryKey["Prompt"] = "prompt";
27
28
  QueryKey["RedirectUri"] = "redirect_uri";
@@ -35,6 +36,8 @@ exports.QueryKey = void 0;
35
36
  QueryKey["InteractionMode"] = "interaction_mode";
36
37
  /** The query key for specifying the organization ID. */
37
38
  QueryKey["OrganizationId"] = "organization_id";
39
+ QueryKey["FirstScreen"] = "first_screen";
40
+ QueryKey["DirectSignIn"] = "direct_sign_in";
38
41
  })(exports.QueryKey || (exports.QueryKey = {}));
39
42
  /** The prompt parameter to be used for the authorization request. */
40
43
  exports.Prompt = void 0;
@@ -19,6 +19,7 @@ export declare enum QueryKey {
19
19
  GrantType = "grant_type",
20
20
  IdToken = "id_token",
21
21
  IdTokenHint = "id_token_hint",
22
+ LoginHint = "login_hint",
22
23
  PostLogoutRedirectUri = "post_logout_redirect_uri",
23
24
  Prompt = "prompt",
24
25
  RedirectUri = "redirect_uri",
@@ -30,7 +31,9 @@ export declare enum QueryKey {
30
31
  Token = "token",
31
32
  InteractionMode = "interaction_mode",
32
33
  /** The query key for specifying the organization ID. */
33
- OrganizationId = "organization_id"
34
+ OrganizationId = "organization_id",
35
+ FirstScreen = "first_screen",
36
+ DirectSignIn = "direct_sign_in"
34
37
  }
35
38
  /** The prompt parameter to be used for the authorization request. */
36
39
  export declare enum Prompt {
@@ -20,6 +20,7 @@ var QueryKey;
20
20
  QueryKey["GrantType"] = "grant_type";
21
21
  QueryKey["IdToken"] = "id_token";
22
22
  QueryKey["IdTokenHint"] = "id_token_hint";
23
+ QueryKey["LoginHint"] = "login_hint";
23
24
  QueryKey["PostLogoutRedirectUri"] = "post_logout_redirect_uri";
24
25
  QueryKey["Prompt"] = "prompt";
25
26
  QueryKey["RedirectUri"] = "redirect_uri";
@@ -33,6 +34,8 @@ var QueryKey;
33
34
  QueryKey["InteractionMode"] = "interaction_mode";
34
35
  /** The query key for specifying the organization ID. */
35
36
  QueryKey["OrganizationId"] = "organization_id";
37
+ QueryKey["FirstScreen"] = "first_screen";
38
+ QueryKey["DirectSignIn"] = "direct_sign_in";
36
39
  })(QueryKey || (QueryKey = {}));
37
40
  /** The prompt parameter to be used for the authorization request. */
38
41
  var Prompt;
@@ -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, interactionMode, }) => {
14
+ const generateSignInUri = ({ authorizationEndpoint, clientId, redirectUri, codeChallenge, state, scopes: scopes$1, resources, prompt, firstScreen, interactionMode, loginHint, directSignIn, extraParams, }) => {
15
15
  const urlSearchParameters = new URLSearchParams({
16
16
  [index.QueryKey.ClientId]: clientId,
17
17
  [index.QueryKey.RedirectUri]: redirectUri,
@@ -21,12 +21,22 @@ const generateSignInUri = ({ authorizationEndpoint, clientId, redirectUri, codeC
21
21
  [index.QueryKey.ResponseType]: responseType,
22
22
  [index.QueryKey.Prompt]: buildPrompt(prompt),
23
23
  [index.QueryKey.Scope]: scopes.withDefaultScopes(scopes$1),
24
+ ...extraParams,
24
25
  });
26
+ if (loginHint) {
27
+ urlSearchParameters.append(index.QueryKey.LoginHint, loginHint);
28
+ }
29
+ if (directSignIn) {
30
+ urlSearchParameters.append(index.QueryKey.DirectSignIn, `${directSignIn.method}:${directSignIn.target}`);
31
+ }
25
32
  for (const resource of resources ?? []) {
26
33
  urlSearchParameters.append(index.QueryKey.Resource, resource);
27
34
  }
28
- // Set interactionMode to signUp for a create account user experience
29
- if (interactionMode) {
35
+ if (firstScreen) {
36
+ urlSearchParameters.append(index.QueryKey.FirstScreen, firstScreen);
37
+ }
38
+ // @deprecated Remove later
39
+ else if (interactionMode) {
30
40
  urlSearchParameters.append(index.QueryKey.InteractionMode, interactionMode);
31
41
  }
32
42
  return `${authorizationEndpoint}?${urlSearchParameters.toString()}`;
@@ -1,5 +1,19 @@
1
1
  import { Prompt } from '../consts/index.js';
2
- import type { InteractionMode } from '../types/index.js';
2
+ import type { FirstScreen, InteractionMode } from '../types/index.js';
3
+ export type DirectSignInOptions = {
4
+ /**
5
+ * The method to be used for the direct sign-in.
6
+ */
7
+ method: 'social' | 'email' | 'sms';
8
+ /**
9
+ * The target to be used for the direct sign-in.
10
+ *
11
+ * - 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
+ */
15
+ target: string;
16
+ };
3
17
  export type SignInUriParameters = {
4
18
  authorizationEndpoint: string;
5
19
  clientId: string;
@@ -9,6 +23,20 @@ export type SignInUriParameters = {
9
23
  scopes?: string[];
10
24
  resources?: string[];
11
25
  prompt?: Prompt | Prompt[];
26
+ /** The first screen to be shown in the sign-in experience. */
27
+ firstScreen?: FirstScreen;
28
+ /** @deprecated Use `firstScreen` instead. */
12
29
  interactionMode?: InteractionMode;
30
+ /**
31
+ * Login hint indicates the current user (usually an email address or a phone number).
32
+ */
33
+ loginHint?: string;
34
+ /** Parameters for direct sign-in. */
35
+ directSignIn?: DirectSignInOptions;
36
+ /**
37
+ * Extra parameters for the authentication request. Note that the parameters should be supported
38
+ * by the authorization server.
39
+ */
40
+ extraParams?: Record<string, string>;
13
41
  };
14
- export declare const generateSignInUri: ({ authorizationEndpoint, clientId, redirectUri, codeChallenge, state, scopes, resources, prompt, interactionMode, }: SignInUriParameters) => string;
42
+ export declare const generateSignInUri: ({ authorizationEndpoint, clientId, redirectUri, codeChallenge, state, scopes, resources, prompt, firstScreen, interactionMode, loginHint, directSignIn, extraParams, }: SignInUriParameters) => string;
@@ -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, interactionMode, }) => {
12
+ const generateSignInUri = ({ authorizationEndpoint, clientId, redirectUri, codeChallenge, state, scopes, resources, prompt, firstScreen, interactionMode, loginHint, directSignIn, extraParams, }) => {
13
13
  const urlSearchParameters = new URLSearchParams({
14
14
  [QueryKey.ClientId]: clientId,
15
15
  [QueryKey.RedirectUri]: redirectUri,
@@ -19,12 +19,22 @@ const generateSignInUri = ({ authorizationEndpoint, clientId, redirectUri, codeC
19
19
  [QueryKey.ResponseType]: responseType,
20
20
  [QueryKey.Prompt]: buildPrompt(prompt),
21
21
  [QueryKey.Scope]: withDefaultScopes(scopes),
22
+ ...extraParams,
22
23
  });
24
+ if (loginHint) {
25
+ urlSearchParameters.append(QueryKey.LoginHint, loginHint);
26
+ }
27
+ if (directSignIn) {
28
+ urlSearchParameters.append(QueryKey.DirectSignIn, `${directSignIn.method}:${directSignIn.target}`);
29
+ }
23
30
  for (const resource of resources ?? []) {
24
31
  urlSearchParameters.append(QueryKey.Resource, resource);
25
32
  }
26
- // Set interactionMode to signUp for a create account user experience
27
- if (interactionMode) {
33
+ if (firstScreen) {
34
+ urlSearchParameters.append(QueryKey.FirstScreen, firstScreen);
35
+ }
36
+ // @deprecated Remove later
37
+ else if (interactionMode) {
28
38
  urlSearchParameters.append(QueryKey.InteractionMode, interactionMode);
29
39
  }
30
40
  return `${authorizationEndpoint}?${urlSearchParameters.toString()}`;
@@ -13,5 +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.
16
18
  */
17
19
  export type InteractionMode = 'signIn' | 'signUp';
20
+ /**
21
+ * The first screen to be shown in the sign-in experience. Note it's not a part of the OIDC
22
+ * standard, but a Logto-specific extension.
23
+ */
24
+ export type FirstScreen = 'signIn' | 'register';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/js",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "type": "module",
5
5
  "main": "./lib/index.cjs",
6
6
  "module": "./lib/index.js",