@@ -134,7 +134,8 @@ class Client extends MatrixApi {
134
134
/// the cached .well-known file updated using [getWellknown]
135
135
DiscoveryInformation ? get wellKnown => _wellKnown;
136
136
137
- /// the cached OIDC auth metadata as per MSC 2965 updated using [getWellknown]
137
+ /// the cached OIDC auth metadata as per MSC 2965 updated using
138
+ /// [getOidcDiscoveryInformation]
138
139
Map <String , Object ?>? get oidcAuthMetadata => _oidcAuthMetadata;
139
140
140
141
/// the cached OIDC auth metadata as per MSC 2966
@@ -558,6 +559,7 @@ class Client extends MatrixApi {
558
559
)> checkHomeserver (
559
560
Uri homeserverUrl, {
560
561
bool checkWellKnown = true ,
562
+ bool checkOidcDiscovery = true ,
561
563
Set <String >? overrideSupportedVersions,
562
564
}) async {
563
565
final supportedVersions =
@@ -575,15 +577,22 @@ class Client extends MatrixApi {
575
577
Logs ().v ('Found no well known information' , e);
576
578
}
577
579
}
580
+ if (checkOidcDiscovery) {
581
+ try {
582
+ _oidcAuthMetadata = await getOidcDiscoveryInformation ();
583
+ } catch (e) {
584
+ Logs ().v ('[OIDC] Error checking OIDC discovery' , e);
585
+ }
586
+ }
578
587
579
588
// Check if server supports at least one supported version
580
589
final versions = await getVersions ();
581
590
if (! versions.versions
582
591
.any ((version) => supportedVersions.contains (version))) {
583
- Logs ().w (
584
- 'Server supports the versions: ${versions .toString ()} but this application is only compatible with ${supportedVersions .toString ()}.' ,
592
+ throw BadServerVersionsException (
593
+ versions.versions.toSet (),
594
+ supportedVersions,
585
595
);
586
- assert (false );
587
596
}
588
597
589
598
final loginTypes = await getLoginFlows () ?? [];
@@ -610,47 +619,16 @@ class Client extends MatrixApi {
610
619
/// Note that this endpoint is not necessarily handled by the homeserver,
611
620
/// but by another webserver, to be used for discovering the homeserver URL.
612
621
///
613
- /// In case the homeserver supports OIDC, this will also request and store
614
- /// the OIDC Auth Metadata provided by the homeserver.
615
- ///
616
622
/// The result of this call is stored in [wellKnown] for later use at runtime.
617
623
@override
618
624
Future <DiscoveryInformation > getWellknown () async {
619
- DiscoveryInformation wellKnown;
620
- try {
621
- wellKnown = await super .getWellknown ();
625
+ final wellKnown = await super .getWellknown ();
626
+
627
+ // do not reset the well known here, so super call
628
+ super .homeserver = wellKnown.mHomeserver.baseUrl.stripTrailingSlash ();
629
+ _wellKnown = wellKnown;
630
+ await database? .storeWellKnown (wellKnown);
622
631
623
- // do not reset the well known here, so super call
624
- super .homeserver = wellKnown.mHomeserver.baseUrl.stripTrailingSlash ();
625
- _wellKnown = wellKnown;
626
- await database? .storeWellKnown (wellKnown);
627
- } finally {
628
- // MSC2965 no longer expects any information on whether OIDC is supported
629
- // to be present in .well-known - the only way to figure out is sadly
630
- // calling the /auth_metadata endpoint.
631
- try {
632
- try {
633
- _oidcAuthMetadata = await getOidcAuthMetadata ();
634
- } on http.ClientException {
635
- Logs ().v (
636
- '[OIDC] auth_metadata endpoint not supported. '
637
- 'Fallback on legacy .well-known discovery.' ,
638
- );
639
- // even though no longer required, a homeserver *might* still prefer
640
- // the fallback on .well-known discovery as per
641
- // https://openid.net/specs/openid-connect-discovery-1_0.html
642
- final issuer =
643
- // ignore: deprecated_member_use_from_same_package
644
- _wellKnown? .authentication? .issuer ?? await oidcAuthIssuer ();
645
- // ignore: deprecated_member_use_from_same_package
646
- _oidcAuthMetadata = await getOidcAuthWellKnown (issuer);
647
- }
648
- await database? .storeOidcAuthMetadata (_oidcAuthMetadata);
649
- Logs ().v ('[OIDC] Found auth metadata document.' );
650
- } on http.ClientException {
651
- Logs ().v ('[OIDC] Homeserver does not support OIDC delegation.' );
652
- }
653
- }
654
632
return wellKnown;
655
633
}
656
634
@@ -1704,22 +1682,7 @@ class Client extends MatrixApi {
1704
1682
return pushrules != null ? TryGetPushRule .tryFromJson (pushrules) : null ;
1705
1683
}
1706
1684
1707
- static const Set <String > supportedVersions = {
1708
- 'v1.1' ,
1709
- 'v1.2' ,
1710
- 'v1.3' ,
1711
- 'v1.4' ,
1712
- 'v1.5' ,
1713
- 'v1.6' ,
1714
- 'v1.7' ,
1715
- 'v1.8' ,
1716
- 'v1.9' ,
1717
- 'v1.10' ,
1718
- 'v1.11' ,
1719
- 'v1.12' ,
1720
- 'v1.13' ,
1721
- };
1722
-
1685
+ static const Set <String > supportedVersions = {'v1.1' , 'v1.2' };
1723
1686
static const List <String > supportedDirectEncryptionAlgorithms = [
1724
1687
AlgorithmTypes .olmV1Curve25519AesSha2,
1725
1688
];
@@ -4091,6 +4054,16 @@ enum SyncStatus {
4091
4054
error,
4092
4055
}
4093
4056
4057
+ class BadServerVersionsException implements Exception {
4058
+ final Set <String > serverVersions, supportedVersions;
4059
+
4060
+ BadServerVersionsException (this .serverVersions, this .supportedVersions);
4061
+
4062
+ @override
4063
+ String toString () =>
4064
+ 'Server supports the versions: ${serverVersions .toString ()} but this application is only compatible with ${supportedVersions .toString ()}.' ;
4065
+ }
4066
+
4094
4067
class BadServerLoginTypesException implements Exception {
4095
4068
final Set <String > serverLoginTypes, supportedLoginTypes;
4096
4069
0 commit comments