From fd52027ac3090a8fd764c05bd566e97ef7b22ba6 Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Tue, 20 Oct 2026 12:13:58 +0200 Subject: [PATCH] Open the sign-up page when creating an account with OAuth Create account sent prompt=consent, the same as Sign in, so MAS opened its sign-in page and new users were asked for a password they didn't have. The create prompt was turned off because MAS used to sign you straight into an existing browser session (element-hq/matrix-authentication-service#3429). MAS v0.15.0 fixed that by always showing its consent page, so send prompt=create again for registration, but only when the server advertises it. --- .../Authentication/AuthenticationService.swift | 6 +++--- UnitTests/Sources/AuthenticationServiceTests.swift | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ElementX/Sources/Services/Authentication/AuthenticationService.swift b/ElementX/Sources/Services/Authentication/AuthenticationService.swift index b58aa9367..db7850682 100644 --- a/ElementX/Sources/Services/Authentication/AuthenticationService.swift +++ b/ElementX/Sources/Services/Authentication/AuthenticationService.swift @@ -116,10 +116,10 @@ class AuthenticationService: AuthenticationServiceProtocol { func urlForOAuthLogin(loginHint: String?) async -> Result { 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: OAuthPrompt = flow == .register ? .create : .consent + let supportsCreatePrompt = homeserverSubject.value.loginMode == .oAuth(supportsCreatePrompt: true) + let prompt: OAuthPrompt = flow == .register && supportsCreatePrompt ? .create : .consent let oAuthData = try await client.urlForOauth(oauthConfiguration: appSettings.oAuthConfiguration.rustValue, - prompt: .consent, + prompt: prompt, loginHint: loginHint, deviceId: nil, additionalScopes: nil) diff --git a/UnitTests/Sources/AuthenticationServiceTests.swift b/UnitTests/Sources/AuthenticationServiceTests.swift index 590a1df78..145468c88 100644 --- a/UnitTests/Sources/AuthenticationServiceTests.swift +++ b/UnitTests/Sources/AuthenticationServiceTests.swift @@ -8,6 +8,7 @@ @testable import ElementX import Foundation +import MatrixRustSDK import MatrixRustSDKMocks import Testing @@ -77,6 +78,18 @@ struct AuthenticationServiceTests { loginMode: .unknown)) } + @Test(arguments: [("matrix.org", AuthenticationFlow.login, OAuthPrompt.consent), + ("matrix.org", .register, .create), + ("company.com", .register, .consent)]) + mutating func oAuthPrompt(serverName: String, flow: AuthenticationFlow, expectedPrompt: OAuthPrompt) async throws { + try await setup(serverNameOrBaseURL: serverName) + try await service.configure(for: serverName, flow: flow).get() + + _ = try await service.urlForOAuthLogin(loginHint: nil).get() + + #expect(client.urlForOauthOauthConfigurationPromptLoginHintDeviceIdAdditionalScopesReceivedArguments?.prompt == expectedPrompt) + } + @Test mutating func classicAppAccountSecretsBundleIsUsed() async throws { // Given an authentication service with an Element Classic account for Alice.