Skip to content

Commit d2c2297

Browse files
authored
chore(dart): add readme and changelogs (#21)
1 parent 2ef0114 commit d2c2297

File tree

7 files changed

+229
-5
lines changed

7 files changed

+229
-5
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,9 @@ jobs:
5353
- name: Test
5454
working-directory: ./example
5555
run: flutter test --no-pub --coverage
56+
57+
- name: Codecov Dart SDK
58+
uses: codecov/codecov-action@v2
59+
with:
60+
flags: Dart-sdk
61+
directory: ./lib

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ migrate_working_dir/
3030
.flutter-plugins-dependencies
3131
.packages
3232
build/
33+
coverage/*

.pubignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Miscellaneous
2+
3+
_.class
4+
_.log
5+
_.pyc
6+
_.swp
7+
.DS_Store
8+
.atom/
9+
.buildlog/
10+
.history
11+
.svn/
12+
migrate_working_dir/
13+
14+
# IntelliJ related
15+
16+
_.iml
17+
_.ipr
18+
\*.iws
19+
.idea/
20+
21+
# The .vscode folder contains launch configuration and tasks you configure in
22+
23+
# VS Code which you may wish to be included in version control, so this line
24+
25+
# is commented out by default.
26+
27+
#.vscode/
28+
29+
# Flutter/Dart/Pub related
30+
31+
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
32+
33+
/pubspec.lock \*_/doc/api/
34+
.dart_tool/
35+
.flutter-plugins
36+
.flutter-plugins-dependencies
37+
.packages
38+
build/
39+
coverage/_

CHANGELOG.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
11
## 0.0.1
22

3-
* TODO: Describe initial release.
3+
### Packages
4+
5+
| Name | Description |
6+
| ------------ | ----------------------------------------------------------------------------------------------------------- |
7+
| logto_core | Core SDK is used for generation dart project with basic API and util method provided. |
8+
| logto_client | Client SDK for flutter native apps. Built based on logto_core with user sign-in interaction flow integrated |
9+
10+
### Platforms
11+
12+
iOS, Android
13+
14+
### Features
15+
16+
- User sign-in using Logto's webAuth
17+
- User sign-out
18+
- Retrieve idToken claims
19+
- Retrieve access token

README.md

Lines changed: 163 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,166 @@
88

99
# Logto Flutter SDKs
1010

11-
The monorepo for SDKs and demo apps wrote in Flutter.
11+
[![Build Status](https://github.com/logto-io/kotlin/actions/workflows/main.yml/badge.svg)](https://github.com/logto-io/dart/actions/workflows/main.yml)
12+
13+
Logto's flutter SDK for native apps.
14+
15+
## Installation
16+
17+
```sh
18+
flutter pub get logto_dart_sdk
19+
```
20+
21+
## Products
22+
23+
| Name | Description |
24+
| ------------ | ----------------------------------------------------------------------------------------------------------- |
25+
| logto_core | Core SDK is used for generation dart project with basic API and util method provided. |
26+
| logto_client | Client SDK for flutter native apps. Built based on logto_core with user sign-in interaction flow integrated |
27+
28+
## Logto Client
29+
30+
### Configurations
31+
32+
#### flutter_secure_storage
33+
34+
We use [flutter_secure_storage](https://pub.dev/packages/flutter_secure_storage) to implement the cross-platform persistent auth_token secure storage.
35+
36+
- Keychain is used for iOS
37+
- AES encryption is used for Android.
38+
39+
Configure Android version:
40+
41+
In [project]/android/app/build.gradle set minSdkVersion to >= 18.
42+
43+
```gradle
44+
android {
45+
...
46+
47+
defaultConfig {
48+
...
49+
minSdkVersion 18
50+
...
51+
}
52+
}
53+
54+
```
55+
56+
> Note By default Android backups data on Google Drive. It can cause exception java.security.InvalidKeyException:Failed to unwrap key. You need to:
57+
>
58+
> - disable autobackup,
59+
> - exclude sharedprefs FlutterSecureStorage used by the plugin
60+
61+
1. To disable autobackup, go to your app manifest file and set the boolean value android:allowBackup.
62+
63+
```xml
64+
<manifest ... >
65+
...
66+
<application
67+
android:allowBackup="false"
68+
android:fullBackupContent="false">
69+
...
70+
>
71+
...
72+
</application>
73+
</manifest>
74+
```
75+
76+
2. Exclude sharedprefs FlutterSecureStorage.
77+
78+
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.
79+
80+
```xml
81+
<application ...
82+
android:fullBackupContent="@xml/backup_rules">
83+
</application>
84+
```
85+
86+
```xml
87+
<?xml version="1.0" encoding="utf-8"?>
88+
<full-backup-content>
89+
<exclude domain="sharedpref" path="FlutterSecureStorage"/>
90+
</full-backup-content>
91+
```
92+
93+
Please check [flutter_secure_storage](https://pub.dev/packages/flutter_secure_storage#configure-android-version) for more details.
94+
95+
#### flutter_web_auth
96+
97+
[flutter_web_auth](https://pub.dev/packages/flutter_appauth) is used behind Logto's flutter SDK. We rely on its webview-based interaction interface to open Logto's authorization pages.
98+
99+
> In the background, 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.
100+
101+
Android
102+
103+
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`.
104+
105+
```xml
106+
<activity android:name="com.linusu.flutter_web_auth.CallbackActivity" android:exported="false">
107+
<intent-filter android:label="flutter_web_auth">
108+
<action android:name="android.intent.action.VIEW"/>
109+
<category android:name="android.intent.category.DEFAULT"/>
110+
<category android:name="android.intent.category.BROWSABLE"/>
111+
<data android:scheme="io.logto"/>
112+
</intent-filter>
113+
</activity>
114+
```
115+
116+
By doing so, your app will automatically capture the callbaclUri after a successful sign-in and redirect the user back to the app.
117+
118+
### Basic Usage
119+
120+
```dart
121+
import 'package:logto_dart_sdk/logto_dart_sdk.dart';
122+
123+
// ...
124+
late LogtoClient logtoClient;
125+
126+
void _init() async {
127+
logtoClient = LogtoClient(
128+
config: config, // LogtoConfig
129+
httpClient: http.Client(), // Optional http client
130+
);
131+
}
132+
133+
void signIn() async {
134+
await logtoClient.signIn(redirectUri);
135+
}
136+
137+
void signOut() async {
138+
await logtoClient.signOut();
139+
}
140+
141+
```
142+
143+
### Class LogtoConfig
144+
145+
#### Properties
146+
147+
| name | type | description |
148+
| --------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
149+
| appId | String | Your appId generate from Logto's admin console |
150+
| appSecret | String? | App Secret generated along with the appId. Optional for native apps. |
151+
| endpoint | String | Your logto server endpoint. e.g. https://logto.dev |
152+
| scopes | List&#60;String&#62;? | List all the permission scopes your app will request for. You may define and find it through Logto's admin console. |
153+
| resources | List&#60;String&#62;? | List all the [resource indicators](https://docs.logto.io/docs/references/resources/) you app may request for access. You may define and find it through Logto's admin console. |
154+
155+
### Class LogtoClient
156+
157+
#### Properties
158+
159+
| name | type | description |
160+
| --------------- | --------------------------------------- | ----------------------------------------------- |
161+
| config | final LogtoConfig | Logto Config used to init Logto Client |
162+
| idToken | read-only Future&#60;String?&#62; | idToken returned after success authentication |
163+
| isAuthenticated | read-only Future&#60;bool&#62; | Is Authenticated status |
164+
| idTokenClaims | read-only Future&#60;OpenIdClaims?&#62; | Decoded idToken claims including basic userinfo |
165+
| loading | read-only bool | Global API loading status |
166+
167+
#### Methods
168+
169+
| name | type | description |
170+
| -------------- | --------------------------------------------------- | ------------------------------------------------------------------- |
171+
| getAccessToken | ({String? resource}) -> Future&#60;AccessToken&#62; | Request for an api resource specific access token for authorization |
172+
| signIn | (String? redirectUri) -> Future&#60;void&#62; | Init user sign-in flow |
173+
| signOut | () -> Future&#60;void&#62; | Sign-out |

example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'package:flutter/material.dart';
2-
import 'package:logto_dart_sdk/logto_dart_sdk.dart';
2+
import 'package:logto_dart_sdk/logto_client.dart';
33
import 'package:http/http.dart' as http;
44

55
void main() async {

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: logto_dart_sdk
2-
description: A new Flutter package project.
2+
description: Logto's Flutter SDK packages
33
version: 0.0.1
4-
homepage:
4+
homepage: https://github.com/logto-io/dart
55

66
environment:
77
sdk: ">=2.17.6 <3.0.0"

0 commit comments

Comments
 (0)