Merge pull request #2181 from famedly/krille/fix-fetch-auth-metadata

refactor: Add option to always call auth metadata
This commit is contained in:
Krille-chan 2025-11-10 10:27:01 +01:00 committed by GitHub
commit 5ef19c6d3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 4 deletions

View File

@ -1188,6 +1188,20 @@ class FakeMatrixApi extends BaseClient {
'errcode': 'M_FORBIDDEN',
'error': 'Blabla',
},
'/client/v1/auth_metadata': (var req) => {
'authorization_endpoint':
'https://fakeserver.notexisting/oauth2/auth',
'code_challenge_methods_supported': ['S256'],
'grant_types_supported': ['authorization_code', 'refresh_token'],
'issuer': 'https://fakeserver.notexisting/',
'registration_endpoint':
'https://fakeserver.notexisting/oauth2/clients/register',
'response_modes_supported': ['query', 'fragment'],
'response_types_supported': ['code'],
'revocation_endpoint':
'https://fakeserver.notexisting/oauth2/revoke',
'token_endpoint': 'https://fakeserver.notexisting/oauth2/token',
},
'/media/v3/preview_url?url=https%3A%2F%2Fmatrix.org&ts=10': (var req) => {
'og:title': 'Matrix Blog Post',
'og:description': 'This is a really cool blog post from matrix.org',

View File

@ -519,6 +519,13 @@ class Client extends MatrixApi {
)> checkHomeserver(
Uri homeserverUrl, {
bool checkWellKnown = true,
/// Weither this method should also call `/auth_metadata` to fetch
/// Matrix native OIDC information. Defaults to if the `/versions` endpoint
/// returns version v1.15 or higher. Set to `true` to always call the
/// endpoint if your homeserver supports the endpoint while not fully
/// supporting version v1.15 yet.
bool? fetchAuthMetadata,
Set<String>? overrideSupportedVersions,
}) async {
final supportedVersions =
@ -555,10 +562,11 @@ class Client extends MatrixApi {
);
}
fetchAuthMetadata ??= versions.versions.any(
(v) => isVersionGreaterThanOrEqualTo(v, 'v1.15'),
);
GetAuthMetadataResponse? authMetadata;
if (versions.versions.any(
(v) => isVersionGreaterThanOrEqualTo(v, 'v1.16'),
)) {
if (fetchAuthMetadata) {
try {
authMetadata = await getAuthMetadata();
} on MatrixException catch (e, s) {

View File

@ -531,9 +531,14 @@ void main() {
database: await getDatabase(),
);
await matrix.checkHomeserver(
final (_, _, _, authMetadata) = await matrix.checkHomeserver(
Uri.parse('https://fakeserver.notexisting'),
checkWellKnown: false,
fetchAuthMetadata: true,
);
expect(
authMetadata?.issuer.toString(),
'https://fakeserver.notexisting/',
);
final loginResp = await matrix.login(