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;
|
Map<String, dynamic>? _rawLoginTypes;
|
||||||
|
|
||||||
void ssoLoginAction(String id) async {
|
void ssoLoginAction(String? id) async {
|
||||||
final redirectUrl = kIsWeb
|
final redirectUrl = kIsWeb
|
||||||
? '${html.window.origin!}/web/auth.html'
|
? '${html.window.origin!}/web/auth.html'
|
||||||
: isDefaultPlatform
|
: isDefaultPlatform
|
||||||
? '${AppConfig.appOpenUrlScheme.toLowerCase()}://login'
|
? '${AppConfig.appOpenUrlScheme.toLowerCase()}://login'
|
||||||
: 'http://localhost:3001//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
|
final urlScheme = isDefaultPlatform
|
||||||
? Uri.parse(redirectUrl).scheme
|
? Uri.parse(redirectUrl).scheme
|
||||||
: "http://localhost:3001";
|
: "http://localhost:3001";
|
||||||
final result = await FlutterWebAuth2.authenticate(
|
final result = await FlutterWebAuth2.authenticate(
|
||||||
url: url,
|
url: url.toString(),
|
||||||
callbackUrlScheme: urlScheme,
|
callbackUrlScheme: urlScheme,
|
||||||
);
|
);
|
||||||
final token = Uri.parse(result).queryParameters['loginToken'];
|
final token = Uri.parse(result).queryParameters['loginToken'];
|
||||||
|
@ -144,9 +148,12 @@ class HomeserverPickerController extends State<HomeserverPicker> {
|
||||||
List<IdentityProvider>? get identityProviders {
|
List<IdentityProvider>? get identityProviders {
|
||||||
final loginTypes = _rawLoginTypes;
|
final loginTypes = _rawLoginTypes;
|
||||||
if (loginTypes == null) return null;
|
if (loginTypes == null) return null;
|
||||||
final rawProviders = loginTypes.tryGetList('flows')!.singleWhere(
|
final List? rawProviders = loginTypes.tryGetList('flows')!.singleWhere(
|
||||||
(flow) => flow['type'] == AuthenticationTypes.sso,
|
(flow) => flow['type'] == AuthenticationTypes.sso,
|
||||||
)['identity_providers'];
|
)['identity_providers'] ??
|
||||||
|
[
|
||||||
|
{'id': null},
|
||||||
|
];
|
||||||
final list = (rawProviders as List)
|
final list = (rawProviders as List)
|
||||||
.map((json) => IdentityProvider.fromJson(json))
|
.map((json) => IdentityProvider.fromJson(json))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
|
@ -124,7 +124,7 @@ class HomeserverPickerView extends StatelessWidget {
|
||||||
L10n.of(context)!.singlesignon,
|
L10n.of(context)!.singlesignon,
|
||||||
),
|
),
|
||||||
onPressed: () =>
|
onPressed: () =>
|
||||||
controller.ssoLoginAction(provider.id!),
|
controller.ssoLoginAction(provider.id),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue