Update the SDK, handling OIDC/OAuth API breaks. (#5497)

Update the SDK handling API breaks.
This commit is contained in:
Doug
2026-04-27 14:46:53 +01:00
committed by GitHub
parent 0087b5a4e5
commit 7bce116d9e
13 changed files with 363 additions and 214 deletions
@@ -72,8 +72,8 @@ class AuthenticationService: AuthenticationServiceProtocol {
let client = try await makeClient(homeserverAddress: homeserverAddress)
let loginDetails = await client.homeserverLoginDetails()
homeserver.loginMode = if loginDetails.supportsOidcLogin() {
.oidc(supportsCreatePrompt: loginDetails.supportedOidcPrompts().contains(.create))
homeserver.loginMode = if loginDetails.supportsOauthLogin() {
.oidc(supportsCreatePrompt: loginDetails.supportedOauthPrompts().contains(.create))
} else if loginDetails.supportsPasswordLogin() {
.password
} else {
@@ -110,11 +110,11 @@ class AuthenticationService: AuthenticationServiceProtocol {
do {
// The create prompt is broken: https://github.com/element-hq/matrix-authentication-service/issues/3429
// let prompt: OidcPrompt = flow == .register ? .create : .consent
let oidcData = try await client.urlForOidc(oidcConfiguration: appSettings.oidcConfiguration.rustValue,
prompt: .consent,
loginHint: loginHint,
deviceId: nil,
additionalScopes: nil)
let oidcData = try await client.urlForOauth(oauthConfiguration: appSettings.oidcConfiguration.rustValue,
prompt: .consent,
loginHint: loginHint,
deviceId: nil,
additionalScopes: nil)
return .success(OIDCAuthorizationDataProxy(underlyingData: oidcData))
} catch {
MXLog.error("Failed to get URL for OIDC login: \(error)")
@@ -125,16 +125,16 @@ class AuthenticationService: AuthenticationServiceProtocol {
func abortOIDCLogin(data: OIDCAuthorizationDataProxy) async {
guard let client else { return }
MXLog.info("Aborting OIDC login.")
await client.abortOidcAuth(authorizationData: data.underlyingData)
await client.abortOauthAuth(authorizationData: data.underlyingData)
}
func loginWithOIDCCallback(_ callbackURL: URL) async -> Result<UserSessionProtocol, AuthenticationServiceError> {
guard let client else { return .failure(.failedLoggingIn) }
do {
try await client.loginWithOidcCallback(callbackUrl: callbackURL.absoluteString)
try await client.loginWithOauthCallback(callbackUrl: callbackURL.absoluteString)
await verifyClientIfPossible(client: client)
return await userSession(for: client)
} catch OidcError.Cancelled {
} catch OAuthError.Cancelled {
return .failure(.oidcError(.userCancellation))
} catch {
MXLog.error("Login with OIDC failed: \(error)")
@@ -206,7 +206,7 @@ class AuthenticationService: AuthenticationServiceProtocol {
Task {
do {
let client = try await makeClient(homeserverAddress: scannedServerNameOrBaseUrl)
let qrCodeHandler = client.newLoginWithQrCodeHandler(oidcConfiguration: appSettings.oidcConfiguration.rustValue)
let qrCodeHandler = client.newLoginWithQrCodeHandler(oauthConfiguration: appSettings.oidcConfiguration.rustValue)
try await qrCodeHandler.scan(qrCodeData: qrData, progressListener: listener)
// Since the QR code login flow includes verification.
@@ -284,7 +284,7 @@ class AuthenticationService: AuthenticationServiceProtocol {
appSettings: appSettings,
appHooks: appHooks)
let loginDetails = await client.homeserverLoginDetails()
let isServerSupported = loginDetails.supportsOidcLogin() || loginDetails.supportsPasswordLogin()
let isServerSupported = loginDetails.supportsOauthLogin() || loginDetails.supportsPasswordLogin()
MXLog.info("Classic app homeserver supported: \(isServerSupported)")
classicAppAccount.state.isServerSupported = isServerSupported
@@ -370,7 +370,7 @@ private extension HumanQrLoginError {
.qrCodeError(.deviceNotSignedIn)
case .UnsupportedQrCodeType:
.qrCodeError(.invalidQRCode)
case .Unknown, .OidcMetadataInvalid, .CheckCodeAlreadySent, .CheckCodeCannotBeSent:
case .Unknown, .OAuthMetadataInvalid, .CheckCodeAlreadySent, .CheckCodeCannotBeSent:
.qrCodeError(.unknown)
}
}
@@ -77,7 +77,7 @@ extension MatrixRustSDK.Session: @retroactive Codable {
userId: container.decode(String.self, forKey: .userId),
deviceId: container.decode(String.self, forKey: .deviceId),
homeserverUrl: container.decode(String.self, forKey: .homeserverUrl),
oidcData: container.decodeIfPresent(String.self, forKey: .oidcData),
oauthData: container.decodeIfPresent(String.self, forKey: .oidcData),
slidingSyncVersion: .native)
}
@@ -88,7 +88,7 @@ extension MatrixRustSDK.Session: @retroactive Codable {
try container.encode(userId, forKey: .userId)
try container.encode(deviceId, forKey: .deviceId)
try container.encode(homeserverUrl, forKey: .homeserverUrl)
try container.encode(oidcData, forKey: .oidcData)
try container.encode(oauthData, forKey: .oidcData)
}
enum CodingKeys: String, CodingKey {