fix: Close safariviewcontroller on SSO

This commit is contained in:
Christian Pauly 2021-07-15 14:04:29 +02:00
parent 480b7b45aa
commit ba685b7a1f
3 changed files with 32 additions and 11 deletions

View File

@ -1,5 +1,6 @@
import 'dart:async';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:matrix/matrix.dart';
import 'package:fluffychat/pages/views/homeserver_picker_view.dart';
import 'package:fluffychat/utils/famedlysdk_store.dart';
@ -63,6 +64,7 @@ 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);
@ -150,7 +152,7 @@ class HomeserverPickerController extends State<HomeserverPicker> {
final list = (rawProviders as List)
.map((json) => IdentityProvider.fromJson(json))
.toList();
if (!PlatformInfos.isCupertinoStyle) {
if (PlatformInfos.isCupertinoStyle) {
list.sort((a, b) => a.brand == 'apple' ? -1 : 1);
}
return list;
@ -190,6 +192,8 @@ class HomeserverPickerController extends State<HomeserverPicker> {
return _rawLoginTypes;
}
ChromeSafariBrowser browser;
static const String ssoHomeserverKey = 'sso-homeserver';
void ssoLoginAction(String id) {
@ -202,14 +206,21 @@ class HomeserverPickerController extends State<HomeserverPicker> {
final redirectUrl = kIsWeb
? AppConfig.webBaseUrl + '/#/'
: AppConfig.appOpenUrlScheme.toLowerCase() + '://login';
launch(
'${Matrix.of(context).client.homeserver?.toString()}/_matrix/client/r0/login/sso/redirect/${Uri.encodeComponent(id)}?redirectUrl=${Uri.encodeQueryComponent(redirectUrl)}',
forceSafariVC: false,
);
final url =
'${Matrix.of(context).client.homeserver?.toString()}/_matrix/client/r0/login/sso/redirect/${Uri.encodeComponent(id)}?redirectUrl=${Uri.encodeQueryComponent(redirectUrl)}';
if (PlatformInfos.isIOS) {
browser ??= ChromeSafariBrowser();
browser.open(url: Uri.parse(url));
} else {
launch(redirectUrl, forceWebView: true);
}
}
void signUpAction() => launch(
'${Matrix.of(context).client.homeserver?.toString()}/_matrix/static/client/register');
'${Matrix.of(context).client.homeserver?.toString()}/_matrix/static/client/register',
forceSafariVC: true,
forceWebView: true,
);
bool _initialized = false;

View File

@ -365,6 +365,13 @@ 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:
@ -551,10 +558,12 @@ packages:
image_picker:
dependency: "direct main"
description:
name: image_picker
url: "https://pub.dartlang.org"
source: hosted
version: "0.8.1+3"
path: "packages/image_picker/image_picker"
ref: image_picker_camera_on_android11
resolved-ref: "6cfc8b8812a71e4eb3480110298d9487da75c560"
url: "https://gitlab.com/famedly/company/frontend/flutter-plugins.git"
source: git
version: "0.8.1+4"
image_picker_for_web:
dependency: transitive
description:

View File

@ -1,7 +1,7 @@
name: fluffychat
description: Chat with your friends.
publish_to: none
version: 0.34.1+0
version: 0.34.1+1
environment:
sdk: ">=2.6.0 <3.0.0"
@ -27,6 +27,7 @@ dependencies:
flutter_app_lock: ^1.5.0
flutter_blurhash: ^0.6.0
flutter_cache_manager: ^3.1.2
flutter_inappwebview: ^5.3.2
flutter_local_notifications: ^6.0.0
flutter_localizations:
sdk: flutter