Skip to content

Commit f45a14e

Browse files
authored
Use UIImplementation to open settings #84
ref DEV-2547
2 parents 5425b5c + 2418f2e commit f45a14e

File tree

8 files changed

+23
-213
lines changed

8 files changed

+23
-213
lines changed

android/src/main/AndroidManifest.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
android:name=".OAuthCoordinatorActivity"
77
android:exported="false"
88
android:launchMode="singleTask" />
9-
<activity
10-
android:name=".WebViewActivity"
11-
android:exported="false"
12-
android:launchMode="singleTask"
13-
android:theme="@style/AuthgearTheme"
14-
android:configChanges="orientation|screenSize" />
159
<activity
1610
android:name=".WebKitWebViewActivity"
1711
android:exported="false"

android/src/main/kotlin/com/authgear/flutter/AuthgearPlugin.kt

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ class AuthgearPlugin: FlutterPlugin, ActivityAware, MethodCallHandler, PluginReg
5959
private const val LOGTAG = "AuthgearPlugin"
6060
private const val ENCRYPTED_SHARED_PREFERENCES_NAME = "authgear_encrypted_shared_preferences"
6161
private const val TAG_AUTHENTICATION = 1
62-
private const val TAG_OPEN_URL = 2
6362

6463
fun wechatErrorResult(errCode: Int, errStr: String, result: Result) {
6564
if (errCode == -2) {
@@ -120,13 +119,6 @@ class AuthgearPlugin: FlutterPlugin, ActivityAware, MethodCallHandler, PluginReg
120119
}
121120
true
122121
}
123-
TAG_OPEN_URL -> {
124-
when (resultCode) {
125-
Activity.RESULT_CANCELED -> handle.value.result.success(null)
126-
Activity.RESULT_OK -> handle.value.result.success(null)
127-
}
128-
true
129-
}
130122
else -> false
131123
}
132124
}
@@ -185,17 +177,6 @@ class AuthgearPlugin: FlutterPlugin, ActivityAware, MethodCallHandler, PluginReg
185177
val intent = WebKitWebViewActivity.createIntent(activity, options)
186178
activity.startActivityForResult(intent, requestCode)
187179
}
188-
"openURL" -> {
189-
val url = Uri.parse(call.argument("url"))
190-
val requestCode = startActivityHandles.push(StartActivityHandle(TAG_OPEN_URL, Handle(result)))
191-
val activity = activityBinding?.activity
192-
if (activity == null) {
193-
result.noActivity()
194-
return
195-
}
196-
val intent = WebViewActivity.createIntent(activity, url)
197-
activity.startActivityForResult(intent, requestCode)
198-
}
199180
"getDeviceInfo" -> {
200181
this.getDeviceInfo(result)
201182
}

android/src/main/kotlin/com/authgear/flutter/WebViewActivity.kt

Lines changed: 0 additions & 129 deletions
This file was deleted.

example/android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
#Mon Sep 01 14:55:54 HKT 2025
12
distributionBase=GRADLE_USER_HOME
23
distributionPath=wrapper/dists
4+
# AGP, gradle, and kotlin versions is a 3-element tuple.
5+
# See https://github.com/flutter/flutter/blob/3.32.8/dev/devicelab/bin/tasks/android_java17_dependency_smoke_tests.dart#L34
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
37
zipStoreBase=GRADLE_USER_HOME
48
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip

example/android/settings.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ pluginManagement {
1818

1919
plugins {
2020
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
21-
id "com.android.application" version "8.1.0" apply false
22-
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
21+
// AGP, gradle, and kotlin versions is a 3-element tuple.
22+
// See https://github.com/flutter/flutter/blob/3.32.8/dev/devicelab/bin/tasks/android_java17_dependency_smoke_tests.dart#L34
23+
id "com.android.application" version "8.7.0" apply false
24+
// AGP, gradle, and kotlin versions is a 3-element tuple.
25+
// See https://github.com/flutter/flutter/blob/3.32.8/dev/devicelab/bin/tasks/android_java17_dependency_smoke_tests.dart#L34
26+
id "org.jetbrains.kotlin.android" version "2.1.0" apply false
2327
}
2428

2529
include ":app"

ios/Classes/SwiftAuthgearPlugin.swift

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ public class SwiftAuthgearPlugin: NSObject, FlutterPlugin, ASWebAuthenticationPr
5454
wechatRedirectURIString: wechatRedirectURIString,
5555
result: result
5656
)
57-
case "openURL":
58-
let arguments = call.arguments as! Dictionary<String, AnyObject>
59-
let urlString = arguments["url"] as! String
60-
let url = URL(string: urlString)!
61-
self.openURL(url: url, result: result);
6257
case "getDeviceInfo":
6358
self.getDeviceInfo(result: result)
6459
case "storageSetItem":
@@ -241,42 +236,6 @@ public class SwiftAuthgearPlugin: NSObject, FlutterPlugin, ASWebAuthenticationPr
241236
controller.start()
242237
}
243238

244-
private func openURL(url: URL, result: @escaping FlutterResult) {
245-
var sessionToKeepAlive: Any? = nil
246-
let completionHandler = { (url: URL?, error: Error?) in
247-
sessionToKeepAlive = nil
248-
if let error = error {
249-
if #available(iOS 12, *) {
250-
if case ASWebAuthenticationSessionError.canceledLogin = error {
251-
result(nil)
252-
return
253-
}
254-
}
255-
256-
self.handleError(result: result, error: error)
257-
return
258-
}
259-
260-
result(FlutterError.cancel)
261-
return
262-
}
263-
if #available(iOS 12, *) {
264-
let session = ASWebAuthenticationSession(
265-
url: url,
266-
callbackURLScheme: "authgearsdk",
267-
completionHandler: completionHandler
268-
)
269-
if #available(iOS 13, *) {
270-
session.presentationContextProvider = self
271-
session.prefersEphemeralWebBrowserSession = true
272-
}
273-
session.start()
274-
sessionToKeepAlive = session
275-
} else {
276-
result(FlutterError.unsupported)
277-
}
278-
}
279-
280239
private func getDeviceInfo(result: FlutterResult) {
281240
var systemInfo = utsname()
282241
uname(&systemInfo)

lib/src/container.dart

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,19 @@ class Authgear implements AuthgearHttpClientDelegate {
494494
wechatRedirectURI: wechatRedirectURI,
495495
);
496496

497-
await native.openURL(
498-
url: targetURL.toString(),
499-
);
497+
try {
498+
await _uiImplementation.openAuthorizationURL(
499+
url: targetURL.toString(),
500+
redirectURI: "nocallback://nocallback",
501+
shareCookiesWithDeviceBrowser: false,
502+
);
503+
} catch (e) {
504+
if (e is CancelException) {
505+
// Ignore CancelException.
506+
return;
507+
}
508+
rethrow;
509+
}
500510
}
501511

502512
Future<void> _openAuthgearURL({

lib/src/native.dart

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,6 @@ Future<String> openAuthorizeURLWithWebView({
5252
}
5353
}
5454

55-
Future<void> openURL({
56-
required String url,
57-
}) async {
58-
try {
59-
await _channel.invokeMethod("openURL", {
60-
"url": url,
61-
});
62-
} on PlatformException catch (e) {
63-
throw wrapException(e);
64-
}
65-
}
66-
6755
Future<Map> getDeviceInfo() async {
6856
try {
6957
return await _channel.invokeMethod("getDeviceInfo");

0 commit comments

Comments
 (0)