@logto/capacitor 1.1.2 → 1.1.3
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/index.cjs +4 -32
- package/lib/index.d.ts +6 -2
- package/lib/index.js +4 -32
- package/package.json +2 -2
package/lib/index.cjs
CHANGED
|
@@ -44,38 +44,10 @@ class CapacitorLogtoClient extends LogtoBaseClient__default.default {
|
|
|
44
44
|
},
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Start the sign-in flow with the specified redirect URI. The URI must be
|
|
49
|
-
* registered in the Logto Console.
|
|
50
|
-
*
|
|
51
|
-
* Remember to configure the correct [scheme or universal links](https://capacitorjs.com/docs/guides/deep-links)
|
|
52
|
-
* to ensure the app can be opened from the redirect URI.
|
|
53
|
-
*
|
|
54
|
-
* @param redirectUri The redirect URI that the user will be redirected to after the sign-in flow is completed.
|
|
55
|
-
* @param interactionMode The interaction mode to be used for the authorization request. Note it's not
|
|
56
|
-
* a part of the OIDC standard, but a Logto-specific extension. Defaults to `signIn`.
|
|
57
|
-
* @throws {@link LogtoClientError} If error happens during the sign-in flow or the user cancels the sign-in.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```ts
|
|
61
|
-
* const client = new CapacitorLogtoClient({
|
|
62
|
-
* endpoint: 'https://your.logto.endpoint',
|
|
63
|
-
* appId: 'your-app-id',
|
|
64
|
-
* });
|
|
65
|
-
*
|
|
66
|
-
* await client.signIn('io.logto.example://callback'); // throws if error happens
|
|
67
|
-
* console.log(await client.getIdTokenClaims()); // { sub: '123', ... }
|
|
68
|
-
* ```
|
|
69
|
-
*
|
|
70
|
-
* @remarks
|
|
71
|
-
* The user will be redirected to that URI after the sign-in flow is completed,
|
|
72
|
-
* and the client will be able to get the authorization code from the URI.
|
|
73
|
-
* {@link handleSignInCallback} will be called after the user is redirected.
|
|
74
|
-
*
|
|
75
|
-
* @see {@link https://docs.logto.io/docs/recipes/integrate-logto/vanilla-js/#sign-in | Sign in} for more information.
|
|
76
|
-
* @see {@link InteractionMode}
|
|
77
|
-
*/
|
|
78
47
|
async signIn(redirectUri, interactionMode) {
|
|
48
|
+
if (typeof redirectUri === 'object' && !(redirectUri instanceof URL)) {
|
|
49
|
+
throw new TypeError('The first argument must be a string or a URL.');
|
|
50
|
+
}
|
|
79
51
|
return new Promise((resolve, reject) => {
|
|
80
52
|
const run = async () => {
|
|
81
53
|
const [browserHandle, appHandle] = await Promise.all([
|
|
@@ -87,7 +59,7 @@ class CapacitorLogtoClient extends LogtoBaseClient__default.default {
|
|
|
87
59
|
// Handle the case where the user completes the sign-in and is redirected
|
|
88
60
|
// back to the app.
|
|
89
61
|
app.App.addListener('appUrlOpen', async ({ url }) => {
|
|
90
|
-
if (!url.startsWith(redirectUri)) {
|
|
62
|
+
if (!url.startsWith(redirectUri.toString())) {
|
|
91
63
|
return;
|
|
92
64
|
}
|
|
93
65
|
await Promise.all([
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type OpenOptions } from '@capacitor/browser';
|
|
2
|
-
import LogtoBaseClient, { type InteractionMode, type LogtoConfig } from '@logto/browser';
|
|
2
|
+
import LogtoBaseClient, { type InteractionMode, type LogtoConfig, type SignInOptions } from '@logto/browser';
|
|
3
3
|
export { LogtoError, LogtoRequestError, LogtoClientError, OidcError, Prompt, ReservedScope, ReservedResource, UserScope, organizationUrnPrefix, buildOrganizationUrn, getOrganizationIdFromUrn, PersistKey, } from '@logto/browser';
|
|
4
4
|
export type CapacitorConfig = {
|
|
5
5
|
/**
|
|
@@ -10,6 +10,10 @@ export type CapacitorConfig = {
|
|
|
10
10
|
};
|
|
11
11
|
export default class CapacitorLogtoClient extends LogtoBaseClient {
|
|
12
12
|
constructor(config: LogtoConfig, capacitorConfig?: CapacitorConfig);
|
|
13
|
+
/**
|
|
14
|
+
* **NOTE: Capacitor does not support this method signature, use the other overloads.**
|
|
15
|
+
*/
|
|
16
|
+
signIn(options: SignInOptions): Promise<void>;
|
|
13
17
|
/**
|
|
14
18
|
* Start the sign-in flow with the specified redirect URI. The URI must be
|
|
15
19
|
* registered in the Logto Console.
|
|
@@ -20,7 +24,7 @@ export default class CapacitorLogtoClient extends LogtoBaseClient {
|
|
|
20
24
|
* @param redirectUri The redirect URI that the user will be redirected to after the sign-in flow is completed.
|
|
21
25
|
* @param interactionMode The interaction mode to be used for the authorization request. Note it's not
|
|
22
26
|
* a part of the OIDC standard, but a Logto-specific extension. Defaults to `signIn`.
|
|
23
|
-
* @throws
|
|
27
|
+
* @throws `LogtoClientError` If error happens during the sign-in flow or the user cancels the sign-in.
|
|
24
28
|
*
|
|
25
29
|
* @example
|
|
26
30
|
* ```ts
|
package/lib/index.js
CHANGED
|
@@ -37,38 +37,10 @@ class CapacitorLogtoClient extends LogtoBaseClient {
|
|
|
37
37
|
},
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Start the sign-in flow with the specified redirect URI. The URI must be
|
|
42
|
-
* registered in the Logto Console.
|
|
43
|
-
*
|
|
44
|
-
* Remember to configure the correct [scheme or universal links](https://capacitorjs.com/docs/guides/deep-links)
|
|
45
|
-
* to ensure the app can be opened from the redirect URI.
|
|
46
|
-
*
|
|
47
|
-
* @param redirectUri The redirect URI that the user will be redirected to after the sign-in flow is completed.
|
|
48
|
-
* @param interactionMode The interaction mode to be used for the authorization request. Note it's not
|
|
49
|
-
* a part of the OIDC standard, but a Logto-specific extension. Defaults to `signIn`.
|
|
50
|
-
* @throws {@link LogtoClientError} If error happens during the sign-in flow or the user cancels the sign-in.
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```ts
|
|
54
|
-
* const client = new CapacitorLogtoClient({
|
|
55
|
-
* endpoint: 'https://your.logto.endpoint',
|
|
56
|
-
* appId: 'your-app-id',
|
|
57
|
-
* });
|
|
58
|
-
*
|
|
59
|
-
* await client.signIn('io.logto.example://callback'); // throws if error happens
|
|
60
|
-
* console.log(await client.getIdTokenClaims()); // { sub: '123', ... }
|
|
61
|
-
* ```
|
|
62
|
-
*
|
|
63
|
-
* @remarks
|
|
64
|
-
* The user will be redirected to that URI after the sign-in flow is completed,
|
|
65
|
-
* and the client will be able to get the authorization code from the URI.
|
|
66
|
-
* {@link handleSignInCallback} will be called after the user is redirected.
|
|
67
|
-
*
|
|
68
|
-
* @see {@link https://docs.logto.io/docs/recipes/integrate-logto/vanilla-js/#sign-in | Sign in} for more information.
|
|
69
|
-
* @see {@link InteractionMode}
|
|
70
|
-
*/
|
|
71
40
|
async signIn(redirectUri, interactionMode) {
|
|
41
|
+
if (typeof redirectUri === 'object' && !(redirectUri instanceof URL)) {
|
|
42
|
+
throw new TypeError('The first argument must be a string or a URL.');
|
|
43
|
+
}
|
|
72
44
|
return new Promise((resolve, reject) => {
|
|
73
45
|
const run = async () => {
|
|
74
46
|
const [browserHandle, appHandle] = await Promise.all([
|
|
@@ -80,7 +52,7 @@ class CapacitorLogtoClient extends LogtoBaseClient {
|
|
|
80
52
|
// Handle the case where the user completes the sign-in and is redirected
|
|
81
53
|
// back to the app.
|
|
82
54
|
App.addListener('appUrlOpen', async ({ url }) => {
|
|
83
|
-
if (!url.startsWith(redirectUri)) {
|
|
55
|
+
if (!url.startsWith(redirectUri.toString())) {
|
|
84
56
|
return;
|
|
85
57
|
}
|
|
86
58
|
await Promise.all([
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/capacitor",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./lib/index.cjs",
|
|
6
6
|
"module": "./lib/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"directory": "packages/capacitor"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@logto/browser": "^2.2.
|
|
24
|
+
"@logto/browser": "^2.2.4"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@capacitor/app": "^5.0.6",
|