@logto/js 4.0.1 → 4.1.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/consts/index.cjs +2 -0
- package/lib/consts/index.d.ts +3 -1
- package/lib/consts/index.js +2 -0
- package/lib/core/sign-in.cjs +10 -3
- package/lib/core/sign-in.d.ts +38 -2
- package/lib/core/sign-in.js +10 -3
- package/lib/types/index.d.ts +7 -0
- package/package.json +1 -1
package/lib/consts/index.cjs
CHANGED
|
@@ -36,6 +36,8 @@ exports.QueryKey = void 0;
|
|
|
36
36
|
QueryKey["InteractionMode"] = "interaction_mode";
|
|
37
37
|
/** The query key for specifying the organization ID. */
|
|
38
38
|
QueryKey["OrganizationId"] = "organization_id";
|
|
39
|
+
QueryKey["FirstScreen"] = "first_screen";
|
|
40
|
+
QueryKey["DirectSignIn"] = "direct_sign_in";
|
|
39
41
|
})(exports.QueryKey || (exports.QueryKey = {}));
|
|
40
42
|
/** The prompt parameter to be used for the authorization request. */
|
|
41
43
|
exports.Prompt = void 0;
|
package/lib/consts/index.d.ts
CHANGED
|
@@ -31,7 +31,9 @@ export declare enum QueryKey {
|
|
|
31
31
|
Token = "token",
|
|
32
32
|
InteractionMode = "interaction_mode",
|
|
33
33
|
/** The query key for specifying the organization ID. */
|
|
34
|
-
OrganizationId = "organization_id"
|
|
34
|
+
OrganizationId = "organization_id",
|
|
35
|
+
FirstScreen = "first_screen",
|
|
36
|
+
DirectSignIn = "direct_sign_in"
|
|
35
37
|
}
|
|
36
38
|
/** The prompt parameter to be used for the authorization request. */
|
|
37
39
|
export declare enum Prompt {
|
package/lib/consts/index.js
CHANGED
|
@@ -34,6 +34,8 @@ var QueryKey;
|
|
|
34
34
|
QueryKey["InteractionMode"] = "interaction_mode";
|
|
35
35
|
/** The query key for specifying the organization ID. */
|
|
36
36
|
QueryKey["OrganizationId"] = "organization_id";
|
|
37
|
+
QueryKey["FirstScreen"] = "first_screen";
|
|
38
|
+
QueryKey["DirectSignIn"] = "direct_sign_in";
|
|
37
39
|
})(QueryKey || (QueryKey = {}));
|
|
38
40
|
/** The prompt parameter to be used for the authorization request. */
|
|
39
41
|
var Prompt;
|
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, interactionMode, loginHint, }) => {
|
|
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,15 +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
|
});
|
|
25
26
|
if (loginHint) {
|
|
26
27
|
urlSearchParameters.append(index.QueryKey.LoginHint, loginHint);
|
|
27
28
|
}
|
|
29
|
+
if (directSignIn) {
|
|
30
|
+
urlSearchParameters.append(index.QueryKey.DirectSignIn, `${directSignIn.method}:${directSignIn.target}`);
|
|
31
|
+
}
|
|
28
32
|
for (const resource of resources ?? []) {
|
|
29
33
|
urlSearchParameters.append(index.QueryKey.Resource, resource);
|
|
30
34
|
}
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
if (firstScreen) {
|
|
36
|
+
urlSearchParameters.append(index.QueryKey.FirstScreen, firstScreen);
|
|
37
|
+
}
|
|
38
|
+
// @deprecated Remove later
|
|
39
|
+
else if (interactionMode) {
|
|
33
40
|
urlSearchParameters.append(index.QueryKey.InteractionMode, interactionMode);
|
|
34
41
|
}
|
|
35
42
|
return `${authorizationEndpoint}?${urlSearchParameters.toString()}`;
|
package/lib/core/sign-in.d.ts
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
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
|
+
/** @experimental Don't use this type as it's under development. */
|
|
4
|
+
export type DirectSignInOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* The method to be used for the direct sign-in.
|
|
7
|
+
*/
|
|
8
|
+
method: 'social';
|
|
9
|
+
/**
|
|
10
|
+
* The target to be used for the direct sign-in.
|
|
11
|
+
*
|
|
12
|
+
* - For `method: 'social'`, it should be the social connector target.
|
|
13
|
+
*/
|
|
14
|
+
target: string;
|
|
15
|
+
};
|
|
3
16
|
export type SignInUriParameters = {
|
|
4
17
|
authorizationEndpoint: string;
|
|
5
18
|
clientId: string;
|
|
@@ -9,7 +22,30 @@ export type SignInUriParameters = {
|
|
|
9
22
|
scopes?: string[];
|
|
10
23
|
resources?: string[];
|
|
11
24
|
prompt?: Prompt | Prompt[];
|
|
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
|
+
*/
|
|
30
|
+
firstScreen?: FirstScreen;
|
|
31
|
+
/** The first screen to be shown in the sign-in experience. */
|
|
12
32
|
interactionMode?: InteractionMode;
|
|
33
|
+
/**
|
|
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.
|
|
37
|
+
*/
|
|
13
38
|
loginHint?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Parameters for direct sign-in.
|
|
41
|
+
*
|
|
42
|
+
* @experimental Don't use this field as it's under development.
|
|
43
|
+
*/
|
|
44
|
+
directSignIn?: DirectSignInOptions;
|
|
45
|
+
/**
|
|
46
|
+
* Extra parameters for the authentication request. Note that the parameters should be supported
|
|
47
|
+
* by the authorization server.
|
|
48
|
+
*/
|
|
49
|
+
extraParams?: Record<string, string>;
|
|
14
50
|
};
|
|
15
|
-
export declare const generateSignInUri: ({ authorizationEndpoint, clientId, redirectUri, codeChallenge, state, scopes, resources, prompt, interactionMode, loginHint, }: SignInUriParameters) => string;
|
|
51
|
+
export declare const generateSignInUri: ({ authorizationEndpoint, clientId, redirectUri, codeChallenge, state, scopes, resources, prompt, firstScreen, interactionMode, loginHint, directSignIn, extraParams, }: SignInUriParameters) => string;
|
package/lib/core/sign-in.js
CHANGED
|
@@ -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, loginHint, }) => {
|
|
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,15 +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
|
});
|
|
23
24
|
if (loginHint) {
|
|
24
25
|
urlSearchParameters.append(QueryKey.LoginHint, loginHint);
|
|
25
26
|
}
|
|
27
|
+
if (directSignIn) {
|
|
28
|
+
urlSearchParameters.append(QueryKey.DirectSignIn, `${directSignIn.method}:${directSignIn.target}`);
|
|
29
|
+
}
|
|
26
30
|
for (const resource of resources ?? []) {
|
|
27
31
|
urlSearchParameters.append(QueryKey.Resource, resource);
|
|
28
32
|
}
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
if (firstScreen) {
|
|
34
|
+
urlSearchParameters.append(QueryKey.FirstScreen, firstScreen);
|
|
35
|
+
}
|
|
36
|
+
// @deprecated Remove later
|
|
37
|
+
else if (interactionMode) {
|
|
31
38
|
urlSearchParameters.append(QueryKey.InteractionMode, interactionMode);
|
|
32
39
|
}
|
|
33
40
|
return `${authorizationEndpoint}?${urlSearchParameters.toString()}`;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -15,3 +15,10 @@ export type Requester = <T>(...args: Parameters<typeof fetch>) => Promise<T>;
|
|
|
15
15
|
* - `signUp`: The authorization request will be initiated with a sign-up page.
|
|
16
16
|
*/
|
|
17
17
|
export type InteractionMode = 'signIn' | 'signUp';
|
|
18
|
+
/**
|
|
19
|
+
* The first screen to be shown in the sign-in experience. Note it's not a part of the OIDC
|
|
20
|
+
* standard, but a Logto-specific extension.
|
|
21
|
+
*
|
|
22
|
+
* @experimental Don't use this type as it's under development.
|
|
23
|
+
*/
|
|
24
|
+
export type FirstScreen = 'signIn' | 'register';
|