Downside Description
I am making an attempt to reuse the login stack of my web site (lirmusic.com, which makes use of ThirdWeb) in my Flutter app utilizing the inappwebview
package deal. The stream ought to work as follows:
- Consumer desires to log in, an
InAppWebView
opens tolirmusic.com/mobileLogin
- Consumer logs in as in the event that they have been on the web site
- Upon profitable login, the web site launches a URL name to
lirmusic.com/firebaseToken=xxxxxx
- I seize this Firebase token and use it to log in to my app with the
firebase_auth
package deal
Present Standing:
- Electronic mail login works as anticipated
- Google (and Apple/Fb) sign-in fails
Subject:
When selecting Google login, it opens the account choice web page, however after deciding on an account, it stays caught on a white web page as an alternative of redirecting again to lirmusic.com/firebaseToken
.
Code
class TestNewWeb extends StatefulWidget {
const TestNewWeb({tremendous.key});
@override
State createState() => _TestNewWebState();
}
class _TestNewWebState extends State {
last GlobalKey webViewKey = GlobalKey();
InAppWebViewController? webViewController;
InAppWebViewSettings settings = InAppWebViewSettings(
cacheEnabled: true,
isInspectable: kDebugMode,
mediaPlaybackRequiresUserGesture: false,
//supportMultipleWindows: true,
//javaScriptCanOpenWindowsAutomatically: true,
allowsInlineMediaPlayback: true,
javaScriptEnabled: true,
iframeAllow: "digicam; microphone",
iframeAllowFullscreen: true,
userAgent: 'random',
);
PullToRefreshController? pullToRefreshController;
String url = "";
double progress = 0;
last urlController = TextEditingController();
@override
void initState() {
tremendous.initState();
pullToRefreshController = kIsWeb
? null
: PullToRefreshController(
settings: PullToRefreshSettings(
colour: Colours.blue,
),
onRefresh: () async {
if (defaultTargetPlatform == TargetPlatform.android) {
webViewController?.reload();
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
webViewController?.loadUrl(
urlRequest:
URLRequest(url: await webViewController?.getUrl()));
}
},
);
}
@override
Widget construct(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Textual content("InAppWebView")),
physique: SafeArea(
youngster: Column(kids: [
TextField(
decoration: const InputDecoration(prefixIcon: Icon(Icons.search)),
controller: urlController,
keyboardType: TextInputType.url,
onSubmitted: (value) {
var url = WebUri(value);
if (url.scheme.isEmpty) {
url = WebUri("https://lirmusic.com/mobileLogin");
}
webViewController?.loadUrl(urlRequest: URLRequest(url: url));
},
),
Expanded(
child: Stack(
children: [
InAppWebView(
key: webViewKey,
initialUrlRequest: URLRequest(url: WebUri(lir)),
initialSettings: settings,
pullToRefreshController: pullToRefreshController,
onWebViewCreated: (controller) {
webViewController = controller;
},
onLoadStart: (controller, url) {
print("URL ----------" + url.toString());
setState(() {
this.url = url.toString();
urlController.text = this.url;
});
},
//onPermissionRequest: (controller, request) async {
// return PermissionResponse(
// resources: request.resources,
// action: PermissionResponseAction.GRANT);
//},
onCreateWindow: (controller, createWindowAction) async {
if (createWindowAction.request.url
.toString()
.contains("login/google")) {
showDialog(
context: context,
builder: (context) {
return WindowPopup(
createWindowAction: createWindowAction);
},
);
}
},
shouldOverrideUrlLoading:
(controller, navigationAction) async {
// https://embedded-wallet.thirdweb.com/api/2024-05-05/login/google?clientId=f3b0d40edd0251e2ba4a9ef3a20fa268
return NavigationActionPolicy.ALLOW;
},
onLoadStop: (controller, url) async {
pullToRefreshController?.endRefreshing();
setState(() {
this.url = url.toString();
urlController.text = this.url;
});
},
onReceivedError: (controller, request, error) {
pullToRefreshController?.endRefreshing();
},
onProgressChanged: (controller, progress) {
if (progress == 100) {
pullToRefreshController?.endRefreshing();
}
setState(() {
this.progress = progress / 100;
urlController.text = url;
});
},
onUpdateVisitedHistory:
(controller, url, androidIsReload) async {
String? token = extractTokenFromUrl(url.toString());
if (token != null) {
final userCredential =
await loginWithFirebaseToken(token);
if (kDebugMode) {
print("debug: ${userCredential.user}");
}
// Clear cookies and cache. Important for forgetting the login.
await CookieManager.instance().deleteAllCookies();
await controller.clearCache();
Navigator.pop(context, token);
}
setState(() {
this.url = url.toString();
urlController.text = this.url;
});
},
onConsoleMessage: (controller, consoleMessage) {
if (kDebugMode) {
print(consoleMessage);
}
},
onReceivedHttpError: (controller, request, errorResponse) {
if (kDebugMode) {
print("albi $errorResponse");
}
},
onPageCommitVisible: (controller, url) async {
if (url != null &&
getCookieString(url.rawValue) != null) {
final cookieString = getCookieString(url.rawValue);
await loginWithFirebaseToken(cookieString!);
Navigator.pop(context);
}
}),
progress < 1.0
? LinearProgressIndicator(value: progress)
: Container(),
],
),
),
ButtonBar(
alignment: MainAxisAlignment.heart,
kids: [
ElevatedButton(
child: const Icon(Icons.arrow_back),
onPressed: () {
webViewController?.goBack();
},
),
ElevatedButton(
child: const Icon(Icons.arrow_forward),
onPressed: () {
webViewController?.goForward();
},
),
ElevatedButton(
child: const Icon(Icons.refresh),
onPressed: () {
webViewController?.reload();
},
),
],
),
])));
}
}
What I’ve Tried
- Carried out
onCreateWindow
to deal with the Google login popup - Enabled
supportMultipleWindows
andjavaScriptCanOpenWindowsAutomatically
inInAppWebViewSettings
- Checked console messages and HTTP errors, however discovered no related data
Atmosphere
- inappwebview package deal model: ^6.0.0
- Platform: iOS and Android
- Flutter physician:
[✓] Flutter (Channel steady, 3.22.1, on macOS 14.5 23F79 darwin-arm64, locale
it-IT)
• Flutter model 3.22.1 on channel steady at /Customers/albertonoris/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision a14f74ff3a (4 months in the past), 2024-05-22 11:08:21 -0500
• Engine revision 55eae6864b
• Dart model 3.4.1
• DevTools model 2.34.3
[✓] Android toolchain - develop for Android gadgets (Android SDK model
34.0.0)
• Android SDK at /Customers/albertonoris/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• Java binary at: /Purposes/Android
Studio.app/Contents/jbr/Contents/Dwelling/bin/java
• Java model OpenJDK Runtime Atmosphere (construct
17.0.9+0-17.0.9b1087.7-11185874)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
• Xcode at /Purposes/Xcode.app/Contents/Developer
• Construct 15F31d
• CocoaPods model 1.15.2
[✓] Chrome - develop for the net
• Chrome at /Purposes/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (model 2023.2)
• Android Studio at /Purposes/Android Studio.app/Contents
• Flutter plugin may be put in from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin may be put in from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java model OpenJDK Runtime Atmosphere (construct
17.0.9+0-17.0.9b1087.7-11185874)
[✓] VS Code (model 1.84.2)
• VS Code at /Customers/albertonoris/Downloads/Visible Studio
Code.app/Contents
• Flutter extension model 3.96.0
[✓] Related gadget (5 accessible)
• sdk gphone64 arm64 (cellular) • emulator-5554 •
android-arm64 • Android 14 (API 34) (emulator)
• Aifon di Albi (cellular) • 00008120-00045CEE0240C01E • ios
• iOS 17.6 21G80
• macOS (desktop) • macos •
darwin-arm64 • macOS 14.5 23F79 darwin-arm64
• Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin
• macOS 14.5 23F79 darwin-arm64
• Chrome (internet) • chrome •
web-javascript • Google Chrome 128.0.6613.120
! Error: Looking on the native space community for iPad di Alberto. Guarantee
the gadget is unlocked and hooked up with a cable or related to the
similar native space community as this Mac.
The gadget should be opted into Developer Mode to attach wirelessly.
(code -27)
[✓] Community sources
• All anticipated community sources can be found.
• No points discovered!
Any insights or options could be vastly appreciated!