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.
This commit is contained in:
Mauro Romito
2026-10-20 12:13:58 +02:00
committed by Mauro
parent d495f937b6
commit fd52027ac3
2 changed files with 16 additions and 3 deletions
@@ -116,10 +116,10 @@ class AuthenticationService: AuthenticationServiceProtocol {
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: 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)
@@ -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.