Skip to content

Fixed a google sign-in issue #1411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 27 additions & 30 deletions lib/widgets/login.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async';

import 'package:flutter/foundation.dart';
//import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:url_launcher/url_launcher.dart';
Expand Down Expand Up @@ -333,43 +333,40 @@ class _LoginPageState extends State<LoginPage> {
});
}
}

// Fixed misbehavior
Future<void> _beginWebAuth(ExternalAuthenticationMethod method) async {
__otp = generateOtp();
__otp = generateOtp(); // Ensure OTP is generated

if (_otp == null || _otp!.isEmpty) {
debugLog('Error: OTP generation failed');
return;
}

try {
final url = widget.serverSettings.realmUrl.resolve(method.loginUrl)
.replace(queryParameters: {'mobile_flow_otp': _otp!});
// Construct the authentication URL
final Uri authUrl = widget.serverSettings.realmUrl.resolve(method.loginUrl)
.replace(queryParameters: {'mobile_flow_otp': _otp!});

// Could set [_inProgress]… but we'd need to unset it if the web-auth
// attempt is aborted (by the user closing the browser, for example),
// and I don't think we can reliably know when that happens.
await ZulipBinding.instance.launchUrl(url, mode: LaunchMode.inAppBrowserView);
} catch (e) {
assert(debugLog(e.toString()));
// Log the authentication URL
debugLog('Opening authentication URL: $authUrl');

if (e is PlatformException
&& defaultTargetPlatform == TargetPlatform.iOS
&& e.message != null && e.message!.startsWith('Error while launching')) {
// Ignore; I've seen this on my iPhone even when auth succeeds.
// Specifically, Apple web auth…which on iOS should be replaced by
// Apple native auth; that's #462.
// Possibly related:
// https://github.com/flutter/flutter/issues/91660
// but in that issue, people report authentication not succeeding.
// TODO(#462) remove this?
return;
}
// Always use external browser to prevent "Open With" popup
await ZulipBinding.instance.launchUrl(
authUrl,
mode: LaunchMode.externalApplication,
);
} catch (e, stackTrace) {
debugLog('Error during web auth: $e\nStackTrace: $stackTrace');

if (!mounted) return;
final zulipLocalizations = ZulipLocalizations.of(context);

String message = zulipLocalizations.errorWebAuthOperationalError;
if (e is PlatformException && e.message != null) {
message = e.message!;
}
showErrorDialog(context: context,
// Show an error message to the user
final zulipLocalizations = ZulipLocalizations.of(context);
showErrorDialog(
context: context,
title: zulipLocalizations.errorWebAuthOperationalErrorTitle,
message: message);
message: zulipLocalizations.errorWebAuthOperationalError,
);
}
}

Expand Down
6 changes: 6 additions & 0 deletions packages/zulip_plugin/pubspec.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages: {}
sdks:
dart: ">=3.4.0-256.0.dev <4.0.0"
flutter: ">=3.3.0"
Loading