mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-24 22:42:33 +01:00
refactor: SSO Login and remove flutter in app view
This commit is contained in:
parent
9bd8b6aa44
commit
24ea7daccf
@ -4,11 +4,9 @@ import 'package:flutter/foundation.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.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:flutter_web_auth/flutter_web_auth.dart';
|
||||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:uni_links/uni_links.dart';
|
|
||||||
import 'package:universal_html/html.dart' as html;
|
import 'package:universal_html/html.dart' as html;
|
||||||
import 'package:vrouter/vrouter.dart';
|
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/famedlysdk_store.dart';
|
||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
import '../../main.dart';
|
|
||||||
import '../../utils/localized_exception_extension.dart';
|
import '../../utils/localized_exception_extension.dart';
|
||||||
|
|
||||||
class HomeserverPicker extends StatefulWidget {
|
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
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_initReceiveUri();
|
|
||||||
if (kIsWeb) {
|
|
||||||
WidgetsBinding.instance!.addPostFrameCallback((_) {
|
|
||||||
final token = Matrix.of(context).widget.queryParameters!['loginToken'];
|
|
||||||
if (token != null) _loginWithToken(token);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
checkHomeserverAction();
|
checkHomeserverAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,8 +170,6 @@ class HomeserverPickerController extends State<HomeserverPicker> {
|
|||||||
.tryGetList('flows')!
|
.tryGetList('flows')!
|
||||||
.any((flow) => flow['type'] == AuthenticationTypes.sso);
|
.any((flow) => flow['type'] == AuthenticationTypes.sso);
|
||||||
|
|
||||||
ChromeSafariBrowser? browser;
|
|
||||||
|
|
||||||
static const String ssoHomeserverKey = 'sso-homeserver';
|
static const String ssoHomeserverKey = 'sso-homeserver';
|
||||||
|
|
||||||
void ssoLoginAction(String id) async {
|
void ssoLoginAction(String id) async {
|
||||||
|
@ -2,11 +2,9 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
|
|
||||||
extension UiaRequestManager on MatrixState {
|
extension UiaRequestManager on MatrixState {
|
||||||
@ -84,39 +82,25 @@ extension UiaRequestManager on MatrixState {
|
|||||||
default:
|
default:
|
||||||
final url = Uri.parse(client.homeserver.toString() +
|
final url = Uri.parse(client.homeserver.toString() +
|
||||||
'/_matrix/client/r0/auth/$stage/fallback/web?session=${uiaRequest.session}');
|
'/_matrix/client/r0/auth/$stage/fallback/web?session=${uiaRequest.session}');
|
||||||
if (PlatformInfos.isMobile) {
|
launch(
|
||||||
final browser = UiaFallbackBrowser();
|
url.toString(),
|
||||||
browser.addMenuItem(
|
forceSafariVC: true,
|
||||||
ChromeSafariBrowserMenuItem(
|
forceWebView: true,
|
||||||
action: (_, __) {
|
|
||||||
uiaRequest.cancel();
|
|
||||||
},
|
|
||||||
label: L10n.of(context)!.cancel,
|
|
||||||
id: 0,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
await browser.open(url: url);
|
|
||||||
await browser.whenClosed.stream.first;
|
|
||||||
} else {
|
|
||||||
launch(url.toString());
|
|
||||||
if (OkCancelResult.ok ==
|
|
||||||
await showOkCancelAlertDialog(
|
|
||||||
useRootNavigator: false,
|
|
||||||
message: L10n.of(context)!.pleaseFollowInstructionsOnWeb,
|
|
||||||
context: navigatorContext,
|
|
||||||
okLabel: L10n.of(context)!.next,
|
|
||||||
cancelLabel: L10n.of(context)!.cancel,
|
|
||||||
)) {
|
|
||||||
return uiaRequest.completeStage(
|
|
||||||
AuthenticationData(session: uiaRequest.session),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return uiaRequest.cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await uiaRequest.completeStage(
|
|
||||||
AuthenticationData(session: uiaRequest.session),
|
|
||||||
);
|
);
|
||||||
|
if (OkCancelResult.ok ==
|
||||||
|
await showOkCancelAlertDialog(
|
||||||
|
useRootNavigator: false,
|
||||||
|
message: L10n.of(context)!.pleaseFollowInstructionsOnWeb,
|
||||||
|
context: navigatorContext,
|
||||||
|
okLabel: L10n.of(context)!.next,
|
||||||
|
cancelLabel: L10n.of(context)!.cancel,
|
||||||
|
)) {
|
||||||
|
return uiaRequest.completeStage(
|
||||||
|
AuthenticationData(session: uiaRequest.session),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return uiaRequest.cancel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logs().e('Error while background UIA', e, s);
|
Logs().e('Error while background UIA', e, s);
|
||||||
@ -133,10 +117,3 @@ class UiaException implements Exception {
|
|||||||
@override
|
@override
|
||||||
String toString() => reason;
|
String toString() => reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
class UiaFallbackBrowser extends ChromeSafariBrowser {
|
|
||||||
final StreamController<bool> whenClosed = StreamController<bool>.broadcast();
|
|
||||||
|
|
||||||
@override
|
|
||||||
onClosed() => whenClosed.add(true);
|
|
||||||
}
|
|
||||||
|
@ -405,13 +405,6 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.7.0"
|
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:
|
flutter_keyboard_visibility:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -30,7 +30,6 @@ dependencies:
|
|||||||
flutter_app_lock: ^2.0.0
|
flutter_app_lock: ^2.0.0
|
||||||
flutter_blurhash: ^0.6.0
|
flutter_blurhash: ^0.6.0
|
||||||
flutter_cache_manager: ^3.1.2
|
flutter_cache_manager: ^3.1.2
|
||||||
flutter_inappwebview: ^5.3.2
|
|
||||||
flutter_local_notifications: ^8.2.0
|
flutter_local_notifications: ^8.2.0
|
||||||
flutter_localizations:
|
flutter_localizations:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
Loading…
Reference in New Issue
Block a user