Use identity server from well-known when creating the client

This commit is contained in:
ismailgulek
2022-06-03 18:08:19 +03:00
parent 7fc9e993be
commit ccd3befbbf
3 changed files with 52 additions and 4 deletions
@@ -186,14 +186,24 @@ class AuthenticationService: NSObject {
MXLog.error("[AuthenticationService] Unable to create a URL from the supplied homeserver address when calling loginFlow.")
throw AuthenticationError.invalidHomeserver
}
var identityServerURL: URL?
if let wellKnown = try? await wellKnown(for: homeserverURL),
let baseURL = URL(string: wellKnown.homeServer.baseUrl) {
homeserverURL = baseURL
if let wellKnown = try? await wellKnown(for: homeserverURL) {
if let baseURL = URL(string: wellKnown.homeServer.baseUrl) {
homeserverURL = baseURL
}
if let identityServer = wellKnown.identityServer,
let baseURL = URL(string: identityServer.baseUrl) {
identityServerURL = baseURL
}
}
#warning("Add an unrecognized certificate handler.")
let client = MXRestClient(homeServer: homeserverURL, unrecognizedCertificateHandler: nil)
if let identityServerURL = identityServerURL {
client.identityServer = identityServerURL.absoluteString
}
let loginFlow = try await getLoginFlowResult(client: client)