Skip to content

Commit 2ecd5eb

Browse files
authored
feat(dart): add sign-in flow (#11)
1 parent 7edf533 commit 2ecd5eb

23 files changed

+508
-50
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ migrate_working_dir/
2626
/pubspec.lock
2727
**/doc/api/
2828
.dart_tool/
29+
.flutter-plugins
30+
.flutter-plugins-dependencies
2931
.packages
3032
build/

example/.metadata

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ migration:
1515
- platform: root
1616
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
1717
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
18-
- platform: web
18+
- platform: ios
1919
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
2020
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
2121

example/ios/Flutter/Debug.xcconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
12
#include "Generated.xcconfig"

example/ios/Flutter/Release.xcconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
12
#include "Generated.xcconfig"

example/ios/Podfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Uncomment this line to define a global platform for your project
2+
# platform :ios, '9.0'
3+
4+
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
5+
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
6+
7+
project 'Runner', {
8+
'Debug' => :debug,
9+
'Profile' => :release,
10+
'Release' => :release,
11+
}
12+
13+
def flutter_root
14+
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
15+
unless File.exist?(generated_xcode_build_settings_path)
16+
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
17+
end
18+
19+
File.foreach(generated_xcode_build_settings_path) do |line|
20+
matches = line.match(/FLUTTER_ROOT\=(.*)/)
21+
return matches[1].strip if matches
22+
end
23+
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
24+
end
25+
26+
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
27+
28+
flutter_ios_podfile_setup
29+
30+
target 'Runner' do
31+
use_frameworks!
32+
use_modular_headers!
33+
34+
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
35+
end
36+
37+
post_install do |installer|
38+
installer.pods_project.targets.each do |target|
39+
flutter_additional_ios_build_settings(target)
40+
end
41+
end

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
1111
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
12+
72922EB6F5B767363CE36318 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A9BE824D0AF9DFAB4E35B0CA /* Pods_Runner.framework */; };
1213
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
1314
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
1415
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
@@ -32,6 +33,7 @@
3233
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
3334
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
3435
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
36+
439E95F172F2B94B36F39620 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
3537
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
3638
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
3739
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
@@ -42,19 +44,34 @@
4244
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
4345
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
4446
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
47+
A9BE824D0AF9DFAB4E35B0CA /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
48+
B60F73CCEBDD12C200A73554 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
49+
CEB39681304224101FD255A2 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
4550
/* End PBXFileReference section */
4651

4752
/* Begin PBXFrameworksBuildPhase section */
4853
97C146EB1CF9000F007C117D /* Frameworks */ = {
4954
isa = PBXFrameworksBuildPhase;
5055
buildActionMask = 2147483647;
5156
files = (
57+
72922EB6F5B767363CE36318 /* Pods_Runner.framework in Frameworks */,
5258
);
5359
runOnlyForDeploymentPostprocessing = 0;
5460
};
5561
/* End PBXFrameworksBuildPhase section */
5662

5763
/* Begin PBXGroup section */
64+
184CE62AE441B8BE00CFE1BC /* Pods */ = {
65+
isa = PBXGroup;
66+
children = (
67+
CEB39681304224101FD255A2 /* Pods-Runner.debug.xcconfig */,
68+
439E95F172F2B94B36F39620 /* Pods-Runner.release.xcconfig */,
69+
B60F73CCEBDD12C200A73554 /* Pods-Runner.profile.xcconfig */,
70+
);
71+
name = Pods;
72+
path = Pods;
73+
sourceTree = "<group>";
74+
};
5875
9740EEB11CF90186004384FC /* Flutter */ = {
5976
isa = PBXGroup;
6077
children = (
@@ -72,6 +89,8 @@
7289
9740EEB11CF90186004384FC /* Flutter */,
7390
97C146F01CF9000F007C117D /* Runner */,
7491
97C146EF1CF9000F007C117D /* Products */,
92+
184CE62AE441B8BE00CFE1BC /* Pods */,
93+
C6BBF6E90EA221AB55C9213B /* Frameworks */,
7594
);
7695
sourceTree = "<group>";
7796
};
@@ -98,19 +117,29 @@
98117
path = Runner;
99118
sourceTree = "<group>";
100119
};
120+
C6BBF6E90EA221AB55C9213B /* Frameworks */ = {
121+
isa = PBXGroup;
122+
children = (
123+
A9BE824D0AF9DFAB4E35B0CA /* Pods_Runner.framework */,
124+
);
125+
name = Frameworks;
126+
sourceTree = "<group>";
127+
};
101128
/* End PBXGroup section */
102129

103130
/* Begin PBXNativeTarget section */
104131
97C146ED1CF9000F007C117D /* Runner */ = {
105132
isa = PBXNativeTarget;
106133
buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */;
107134
buildPhases = (
135+
118C519E8DACC1FC3921C8EB /* [CP] Check Pods Manifest.lock */,
108136
9740EEB61CF901F6004384FC /* Run Script */,
109137
97C146EA1CF9000F007C117D /* Sources */,
110138
97C146EB1CF9000F007C117D /* Frameworks */,
111139
97C146EC1CF9000F007C117D /* Resources */,
112140
9705A1C41CF9048500538489 /* Embed Frameworks */,
113141
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
142+
9CEEC5439720D3CE34A3E5E8 /* [CP] Embed Pods Frameworks */,
114143
);
115144
buildRules = (
116145
);
@@ -169,6 +198,28 @@
169198
/* End PBXResourcesBuildPhase section */
170199

171200
/* Begin PBXShellScriptBuildPhase section */
201+
118C519E8DACC1FC3921C8EB /* [CP] Check Pods Manifest.lock */ = {
202+
isa = PBXShellScriptBuildPhase;
203+
buildActionMask = 2147483647;
204+
files = (
205+
);
206+
inputFileListPaths = (
207+
);
208+
inputPaths = (
209+
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
210+
"${PODS_ROOT}/Manifest.lock",
211+
);
212+
name = "[CP] Check Pods Manifest.lock";
213+
outputFileListPaths = (
214+
);
215+
outputPaths = (
216+
"$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt",
217+
);
218+
runOnlyForDeploymentPostprocessing = 0;
219+
shellPath = /bin/sh;
220+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
221+
showEnvVarsInLog = 0;
222+
};
172223
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
173224
isa = PBXShellScriptBuildPhase;
174225
buildActionMask = 2147483647;
@@ -197,6 +248,23 @@
197248
shellPath = /bin/sh;
198249
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
199250
};
251+
9CEEC5439720D3CE34A3E5E8 /* [CP] Embed Pods Frameworks */ = {
252+
isa = PBXShellScriptBuildPhase;
253+
buildActionMask = 2147483647;
254+
files = (
255+
);
256+
inputFileListPaths = (
257+
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
258+
);
259+
name = "[CP] Embed Pods Frameworks";
260+
outputFileListPaths = (
261+
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
262+
);
263+
runOnlyForDeploymentPostprocessing = 0;
264+
shellPath = /bin/sh;
265+
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
266+
showEnvVarsInLog = 0;
267+
};
200268
/* End PBXShellScriptBuildPhase section */
201269

202270
/* Begin PBXSourcesBuildPhase section */
@@ -272,7 +340,7 @@
272340
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
273341
GCC_WARN_UNUSED_FUNCTION = YES;
274342
GCC_WARN_UNUSED_VARIABLE = YES;
275-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
343+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
276344
MTL_ENABLE_DEBUG_INFO = NO;
277345
SDKROOT = iphoneos;
278346
SUPPORTED_PLATFORMS = iphoneos;
@@ -350,7 +418,7 @@
350418
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
351419
GCC_WARN_UNUSED_FUNCTION = YES;
352420
GCC_WARN_UNUSED_VARIABLE = YES;
353-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
421+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
354422
MTL_ENABLE_DEBUG_INFO = YES;
355423
ONLY_ACTIVE_ARCH = YES;
356424
SDKROOT = iphoneos;
@@ -399,7 +467,7 @@
399467
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
400468
GCC_WARN_UNUSED_FUNCTION = YES;
401469
GCC_WARN_UNUSED_VARIABLE = YES;
402-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
470+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
403471
MTL_ENABLE_DEBUG_INFO = NO;
404472
SDKROOT = iphoneos;
405473
SUPPORTED_PLATFORMS = iphoneos;

example/ios/Runner.xcworkspace/contents.xcworkspacedata

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/ios/Runner/Info.plist

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,12 @@
4545
<false/>
4646
<key>CADisableMinimumFrameDurationOnPhone</key>
4747
<true/>
48+
<key>NSAppTransportSecurity</key>
49+
<dict>
50+
<key>NSAllowsArbitraryLoads</key>
51+
<true/>
52+
<key>NSAllowsArbitraryLoadsInWebContent</key>
53+
<true/>
54+
</dict>
4855
</dict>
4956
</plist>

example/lib/main.dart

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:http/http.dart' as http;
22
import 'package:flutter/material.dart';
3-
import 'package:logto_dart_sdk/logto_core.dart' as logto_core;
3+
4+
import 'package:logto_dart_sdk/logto_client.dart';
45

56
void main() {
67
runApp(const MyApp());
@@ -16,6 +17,11 @@ class MyApp extends StatelessWidget {
1617
title: 'Flutter SDK Demo',
1718
theme: ThemeData(
1819
primarySwatch: Colors.blue,
20+
textButtonTheme: TextButtonThemeData(
21+
style: TextButton.styleFrom(
22+
foregroundColor: Colors.white,
23+
),
24+
),
1925
),
2026
home: const MyHomePage(title: 'Logto SDK Demo Home Page'),
2127
);
@@ -32,25 +38,33 @@ class MyHomePage extends StatefulWidget {
3238

3339
class _MyHomePageState extends State<MyHomePage> {
3440
String content = 'Logto SDK Demo Home Page';
35-
var client = http.Client();
41+
final client = http.Client();
42+
final redirectUri = 'io.logto://callback';
43+
final config = const LogtoConfig(
44+
appId: 'xgSxW0MDpVqW2GDvCnlNb', endpoint: 'https://logto.dev');
45+
46+
late LogtoClient logtoClient;
3647

3748
@override
3849
void initState() {
3950
super.initState();
40-
WidgetsBinding.instance.addPostFrameCallback((_) {
41-
_init();
42-
});
51+
_init();
4352
}
4453

4554
void _init() async {
46-
logto_core
47-
.fetchOidcConfig(
48-
client, "https://logto.dev/oidc/.well-known/openid-configuration")
49-
.then((value) => {
50-
setState(() {
51-
content = value.toJson().toString();
52-
})
53-
});
55+
logtoClient = LogtoClient(config, client);
56+
}
57+
58+
void signInCallback() {
59+
if (logtoClient.isAuthenticate) {
60+
setState(() {
61+
var claims = logtoClient.idTokenClaims?.toJson();
62+
63+
if (claims != null) {
64+
content = claims.entries.map((e) => '${e.key}:${e.value}').join("\n");
65+
}
66+
});
67+
}
5468
}
5569

5670
@override
@@ -68,7 +82,18 @@ class _MyHomePageState extends State<MyHomePage> {
6882
child: Text(
6983
content,
7084
),
71-
)
85+
),
86+
TextButton(
87+
style: TextButton.styleFrom(
88+
backgroundColor: Colors.deepPurpleAccent,
89+
padding: const EdgeInsets.all(16.0),
90+
textStyle: const TextStyle(fontSize: 20),
91+
),
92+
onPressed: () {
93+
logtoClient.signIn(context, redirectUri, signInCallback);
94+
},
95+
child: const Text('Sign In'),
96+
),
7297
],
7398
),
7499
),

example/pubspec.lock

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ packages:
277277
url: "https://pub.dartlang.org"
278278
source: hosted
279279
version: "1.8.1"
280+
plugin_platform_interface:
281+
dependency: transitive
282+
description:
283+
name: plugin_platform_interface
284+
url: "https://pub.dartlang.org"
285+
source: hosted
286+
version: "2.1.2"
280287
pointycastle:
281288
dependency: transitive
282289
description:
@@ -450,6 +457,34 @@ packages:
450457
url: "https://pub.dartlang.org"
451458
source: hosted
452459
version: "1.1.0"
460+
webview_flutter:
461+
dependency: transitive
462+
description:
463+
name: webview_flutter
464+
url: "https://pub.dartlang.org"
465+
source: hosted
466+
version: "3.0.4"
467+
webview_flutter_android:
468+
dependency: transitive
469+
description:
470+
name: webview_flutter_android
471+
url: "https://pub.dartlang.org"
472+
source: hosted
473+
version: "2.10.0"
474+
webview_flutter_platform_interface:
475+
dependency: transitive
476+
description:
477+
name: webview_flutter_platform_interface
478+
url: "https://pub.dartlang.org"
479+
source: hosted
480+
version: "1.9.3"
481+
webview_flutter_wkwebview:
482+
dependency: transitive
483+
description:
484+
name: webview_flutter_wkwebview
485+
url: "https://pub.dartlang.org"
486+
source: hosted
487+
version: "2.9.3"
453488
x509:
454489
dependency: transitive
455490
description:
@@ -466,4 +501,4 @@ packages:
466501
version: "3.1.1"
467502
sdks:
468503
dart: ">=2.17.6 <3.0.0"
469-
flutter: ">=1.17.0"
504+
flutter: ">=3.0.0"

0 commit comments

Comments
 (0)