mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-10 13:05:11 +00:00
fix: SSO with no identity providers
This commit is contained in:
parent
c0ee1bbdfc
commit
1e4147e31c
2 changed files with 15 additions and 8 deletions
|
@ -113,19 +113,23 @@ class HomeserverPickerController extends State<HomeserverPicker> {
|
|||
|
||||
Map<String, dynamic>? _rawLoginTypes;
|
||||
|
||||
void ssoLoginAction(String id) async {
|
||||
void ssoLoginAction(String? id) async {
|
||||
final redirectUrl = kIsWeb
|
||||
? '${html.window.origin!}/web/auth.html'
|
||||
: isDefaultPlatform
|
||||
? '${AppConfig.appOpenUrlScheme.toLowerCase()}://login'
|
||||
: 'http://localhost:3001//login';
|
||||
final url =
|
||||
'${Matrix.of(context).getLoginClient().homeserver?.toString()}/_matrix/client/r0/login/sso/redirect/${Uri.encodeComponent(id)}?redirectUrl=${Uri.encodeQueryComponent(redirectUrl)}';
|
||||
|
||||
final url = Matrix.of(context).getLoginClient().homeserver!.replace(
|
||||
path: '/_matrix/client/r0/login/sso/redirect${id == null ? '' : '/$id'}',
|
||||
queryParameters: {'redirectUrl': redirectUrl},
|
||||
);
|
||||
|
||||
final urlScheme = isDefaultPlatform
|
||||
? Uri.parse(redirectUrl).scheme
|
||||
: "http://localhost:3001";
|
||||
final result = await FlutterWebAuth2.authenticate(
|
||||
url: url,
|
||||
url: url.toString(),
|
||||
callbackUrlScheme: urlScheme,
|
||||
);
|
||||
final token = Uri.parse(result).queryParameters['loginToken'];
|
||||
|
@ -144,9 +148,12 @@ class HomeserverPickerController extends State<HomeserverPicker> {
|
|||
List<IdentityProvider>? get identityProviders {
|
||||
final loginTypes = _rawLoginTypes;
|
||||
if (loginTypes == null) return null;
|
||||
final rawProviders = loginTypes.tryGetList('flows')!.singleWhere(
|
||||
(flow) => flow['type'] == AuthenticationTypes.sso,
|
||||
)['identity_providers'];
|
||||
final List? rawProviders = loginTypes.tryGetList('flows')!.singleWhere(
|
||||
(flow) => flow['type'] == AuthenticationTypes.sso,
|
||||
)['identity_providers'] ??
|
||||
[
|
||||
{'id': null},
|
||||
];
|
||||
final list = (rawProviders as List)
|
||||
.map((json) => IdentityProvider.fromJson(json))
|
||||
.toList();
|
||||
|
|
|
@ -124,7 +124,7 @@ class HomeserverPickerView extends StatelessWidget {
|
|||
L10n.of(context)!.singlesignon,
|
||||
),
|
||||
onPressed: () =>
|
||||
controller.ssoLoginAction(provider.id!),
|
||||
controller.ssoLoginAction(provider.id),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
Loading…
Reference in a new issue