Rename OIDC to OAuth. (#5525)

* Rename OIDC to OAuth.

* Update the enterprise submodule.
This commit is contained in:
Doug
2026-05-05 14:07:06 +01:00
committed by GitHub
parent 50f4022b7c
commit fe6c62b60f
57 changed files with 402 additions and 400 deletions

View File

@@ -73,7 +73,7 @@ class AuthenticationService: AuthenticationServiceProtocol {
let loginDetails = await client.homeserverLoginDetails()
homeserver.loginMode = if loginDetails.supportsOauthLogin() {
.oidc(supportsCreatePrompt: loginDetails.supportedOauthPrompts().contains(.create))
.oAuth(supportsCreatePrompt: loginDetails.supportedOauthPrompts().contains(.create))
} else if loginDetails.supportsPasswordLogin() {
.password
} else {
@@ -83,7 +83,7 @@ class AuthenticationService: AuthenticationServiceProtocol {
if flow == .login, homeserver.loginMode == .unsupported {
return .failure(.loginNotSupported)
}
if flow == .register, !homeserver.loginMode.supportsOIDCFlow {
if flow == .register, !homeserver.loginMode.supportsOAuthFlow {
return .failure(.registrationNotSupported)
}
@@ -105,39 +105,39 @@ class AuthenticationService: AuthenticationServiceProtocol {
}
}
func urlForOIDCLogin(loginHint: String?) async -> Result<OIDCAuthorizationDataProxy, AuthenticationServiceError> {
guard let client else { return .failure(.oidcError(.urlFailure)) }
func urlForOAuthLogin(loginHint: String?) async -> Result<OAuthAuthorizationDataProxy, AuthenticationServiceError> {
guard let client else { return .failure(.oAuthError(.urlFailure)) }
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.urlForOauth(oauthConfiguration: appSettings.oidcConfiguration.rustValue,
prompt: .consent,
loginHint: loginHint,
deviceId: nil,
additionalScopes: nil)
return .success(OIDCAuthorizationDataProxy(underlyingData: oidcData))
// let prompt: OAuthPrompt = flow == .register ? .create : .consent
let oAuthData = try await client.urlForOauth(oauthConfiguration: appSettings.oAuthConfiguration.rustValue,
prompt: .consent,
loginHint: loginHint,
deviceId: nil,
additionalScopes: nil)
return .success(OAuthAuthorizationDataProxy(underlyingData: oAuthData))
} catch {
MXLog.error("Failed to get URL for OIDC login: \(error)")
return .failure(.oidcError(.urlFailure))
MXLog.error("Failed to get URL for OAuth login: \(error)")
return .failure(.oAuthError(.urlFailure))
}
}
func abortOIDCLogin(data: OIDCAuthorizationDataProxy) async {
func abortOAuthLogin(data: OAuthAuthorizationDataProxy) async {
guard let client else { return }
MXLog.info("Aborting OIDC login.")
MXLog.info("Aborting OAuth login.")
await client.abortOauthAuth(authorizationData: data.underlyingData)
}
func loginWithOIDCCallback(_ callbackURL: URL) async -> Result<UserSessionProtocol, AuthenticationServiceError> {
func loginWithOAuthCallback(_ callbackURL: URL) async -> Result<UserSessionProtocol, AuthenticationServiceError> {
guard let client else { return .failure(.failedLoggingIn) }
do {
try await client.loginWithOauthCallback(callbackUrl: callbackURL.absoluteString)
await verifyClientIfPossible(client: client)
return await userSession(for: client)
} catch OAuthError.Cancelled {
return .failure(.oidcError(.userCancellation))
} catch MatrixRustSDK.OAuthError.Cancelled {
return .failure(.oAuthError(.userCancellation))
} catch {
MXLog.error("Login with OIDC failed: \(error)")
MXLog.error("Login with OAuth failed: \(error)")
return .failure(.failedLoggingIn)
}
}
@@ -149,7 +149,7 @@ class AuthenticationService: AuthenticationServiceProtocol {
let refreshToken = try? client.session().refreshToken
if refreshToken != nil {
MXLog.warning("Refresh token found for a non oidc session, can't restore session, logging out")
MXLog.warning("Refresh token found for a non OAuth session, can't restore session, logging out")
_ = try? await client.logout()
return .failure(.sessionTokenRefreshNotSupported)
}
@@ -206,7 +206,7 @@ class AuthenticationService: AuthenticationServiceProtocol {
Task {
do {
let client = try await makeClient(homeserverAddress: scannedServerNameOrBaseUrl)
let qrCodeHandler = client.newLoginWithQrCodeHandler(oauthConfiguration: appSettings.oidcConfiguration.rustValue)
let qrCodeHandler = client.newLoginWithQrCodeHandler(oauthConfiguration: appSettings.oAuthConfiguration.rustValue)
try await qrCodeHandler.scan(qrCodeData: qrData, progressListener: listener)
// Since the QR code login flow includes verification.
@@ -273,7 +273,7 @@ class AuthenticationService: AuthenticationServiceProtocol {
// MARK: - Classic App
/// Populates the Classic app account's state by checking whether the account's homeserver is supported
/// (has Sliding Sync and OIDC or password login) and whether all of the required secrets are available.
/// (has Sliding Sync and OAuth or password login) and whether all of the required secrets are available.
func setupClassicAppAccountState() async {
guard let classicAppAccount, classicAppAccount.state.isServerSupported == nil else { return }
MXLog.info("Checking Classic app account: \(classicAppAccount)")

View File

@@ -19,8 +19,8 @@ enum AuthenticationFlow {
}
enum AuthenticationServiceError: Error, Equatable {
/// An error occurred during OIDC authentication.
case oidcError(OIDCError)
/// An error occurred during OAuth authentication.
case oAuthError(OAuthError)
/// An error occurred during login with QR Code.
case qrCodeError(QRCodeLoginError)
@@ -46,12 +46,12 @@ protocol AuthenticationServiceProtocol: QRCodeLoginServiceProtocol {
/// Sets up the service for login on the specified homeserver address.
func configure(for homeserverAddress: String, flow: AuthenticationFlow) async -> Result<Void, AuthenticationServiceError>
/// Performs login using OIDC for the current homeserver.
func urlForOIDCLogin(loginHint: String?) async -> Result<OIDCAuthorizationDataProxy, AuthenticationServiceError>
/// Asks the SDK to abort an ongoing OIDC login if we didn't get a callback to complete the request with.
func abortOIDCLogin(data: OIDCAuthorizationDataProxy) async
/// Completes an OIDC login that was started using ``urlForOIDCLogin``.
func loginWithOIDCCallback(_ callbackURL: URL) async -> Result<UserSessionProtocol, AuthenticationServiceError>
/// Performs login using OAuth for the current homeserver.
func urlForOAuthLogin(loginHint: String?) async -> Result<OAuthAuthorizationDataProxy, AuthenticationServiceError>
/// Asks the SDK to abort an ongoing OAuth login if we didn't get a callback to complete the request with.
func abortOAuthLogin(data: OAuthAuthorizationDataProxy) async
/// Completes an OAuth login that was started using ``urlForOAuthLogin``.
func loginWithOAuthCallback(_ callbackURL: URL) async -> Result<UserSessionProtocol, AuthenticationServiceError>
/// Performs a password login using the current homeserver.
func login(username: String, password: String, initialDeviceName: String?, deviceID: String?) async -> Result<UserSessionProtocol, AuthenticationServiceError>
@@ -70,25 +70,25 @@ protocol AuthenticationServiceProtocol: QRCodeLoginServiceProtocol {
func refreshClassicAppAccountState() async
}
// MARK: - OIDC
// MARK: - OAuth
enum OIDCError: Error {
enum OAuthError: Error {
/// Failed to get the URL that should be presented for login.
case urlFailure
/// The user cancelled the login.
case userCancellation
/// OIDC isn't supported on the currently configured server.
/// OAuth isn't supported on the currently configured server.
case notSupported
/// An unknown error occurred.
case unknown
}
struct OIDCAuthorizationDataProxy: Hashable {
struct OAuthAuthorizationDataProxy: Hashable {
let underlyingData: OAuthAuthorizationData
var url: URL {
guard let url = URL(string: underlyingData.loginUrl()) else {
fatalError("OIDC login URL hasn't been validated.")
fatalError("OAuth login URL hasn't been validated.")
}
return url
}