mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-02-17 14:30:40 +01:00
fix: SSO in web
This commit is contained in:
parent
9a01b42874
commit
62a4eebb86
@ -5,10 +5,11 @@ 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_inappwebview/flutter_inappwebview.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:uni_links/uni_links.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:universal_html/html.dart' as html;
|
||||||
import 'package:vrouter/vrouter.dart';
|
import 'package:vrouter/vrouter.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/config/app_config.dart';
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
@ -201,7 +202,7 @@ class HomeserverPickerController extends State<HomeserverPicker> {
|
|||||||
|
|
||||||
static const String ssoHomeserverKey = 'sso-homeserver';
|
static const String ssoHomeserverKey = 'sso-homeserver';
|
||||||
|
|
||||||
void ssoLoginAction(String id) {
|
void ssoLoginAction(String id) async {
|
||||||
if (kIsWeb) {
|
if (kIsWeb) {
|
||||||
// We store the homserver in the local storage instead of a redirect
|
// We store the homserver in the local storage instead of a redirect
|
||||||
// parameter because of possible CSRF attacks.
|
// parameter because of possible CSRF attacks.
|
||||||
@ -209,16 +210,15 @@ class HomeserverPickerController extends State<HomeserverPicker> {
|
|||||||
Matrix.of(context).getLoginClient().homeserver.toString());
|
Matrix.of(context).getLoginClient().homeserver.toString());
|
||||||
}
|
}
|
||||||
final redirectUrl = kIsWeb
|
final redirectUrl = kIsWeb
|
||||||
? AppConfig.webBaseUrl + '/#/'
|
? html.window.origin! + '/web/auth.html'
|
||||||
: AppConfig.appOpenUrlScheme.toLowerCase() + '://login';
|
: AppConfig.appOpenUrlScheme.toLowerCase() + '://login';
|
||||||
final url =
|
final url =
|
||||||
'${Matrix.of(context).getLoginClient().homeserver?.toString()}/_matrix/client/r0/login/sso/redirect/${Uri.encodeComponent(id)}?redirectUrl=${Uri.encodeQueryComponent(redirectUrl)}';
|
'${Matrix.of(context).getLoginClient().homeserver?.toString()}/_matrix/client/r0/login/sso/redirect/${Uri.encodeComponent(id)}?redirectUrl=${Uri.encodeQueryComponent(redirectUrl)}';
|
||||||
if (PlatformInfos.isMobile) {
|
final urlScheme = Uri.parse(redirectUrl).scheme;
|
||||||
browser ??= ChromeSafariBrowser();
|
final result = await FlutterWebAuth.authenticate(
|
||||||
browser!.open(url: Uri.parse(url));
|
url: url, callbackUrlScheme: urlScheme);
|
||||||
} else {
|
final token = Uri.parse(result).queryParameters['loginToken'];
|
||||||
launch(redirectUrl);
|
if (token != null) _loginWithToken(token);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void signUpAction() => VRouter.of(context).to(
|
void signUpAction() => VRouter.of(context).to(
|
||||||
|
11
pubspec.lock
11
pubspec.lock
@ -576,6 +576,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.2.4"
|
version: "3.2.4"
|
||||||
|
flutter_web_auth:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: flutter_web_auth
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.4.0"
|
||||||
flutter_web_plugins:
|
flutter_web_plugins:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description: flutter
|
description: flutter
|
||||||
@ -1572,7 +1579,7 @@ packages:
|
|||||||
name: url_launcher_web
|
name: url_launcher_web
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.6"
|
version: "2.0.8"
|
||||||
url_launcher_windows:
|
url_launcher_windows:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -1757,4 +1764,4 @@ packages:
|
|||||||
version: "3.1.0"
|
version: "3.1.0"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.15.1 <3.0.0"
|
dart: ">=2.15.1 <3.0.0"
|
||||||
flutter: ">=2.8.0"
|
flutter: ">=2.10.0"
|
||||||
|
@ -42,6 +42,7 @@ dependencies:
|
|||||||
flutter_slidable: ^1.1.0
|
flutter_slidable: ^1.1.0
|
||||||
flutter_svg: ^0.22.0
|
flutter_svg: ^0.22.0
|
||||||
flutter_typeahead: ^3.2.1
|
flutter_typeahead: ^3.2.1
|
||||||
|
flutter_web_auth: ^0.4.0
|
||||||
future_loading_dialog: ^0.2.2
|
future_loading_dialog: ^0.2.2
|
||||||
geolocator: ^7.6.2
|
geolocator: ^7.6.2
|
||||||
hive_flutter: ^1.1.0
|
hive_flutter: ^1.1.0
|
||||||
|
14
web/auth.html
Normal file
14
web/auth.html
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<head>
|
||||||
|
<title>Authentication complete</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>Authentication is complete. If this does not happen automatically, please
|
||||||
|
close the window.
|
||||||
|
<script>
|
||||||
|
window.opener.postMessage({
|
||||||
|
'flutter-web-auth': window.location.href
|
||||||
|
}, window.location.origin);
|
||||||
|
window.close();
|
||||||
|
</script>
|
||||||
|
</body>
|
Loading…
x
Reference in New Issue
Block a user