refactor: SSO Login and remove flutter in app view

This commit is contained in:
Christian Pauly 2022-02-14 15:59:10 +01:00 committed by Krille Fear
parent 9bd8b6aa44
commit 24ea7daccf
4 changed files with 18 additions and 79 deletions

View File

@ -4,11 +4,9 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_web_auth/flutter_web_auth.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:matrix/matrix.dart';
import 'package:uni_links/uni_links.dart';
import 'package:universal_html/html.dart' as html;
import 'package:vrouter/vrouter.dart';
@ -18,7 +16,6 @@ import 'package:fluffychat/pages/homeserver_picker/homeserver_picker_view.dart';
import 'package:fluffychat/utils/famedlysdk_store.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/widgets/matrix.dart';
import '../../main.dart';
import '../../utils/localized_exception_extension.dart';
class HomeserverPicker extends StatefulWidget {
@ -67,34 +64,9 @@ class HomeserverPickerController extends State<HomeserverPicker> {
);
}
void _processIncomingUris(String? text) async {
if (text == null || !text.startsWith(AppConfig.appOpenUrlScheme)) return;
await browser?.close();
VRouter.of(context).to('/home');
final token = Uri.parse(text).queryParameters['loginToken'];
if (token != null) _loginWithToken(token);
}
void _initReceiveUri() {
if (!PlatformInfos.isMobile) return;
// For receiving shared Uris
_intentDataStreamSubscription = linkStream.listen(_processIncomingUris);
if (FluffyChatApp.gotInitialLink == false) {
FluffyChatApp.gotInitialLink = true;
getInitialLink().then(_processIncomingUris);
}
}
@override
void initState() {
super.initState();
_initReceiveUri();
if (kIsWeb) {
WidgetsBinding.instance!.addPostFrameCallback((_) {
final token = Matrix.of(context).widget.queryParameters!['loginToken'];
if (token != null) _loginWithToken(token);
});
}
checkHomeserverAction();
}
@ -198,8 +170,6 @@ class HomeserverPickerController extends State<HomeserverPicker> {
.tryGetList('flows')!
.any((flow) => flow['type'] == AuthenticationTypes.sso);
ChromeSafariBrowser? browser;
static const String ssoHomeserverKey = 'sso-homeserver';
void ssoLoginAction(String id) async {

View File

@ -2,11 +2,9 @@ import 'dart:async';
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:matrix/matrix.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/widgets/matrix.dart';
extension UiaRequestManager on MatrixState {
@ -84,21 +82,11 @@ extension UiaRequestManager on MatrixState {
default:
final url = Uri.parse(client.homeserver.toString() +
'/_matrix/client/r0/auth/$stage/fallback/web?session=${uiaRequest.session}');
if (PlatformInfos.isMobile) {
final browser = UiaFallbackBrowser();
browser.addMenuItem(
ChromeSafariBrowserMenuItem(
action: (_, __) {
uiaRequest.cancel();
},
label: L10n.of(context)!.cancel,
id: 0,
),
launch(
url.toString(),
forceSafariVC: true,
forceWebView: true,
);
await browser.open(url: url);
await browser.whenClosed.stream.first;
} else {
launch(url.toString());
if (OkCancelResult.ok ==
await showOkCancelAlertDialog(
useRootNavigator: false,
@ -114,10 +102,6 @@ extension UiaRequestManager on MatrixState {
return uiaRequest.cancel();
}
}
await uiaRequest.completeStage(
AuthenticationData(session: uiaRequest.session),
);
}
} catch (e, s) {
Logs().e('Error while background UIA', e, s);
return uiaRequest.cancel(e is Exception ? e : Exception(e));
@ -133,10 +117,3 @@ class UiaException implements Exception {
@override
String toString() => reason;
}
class UiaFallbackBrowser extends ChromeSafariBrowser {
final StreamController<bool> whenClosed = StreamController<bool>.broadcast();
@override
onClosed() => whenClosed.add(true);
}

View File

@ -405,13 +405,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.0"
flutter_inappwebview:
dependency: "direct main"
description:
name: flutter_inappwebview
url: "https://pub.dartlang.org"
source: hosted
version: "5.3.2"
flutter_keyboard_visibility:
dependency: transitive
description:

View File

@ -30,7 +30,6 @@ dependencies:
flutter_app_lock: ^2.0.0
flutter_blurhash: ^0.6.0
flutter_cache_manager: ^3.1.2
flutter_inappwebview: ^5.3.2
flutter_local_notifications: ^8.2.0
flutter_localizations:
sdk: flutter