mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Simplify authentication logic
matrix.org now supports MAS so we don't need the web registration helper anymore.
This commit is contained in:
@@ -15,19 +15,21 @@ extension AuthenticationClientBuilderMock {
|
||||
"example.com": ClientSDKMock(configuration: .init(serverAddress: "example.com",
|
||||
homeserverURL: "https://matrix.example.com",
|
||||
slidingSyncVersion: .native,
|
||||
supportsPasswordLogin: true,
|
||||
elementWellKnown: "")),
|
||||
oidcLoginURL: nil,
|
||||
supportsOIDCCreatePrompt: false,
|
||||
supportsPasswordLogin: true)),
|
||||
"company.com": ClientSDKMock(configuration: .init(serverAddress: "company.com",
|
||||
homeserverURL: "https://matrix.company.com",
|
||||
slidingSyncVersion: .native,
|
||||
oidcLoginURL: "https://auth.company.com/oidc",
|
||||
supportsPasswordLogin: false,
|
||||
elementWellKnown: "")),
|
||||
supportsOIDCCreatePrompt: false,
|
||||
supportsPasswordLogin: false)),
|
||||
"server.net": ClientSDKMock(configuration: .init(serverAddress: "server.net",
|
||||
homeserverURL: "https://matrix.example.com",
|
||||
slidingSyncVersion: .native,
|
||||
supportsPasswordLogin: false,
|
||||
elementWellKnown: ""))
|
||||
oidcLoginURL: nil,
|
||||
supportsOIDCCreatePrompt: false,
|
||||
supportsPasswordLogin: false))
|
||||
]
|
||||
var qrCodeClient = ClientSDKMock(configuration: .init())
|
||||
}
|
||||
|
||||
@@ -76,8 +76,6 @@ extension ClientProxyMock {
|
||||
recentlyVisitedRoomsReturnValue = .success([])
|
||||
recentConversationCounterpartsReturnValue = []
|
||||
|
||||
getElementWellKnownReturnValue = .success(nil)
|
||||
|
||||
loadMediaContentForSourceThrowableError = ClientProxyError.sdkError(ClientProxyMockError.generic)
|
||||
loadMediaThumbnailForSourceWidthHeightThrowableError = ClientProxyError.sdkError(ClientProxyMockError.generic)
|
||||
loadMediaFileForSourceFilenameThrowableError = ClientProxyError.sdkError(ClientProxyMockError.generic)
|
||||
|
||||
@@ -4281,70 +4281,6 @@ class ClientProxyMock: ClientProxyProtocol, @unchecked Sendable {
|
||||
return isAliasAvailableReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - getElementWellKnown
|
||||
|
||||
var getElementWellKnownUnderlyingCallsCount = 0
|
||||
var getElementWellKnownCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return getElementWellKnownUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = getElementWellKnownUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
getElementWellKnownUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
getElementWellKnownUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var getElementWellKnownCalled: Bool {
|
||||
return getElementWellKnownCallsCount > 0
|
||||
}
|
||||
|
||||
var getElementWellKnownUnderlyingReturnValue: Result<ElementWellKnown?, ClientProxyError>!
|
||||
var getElementWellKnownReturnValue: Result<ElementWellKnown?, ClientProxyError>! {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return getElementWellKnownUnderlyingReturnValue
|
||||
} else {
|
||||
var returnValue: Result<ElementWellKnown?, ClientProxyError>? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = getElementWellKnownUnderlyingReturnValue
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
getElementWellKnownUnderlyingReturnValue = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
getElementWellKnownUnderlyingReturnValue = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var getElementWellKnownClosure: (() async -> Result<ElementWellKnown?, ClientProxyError>)?
|
||||
|
||||
func getElementWellKnown() async -> Result<ElementWellKnown?, ClientProxyError> {
|
||||
getElementWellKnownCallsCount += 1
|
||||
if let getElementWellKnownClosure = getElementWellKnownClosure {
|
||||
return await getElementWellKnownClosure()
|
||||
} else {
|
||||
return getElementWellKnownReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - clearCaches
|
||||
|
||||
var clearCachesUnderlyingCallsCount = 0
|
||||
|
||||
@@ -15,9 +15,9 @@ extension ClientSDKMock {
|
||||
var serverAddress = "matrix.org"
|
||||
var homeserverURL = "https://matrix-client.matrix.org"
|
||||
var slidingSyncVersion = SlidingSyncVersion.native
|
||||
var oidcLoginURL: String?
|
||||
var oidcLoginURL: String? = "https://account.matrix.org/authorize"
|
||||
var supportsOIDCCreatePrompt = true
|
||||
var supportsPasswordLogin = true
|
||||
var elementWellKnown = "{\"registration_helper_url\":\"https://develop.element.io/#/mobile_register\"}"
|
||||
var validCredentials = (username: "alice", password: "12345678")
|
||||
|
||||
// MARK: Session
|
||||
@@ -41,7 +41,6 @@ extension ClientSDKMock {
|
||||
slidingSyncVersionReturnValue = configuration.slidingSyncVersion
|
||||
userIdServerNameThrowableError = MockError.generic
|
||||
serverReturnValue = "https://\(configuration.serverAddress)"
|
||||
getUrlUrlReturnValue = configuration.elementWellKnown
|
||||
urlForOidcOidcConfigurationPromptReturnValue = OAuthAuthorizationDataSDKMock(configuration: configuration)
|
||||
loginUsernamePasswordInitialDeviceNameDeviceIdClosure = { username, password, _, _ in
|
||||
guard username == configuration.validCredentials.username,
|
||||
@@ -62,6 +61,11 @@ extension HomeserverLoginDetailsSDKMock {
|
||||
slidingSyncVersionReturnValue = configuration.slidingSyncVersion
|
||||
supportsPasswordLoginReturnValue = configuration.supportsPasswordLogin
|
||||
supportsOidcLoginReturnValue = configuration.oidcLoginURL != nil
|
||||
supportedOidcPromptsReturnValue = switch (configuration.oidcLoginURL, configuration.supportsOIDCCreatePrompt) {
|
||||
case (.none, _): []
|
||||
case (.some, true): [.consent, .create]
|
||||
case (.some, false): [.consent]
|
||||
}
|
||||
urlReturnValue = configuration.homeserverURL
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user