Skip to content

Commit 41dfe52

Browse files
authored
refactor: refactor SDK using flutter_web_auth_2 (#76)
1 parent 4e223c5 commit 41dfe52

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+732
-458
lines changed

CHANGELOG.md

Lines changed: 72 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,120 @@
1-
## 0.0.1
2-
3-
### Packages
1+
## 2.1.0
42

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 |
3+
### New features
94

10-
### Platforms
5+
Add extra parameters to the signIn method for better sign-in experience customization.
116

12-
iOS, Android
7+
See the [Authentication parameters](https://docs.logto.io/docs/references/openid-connect/authentication-parameters) for more details.
138

14-
### Features
9+
1. `directSignIn`: This parameter allows you to skip the first screen of the sign-in page and directly go to the social or enterprise sso connectors's sign-in page.
1510

16-
- User sign-in using Logto's webAuth
17-
- User sign-out
18-
- Retrieve idToken claims
19-
- Retrieve access token
11+
- `social:<idp-name>`: Use the specified social connector, e.g. `social:google`
12+
- `sso:<connector-id>`: Use the specified enterprise sso connector, e.g. `sso:123456`
2013

21-
## 1.0.0
14+
2. `firstScreen`: This parameter allows you to customize the first screen that users see when they start the authentication process. The value for this parameter can be:
2215

23-
### logto_client
16+
- `sign_in`: Allow users to directly access the sign-in page.
17+
- `register`: Allow users to directly access the registration page.
18+
- `single_sign_on`: Allow users to directly access the single sign-on (SSO) page.
19+
- `identifier:sign_in`: Allow users to direct access a page that only display specific identifier-based sign-in methods to users.
20+
- `identifier:register`: Allow users to direct access a page that only display specific identifier-based registration methods to users.
21+
- `reset_password`: Allow users to directly access the password reset page.
2422

25-
- Support RBAC
26-
- Add `LogtoClient.getUserInfo` to get authenticated user info
23+
3. `identifiers`: Additional parameter to specify the identifier type for the first screen. This parameter is only used when the `firstScreen` parameter is set to `identifier:sign_in`, `identifier:register` or `reset_password`. The value can be a list of the following supported identifier types:
2724

28-
## 1.1.0
25+
- `email`
26+
- `phone`
27+
- `username`
2928

30-
- fix Logto sign-out bug, the token revoke endpoint was misconfigured
31-
- bump version to support Flutter 3.10
32-
- bump the http dependency to the latest version
33-
- bump the flutter_web_auth dependency to the latest version
34-
- bump the flutter_secure_storage dependency to the latest version
29+
4. `extraParams`: This parameter allow you to pass additional custom parameters to the Logto sign-in page. The value for this parameter should be a Map<String, String> object.
3530

36-
## 1.2.0
31+
### Bug fixes
3732

38-
### Dependencies update
33+
Fix the `logtoClient.getAccessToken` method always fetching new access token bug.
3934

40-
- bump http package dependency to 1.2.0
41-
- bump flutter_secure_storage package dependency to 9.0.0
42-
- bump flutter_lints package dependency to 3.0.x
35+
Background:
36+
On each token exchange request, Logto dart SDK will cache the token response in the local storage. To reduce the number of token exchange requests, the SDK should always return the cached access token if it's not expired. Only when the access token is expired, the SDK should fetch a new access token using the refresh token.
37+
However, the current implementation always fetches a new access token even if the cached access token is not expired.
4338

44-
### Features
39+
Root cause:
40+
Previously, all the access token storage keys are generated using the combination of the token's `resource`, `organization` and `scopes` values. This is to ensure that multiple access tokens can be stored in the storage without conflict.
41+
Logto does not support narrowing down the scopes during a token exchange request, so the scopes value is always the same as the initial token request, therefore `scopes` is not necessary to be included in the `logtoClient.getAccessToken` method. Without the `scopes` value specified, the SDK can not locate the correct access token in the storage, which leads to always fetching a new access token.
4542

46-
- Update `LogtoConfig` to support new organization feature, including new organization scopes and fetching organization token
47-
- Add `LogtoClient.getOrganizationToken` method to support organization token retrieval
43+
Fix:
44+
Remove the `scope` parameter from the `_tokenStorage.buildAccessTokenKey` and `_tokenStorage.getAccessToken` methods. Always get and set the access token using the `resource` and `organization` values as the key.
4845

49-
### Refactor
46+
## 2.0.2
5047

51-
- Export all the necessary classes and interfaces from `logto_core` to `logto_client` package
52-
- Update the example app to demonstrate the new organization feature
48+
### Bug fixes
5349

54-
## 2.0.0
50+
Fix the `OpenIdClaims` class key parsing issue:
5551

56-
Upgrade to dart 3.0.0
52+
- `avatar` key is now `picture` mapped from the `picture` key in the token claims
53+
- `phone` key is now `phoneNumber` mapped from the `phone_number` key in the token claims
54+
- `phoneVerified` key is now `phoneNumberVerified` mapped from the `phone_number_verified` key in the token claims
5755

58-
- Fix the `UserInfo` abstract class used as mixin incompatibility issue
59-
- SDK now supports Dart ^3.0.0
60-
- < 3.0.0 users please use the previous version of the SDK
56+
Previous key mapping values are always empty as they are not available in the IdToken claims.
57+
This fix update the key mapping to the correct values.
6158

6259
## 2.0.1
6360

64-
Bug fix
61+
### Bug fixes
6562

6663
Issue: `LogtoClient.getUserInfo` method throws an `not authenticated` error when the initial access token is expired.
6764
Expected behavior: The method should refresh the access token and return the user info properly.
6865
Fix: Always get the access token by calling `LogtoClient.getAccessToken`, which will refresh the token automatically if it's expired.
6966

70-
## 2.0.2
67+
## 2.0.0
7168

72-
Bug fix
69+
### Dependencies update
7370

74-
Fix the `OpenIdClaims` class key parsing issue:
71+
Upgrade to dart 3.0.0
7572

76-
- `avatar` key is now `picture` mapped from the `picture` key in the token claims
77-
- `phone` key is now `phoneNumber` mapped from the `phone_number` key in the token claims
78-
- `phoneVerified` key is now `phoneNumberVerified` mapped from the `phone_number_verified` key in the token claims
73+
- Fix the `UserInfo` abstract class used as mixin incompatibility issue
74+
- SDK now supports Dart ^3.0.0
75+
- < 3.0.0 users please use the previous version of the SDK
7976

80-
Previous key mapping values are always empty as they are not available in the IdToken claims.
81-
This fix update the key mapping to the correct values.
77+
## 1.2.0
8278

83-
## 2.1.0
79+
### Dependencies update
8480

85-
### New Features
81+
- bump http package dependency to 1.2.0
82+
- bump flutter_secure_storage package dependency to 9.0.0
83+
- bump flutter_lints package dependency to 3.0.x
8684

87-
Add extra parameters to the signIn method for better sign-in experience customization.
85+
### New features
8886

89-
See the [Authentication parameters](https://docs.logto.io/docs/references/openid-connect/authentication-parameters) for more details.
87+
- Update `LogtoConfig` to support new organization feature, including new organization scopes and fetching organization token
88+
- Add `LogtoClient.getOrganizationToken` method to support organization token retrieval
9089

91-
1. `directSignIn`: This parameter allows you to skip the first screen of the sign-in page and directly go to the social or enterprise sso connectors's sign-in page.
90+
### Refactors
9291

93-
- `social:<idp-name>`: Use the specified social connector, e.g. `social:google`
94-
- `sso:<connector-id>`: Use the specified enterprise sso connector, e.g. `sso:123456`
92+
- Export all the necessary classes and interfaces from `logto_core` to `logto_client` package
93+
- Update the example app to demonstrate the new organization feature
9594

96-
2. `firstScreen`: This parameter allows you to customize the first screen that users see when they start the authentication process. The value for this parameter can be:
95+
## 1.0.0
9796

98-
- `sign_in`: Allow users to directly access the sign-in page.
99-
- `register`: Allow users to directly access the registration page.
100-
- `single_sign_on`: Allow users to directly access the single sign-on (SSO) page.
101-
- `identifier:sign_in`: Allow users to direct access a page that only display specific identifier-based sign-in methods to users.
102-
- `identifier:register`: Allow users to direct access a page that only display specific identifier-based registration methods to users.
103-
- `reset_password`: Allow users to directly access the password reset page.
97+
### New features
10498

105-
3. `identifiers`: Additional parameter to specify the identifier type for the first screen. This parameter is only used when the `firstScreen` parameter is set to `identifier:sign_in`, `identifier:register` or `reset_password`. The value can be a list of the following supported identifier types:
99+
- Support RBAC
100+
- Add `LogtoClient.getUserInfo` method to get authenticated user info
106101

107-
- `email`
108-
- `phone`
109-
- `username`
102+
## 0.0.1
110103

111-
4. `extraParams`: This parameter allow you to pass additional custom parameters to the Logto sign-in page. The value for this parameter should be a Map<String, String> object.
104+
### Packages
112105

113-
### Bug Fixes
106+
| Name | Description |
107+
| ------------ | ----------------------------------------------------------------------------------------------------------- |
108+
| logto_core | Core SDK is used for generation dart project with basic API and util method provided. |
109+
| logto_client | Client SDK for flutter native apps. Built based on logto_core with user sign-in interaction flow integrated |
114110

115-
Fix the `logtoClient.getAccessToken` method always fetching new access token bug.
111+
### Supported Platforms
116112

117-
Background:
118-
On each token exchange request, Logto dart SDK will cache the token response in the local storage. To reduce the number of token exchange requests, the SDK should always return the cached access token if it's not expired. Only when the access token is expired, the SDK should fetch a new access token using the refresh token.
119-
However, the current implementation always fetches a new access token even if the cached access token is not expired.
113+
iOS, Android
120114

121-
Root cause:
122-
Previously, all the access token storage keys are generated using the combination of the token's `resource`, `organization` and `scopes` values. This is to ensure that multiple access tokens can be stored in the storage without conflict.
123-
Logto does not support narrowing down the scopes during a token exchange request, so the scopes value is always the same as the initial token request, therefore `scopes` is not necessary to be included in the `logtoClient.getAccessToken` method. Without the `scopes` value specified, the SDK can not locate the correct access token in the storage, which leads to always fetching a new access token.
115+
### Features
124116

125-
Fix:
126-
Remove the `scope` parameter from the `_tokenStorage.buildAccessTokenKey` and `_tokenStorage.getAccessToken` methods. Always get and set the access token using the `resource` and `organization` values as the key.
117+
- User sign-in using Logto's webAuth
118+
- User sign-out
119+
- Retrieve idToken claims
120+
- Retrieve access token

example/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
*.swp
66
.DS_Store
77
.atom/
8+
.build/
89
.buildlog/
910
.history
1011
.svn/
12+
.swiftpm/
1113
migrate_working_dir/
1214

1315
# IntelliJ related

example/.metadata

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
# This file tracks properties of this Flutter project.
22
# Used by Flutter tool to assess capabilities and perform upgrades etc.
33
#
4-
# This file should be version controlled.
4+
# This file should be version controlled and should not be manually edited.
55

66
version:
7-
revision: f1875d570e39de09040c8f79aa13cc56baab8db1
8-
channel: stable
7+
revision: "17025dd88227cd9532c33fa78f5250d548d87e9a"
8+
channel: "stable"
99

1010
project_type: app
1111

1212
# Tracks metadata for the flutter migrate command
1313
migration:
1414
platforms:
1515
- platform: root
16-
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
17-
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
18-
- platform: ios
19-
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
20-
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
16+
create_revision: 17025dd88227cd9532c33fa78f5250d548d87e9a
17+
base_revision: 17025dd88227cd9532c33fa78f5250d548d87e9a
18+
- platform: android
19+
create_revision: 17025dd88227cd9532c33fa78f5250d548d87e9a
20+
base_revision: 17025dd88227cd9532c33fa78f5250d548d87e9a
2121

2222
# User provided section
2323

example/android/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ gradle-wrapper.jar
77
GeneratedPluginRegistrant.java
88

99
# Remember to never publicly share your keystore.
10-
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
10+
# See https://flutter.dev/to/reference-keystore
1111
key.properties
1212
**/*.keystore
1313
**/*.jks

example/android/app/build.gradle

Lines changed: 19 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,44 @@
1-
def localProperties = new Properties()
2-
def localPropertiesFile = rootProject.file('local.properties')
3-
if (localPropertiesFile.exists()) {
4-
localPropertiesFile.withReader('UTF-8') { reader ->
5-
localProperties.load(reader)
6-
}
7-
}
8-
9-
def flutterRoot = localProperties.getProperty('flutter.sdk')
10-
if (flutterRoot == null) {
11-
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12-
}
13-
14-
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
15-
if (flutterVersionCode == null) {
16-
flutterVersionCode = '1'
17-
}
18-
19-
def flutterVersionName = localProperties.getProperty('flutter.versionName')
20-
if (flutterVersionName == null) {
21-
flutterVersionName = '1.0'
1+
plugins {
2+
id "com.android.application"
3+
id "kotlin-android"
4+
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
5+
id "dev.flutter.flutter-gradle-plugin"
226
}
237

24-
apply plugin: 'com.android.application'
25-
apply plugin: 'kotlin-android'
26-
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27-
288
android {
29-
compileSdkVersion 33
30-
ndkVersion flutter.ndkVersion
9+
namespace = "com.example.example"
10+
compileSdk = flutter.compileSdkVersion
11+
ndkVersion = flutter.ndkVersion
3112

3213
compileOptions {
33-
sourceCompatibility JavaVersion.VERSION_1_8
34-
targetCompatibility JavaVersion.VERSION_1_8
14+
sourceCompatibility = JavaVersion.VERSION_1_8
15+
targetCompatibility = JavaVersion.VERSION_1_8
3516
}
3617

3718
kotlinOptions {
38-
jvmTarget = '1.8'
39-
}
40-
41-
sourceSets {
42-
main.java.srcDirs += 'src/main/kotlin'
19+
jvmTarget = JavaVersion.VERSION_1_8
4320
}
4421

4522
defaultConfig {
4623
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
47-
applicationId "com.example.example"
24+
applicationId = "com.example.example"
4825
// You can update the following values to match your application needs.
49-
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
50-
minSdkVersion 19
51-
targetSdkVersion flutter.targetSdkVersion
52-
versionCode flutterVersionCode.toInteger()
53-
versionName flutterVersionName
26+
// For more information, see: https://flutter.dev/to/review-gradle-config.
27+
minSdk = flutter.minSdkVersion
28+
targetSdk = flutter.targetSdkVersion
29+
versionCode = flutter.versionCode
30+
versionName = flutter.versionName
5431
}
5532

5633
buildTypes {
5734
release {
5835
// TODO: Add your own signing config for the release build.
5936
// Signing with the debug keys for now, so `flutter run --release` works.
60-
signingConfig signingConfigs.debug
37+
signingConfig = signingConfigs.debug
6138
}
6239
}
6340
}
6441

6542
flutter {
66-
source '../..'
67-
}
68-
69-
dependencies {
70-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
43+
source = "../.."
7144
}

example/android/app/src/debug/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.example.example">
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
32
<!-- The INTERNET permission is required for development. Specifically,
43
the Flutter tool needs it to communicate with the running application
54
to allow setting breakpoints, to provide hot reload, etc.

0 commit comments

Comments
 (0)