diff --git a/packages/console/src/assets/docs/guides/native-flutter/README.mdx b/packages/console/src/assets/docs/guides/native-flutter/README.mdx index ae759f749..84fd7e02c 100644 --- a/packages/console/src/assets/docs/guides/native-flutter/README.mdx +++ b/packages/console/src/assets/docs/guides/native-flutter/README.mdx @@ -1 +1,196 @@ -## Replace this with actual guide \ No newline at end of file +import UriInputField from '@/mdx-components-v2/UriInputField'; +import Steps from '@/mdx-components-v2/Steps'; +import Step from '@/mdx-components-v2/Step'; +import Tabs from '@mdx/components/Tabs'; +import TabItem from '@mdx/components/TabItem'; +import InlineNotification from '@/ds-components/InlineNotification'; + + + + +Our flutter SDK package is published on [pub.dev](https://pub.dev/packages/logto_dart_sdk). Install the SDK package by running the following command in your project directory: + +```bash +flutter pub get logto_dart_sdk +``` + + + +
+ +flutter_secure_storage + +

+ +We use [flutter_secure_storage](https://pub.dev/packages/flutter_secure_storage) to implement the cross-platform persistent secure token storage. + +- Keychain is used for iOS +- AES encryption is used for Android. + +### Config Android version: + +In `[project]/android/app/build.gradle` set minSdkVersion to >= 18. + +```gradle +android { + ... + + defaultConfig { + ... + minSdkVersion 18 + ... + } +} +``` + + + +By default Android backups data on Google Drive. It can cause exception `java.security.InvalidKeyException:Failed` to unwrap key. You will need to: + +- Disable `autobackup`; +- Exclude `sharedprefs` FlutterSecureStorage used by the plugin; + + + +1. To disable `autobackup`, go to your app manifest file and set the boolean value `android:allowBackup`: + + ```xml + + ... + + ... + + + + ``` + +2. Exclude `sharedprefs` FlutterSecureStorage. + + If you need to enable the `android:fullBackupContent` for your app. Set up a backup rule to [exclude](https://developer.android.com/guide/topics/data/autobackup#IncludingFiles) the prefs used by the plugin: + + ```xml + + + ``` + + ```xml + + + + + ``` + +Please check [flutter_secure_storage](https://pub.dev/packages/flutter_secure_storage#configure-android-version) for more details. + +

+ +
+ +
+ +flutter_web_auth + +

+ +[flutter_web_auth](https://pub.dev/packages/flutter_web_auth) is used behind Logto's flutter SDK. We rely on its webview-based interaction interface to open Logto's authorization pages. + + + +Under the hood, this plugin uses `ASWebAuthenticationSession` on iOS 12+ and macOS 10.15+, +`SFAuthenticationSession` on iOS 11, Chrome Custom Tabs on Android and opens a new window on Web. +You can build it with iOS 8+, but it is currently only supported by iOS 11 or higher. + + + +Andorid: + +In order to capture the callback url from Logto's sign-in web page, you will need to register your sign-in redirectUri to the `AndroidManifest.xml`. + +```xml + + + + + + + + +``` + +

+ +
+ +
+ + +
+  
+    {`
+import 'package:logto_dart_sdk/logto_dart_sdk.dart';
+import 'package:http/http.dart' as http;
+
+late LogtoClient logtoClient;
+
+// LogtoConfig
+final logtoConfig = const LogtoConfig(
+  endpoint: '${props.endpoint}',${
+    props.alternativeEndpoint ? ` // or "${props.alternativeEndpoint}"` : ''
+  }
+  appId: '${props.app.id}',
+);
+
+void init() async {
+  logtoClient = LogtoClient(
+    config: logtoConfig,
+    httpClient: http.Client(), // Optional http client
+  );
+}
+`}
+  
+
+ +
+ + +### Configure Redirect URI + + + In the following steps, we assume your app has configured using `io.logo` as your schema . + + +Let's switch to the Application details page of Logto Admin Console. Add a Redirect URI `io.logto://callback` and click "Save Changes". + + + +### Implement a sign-in method + +
+  
+    {`void signIn() async {
+  await logtoClient.signIn('${props.redirectUris[0] ?? 'io.logto://callback'}');
+}
+  `}
+  
+
+ +
+ + + +Calling `.signOut()` will clean all the Logto data in the secret storage, if it has. + +```dart +void signOut() async { + await logtoClient.signOut(); +} +``` + + + +