refactor: Improved UIA support for OIDC and SSO
This commit is contained in:
parent
9dbb75dada
commit
c372f7d79f
|
|
@ -1,9 +1,11 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:extera_next/generated/l10n/l10n.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
|
||||||
|
|
||||||
|
import 'package:matrix/matrix.dart';
|
||||||
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
|
import 'package:extera_next/generated/l10n/l10n.dart';
|
||||||
import 'package:extera_next/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
|
import 'package:extera_next/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
|
||||||
import 'package:extera_next/widgets/adaptive_dialogs/show_text_input_dialog.dart';
|
import 'package:extera_next/widgets/adaptive_dialogs/show_text_input_dialog.dart';
|
||||||
import 'package:extera_next/widgets/fluffy_chat_app.dart';
|
import 'package:extera_next/widgets/fluffy_chat_app.dart';
|
||||||
|
|
@ -34,7 +36,7 @@ extension UiaRequestManager on MatrixState {
|
||||||
minLines: 1,
|
minLines: 1,
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
hintText: l10n.password,
|
hintText: L10n.of(context).password,
|
||||||
));
|
));
|
||||||
if (input == null || input.isEmpty) {
|
if (input == null || input.isEmpty) {
|
||||||
return uiaRequest.cancel();
|
return uiaRequest.cancel();
|
||||||
|
|
@ -80,24 +82,38 @@ extension UiaRequestManager on MatrixState {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
final url = Uri.parse(
|
final stageUrl = uiaRequest.params
|
||||||
'${client.homeserver}/_matrix/client/r0/auth/$stage/fallback/web?session=${uiaRequest.session}',
|
.tryGetMap<String, Object?>(stage)
|
||||||
|
?.tryGet<String>('url');
|
||||||
|
final fallbackUrl = client.homeserver!.replace(
|
||||||
|
path: '/_matrix/client/v3/auth/$stage/fallback/web',
|
||||||
|
queryParameters: {
|
||||||
|
'session': uiaRequest.session,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
final url = stageUrl != null
|
||||||
|
? (Uri.tryParse(stageUrl) ?? fallbackUrl)
|
||||||
|
: fallbackUrl;
|
||||||
|
|
||||||
|
final consent = await showOkCancelAlertDialog(
|
||||||
|
useRootNavigator: false,
|
||||||
|
title: l10n.pleaseFollowInstructionsOnWeb,
|
||||||
|
context: navigatorContext,
|
||||||
|
okLabel: l10n.open,
|
||||||
|
cancelLabel: l10n.cancel,
|
||||||
|
);
|
||||||
|
if (consent != OkCancelResult.ok) return uiaRequest.cancel();
|
||||||
|
|
||||||
|
launchUrl(url, mode: LaunchMode.inAppBrowserView);
|
||||||
|
final completer = Completer();
|
||||||
|
final listener =
|
||||||
|
AppLifecycleListener(onResume: () => completer.complete());
|
||||||
|
await completer.future;
|
||||||
|
listener.dispose();
|
||||||
|
|
||||||
|
return uiaRequest.completeStage(
|
||||||
|
AuthenticationData(session: uiaRequest.session),
|
||||||
);
|
);
|
||||||
launchUrlString(url.toString());
|
|
||||||
if (OkCancelResult.ok ==
|
|
||||||
await showOkCancelAlertDialog(
|
|
||||||
useRootNavigator: false,
|
|
||||||
title: l10n.pleaseFollowInstructionsOnWeb,
|
|
||||||
context: navigatorContext,
|
|
||||||
okLabel: l10n.next,
|
|
||||||
cancelLabel: l10n.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);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue