mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 11:58:32 +00:00
@@ -31,17 +31,17 @@ class AuthenticationServiceProxy: AuthenticationServiceProxyProtocol {
|
||||
homeserverSubject = .init(LoginHomeserver(address: appSettings.defaultHomeserverAddress,
|
||||
loginMode: .unknown))
|
||||
|
||||
// let oidcConfiguration = OidcConfiguration(clientName: InfoPlistReader.main.bundleDisplayName,
|
||||
// redirectUri: settings.oidcRedirectURL.absoluteString,
|
||||
// clientUri: appSettings.oidcClientURL.absoluteString,
|
||||
// tosUri: appSettings.oidcTermsURL.absoluteString,
|
||||
// policyUri: appSettings.oidcPolicyURL.absoluteString,
|
||||
// staticRegistrations: appSettings.oidcStaticRegistrations.mapKeys { $0.absoluteString })
|
||||
let oidcConfiguration = OidcConfiguration(clientName: InfoPlistReader.main.bundleDisplayName,
|
||||
redirectUri: appSettings.oidcRedirectURL.absoluteString,
|
||||
clientUri: appSettings.oidcClientURL.absoluteString,
|
||||
tosUri: appSettings.oidcTermsURL.absoluteString,
|
||||
policyUri: appSettings.oidcPolicyURL.absoluteString,
|
||||
staticRegistrations: appSettings.oidcStaticRegistrations.mapKeys { $0.absoluteString })
|
||||
|
||||
authenticationService = AuthenticationService(basePath: userSessionStore.baseDirectory.path,
|
||||
passphrase: nil,
|
||||
userAgent: UserAgentBuilder.makeASCIIUserAgent(),
|
||||
// oidcConfiguration: oidcConfiguration,
|
||||
oidcConfiguration: oidcConfiguration,
|
||||
customSlidingSyncProxy: appSettings.slidingSyncProxyURL?.absoluteString)
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ class AuthenticationServiceProxy: AuthenticationServiceProxyProtocol {
|
||||
}
|
||||
|
||||
if let details = authenticationService.homeserverDetails() {
|
||||
if details.authenticationIssuer() != nil {
|
||||
if details.supportsOidcLogin() {
|
||||
homeserver.loginMode = .oidc
|
||||
} else if details.supportsPasswordLogin() {
|
||||
homeserver.loginMode = .password
|
||||
@@ -77,31 +77,29 @@ class AuthenticationServiceProxy: AuthenticationServiceProxyProtocol {
|
||||
}
|
||||
|
||||
func urlForOIDCLogin() async -> Result<OIDCAuthenticationDataProxy, AuthenticationServiceError> {
|
||||
.failure(.oidcError(.notSupported))
|
||||
// do {
|
||||
// let oidcData = try await Task.dispatch(on: .global()) {
|
||||
// try self.authenticationService.urlForOidcLogin()
|
||||
// }
|
||||
// return .success(OIDCAuthenticationDataProxy(underlyingData: oidcData))
|
||||
// } catch {
|
||||
// MXLog.error("Failed to get URL for OIDC login: \(error)")
|
||||
// return .failure(.oidcError(.urlFailure))
|
||||
// }
|
||||
do {
|
||||
let oidcData = try await Task.dispatch(on: .global()) {
|
||||
try self.authenticationService.urlForOidcLogin()
|
||||
}
|
||||
return .success(OIDCAuthenticationDataProxy(underlyingData: oidcData))
|
||||
} catch {
|
||||
MXLog.error("Failed to get URL for OIDC login: \(error)")
|
||||
return .failure(.oidcError(.urlFailure))
|
||||
}
|
||||
}
|
||||
|
||||
func loginWithOIDCCallback(_ callbackURL: URL, data: OIDCAuthenticationDataProxy) async -> Result<UserSessionProtocol, AuthenticationServiceError> {
|
||||
.failure(.oidcError(.notSupported))
|
||||
// do {
|
||||
// let client = try await Task.dispatch(on: .global()) {
|
||||
// try self.authenticationService.loginWithOidcCallback(authenticationData: data.underlyingData, callbackUrl: callbackURL.absoluteString)
|
||||
// }
|
||||
// return await userSession(for: client)
|
||||
// } catch AuthenticationError.OidcCancelled {
|
||||
// return .failure(.oidcError(.userCancellation))
|
||||
// } catch {
|
||||
// MXLog.error("Login with OIDC failed: \(error)")
|
||||
// return .failure(.failedLoggingIn)
|
||||
// }
|
||||
do {
|
||||
let client = try await Task.dispatch(on: .global()) {
|
||||
try self.authenticationService.loginWithOidcCallback(authenticationData: data.underlyingData, callbackUrl: callbackURL.absoluteString)
|
||||
}
|
||||
return await userSession(for: client)
|
||||
} catch AuthenticationError.OidcCancelled {
|
||||
return .failure(.oidcError(.userCancellation))
|
||||
} catch {
|
||||
MXLog.error("Login with OIDC failed: \(error)")
|
||||
return .failure(.failedLoggingIn)
|
||||
}
|
||||
}
|
||||
|
||||
func login(username: String, password: String, initialDeviceName: String?, deviceID: String?) async -> Result<UserSessionProtocol, AuthenticationServiceError> {
|
||||
|
||||
@@ -66,16 +66,18 @@ enum OIDCError: Error {
|
||||
}
|
||||
|
||||
struct OIDCAuthenticationDataProxy: Equatable {
|
||||
// let underlyingData: OidcAuthenticationData
|
||||
//
|
||||
// var url: URL {
|
||||
// URL(string: underlyingData.loginUrl())!
|
||||
// }
|
||||
let url: URL = "https://theroadtonowhere"
|
||||
let underlyingData: OidcAuthenticationData
|
||||
|
||||
var url: URL {
|
||||
guard let url = URL(string: underlyingData.loginUrl()) else {
|
||||
fatalError("OIDC login URL hasn't been validated.")
|
||||
}
|
||||
return url
|
||||
}
|
||||
}
|
||||
|
||||
// extension OidcAuthenticationData: Equatable {
|
||||
// public static func == (lhs: MatrixRustSDK.OidcAuthenticationData, rhs: MatrixRustSDK.OidcAuthenticationData) -> Bool {
|
||||
// lhs.loginUrl() == rhs.loginUrl()
|
||||
// }
|
||||
// }
|
||||
extension OidcAuthenticationData: Equatable {
|
||||
public static func == (lhs: MatrixRustSDK.OidcAuthenticationData, rhs: MatrixRustSDK.OidcAuthenticationData) -> Bool {
|
||||
lhs.loginUrl() == rhs.loginUrl()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,6 +108,10 @@ class ClientProxy: ClientProxyProtocol {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
var accountURL: URL? {
|
||||
client.accountUrl().flatMap(URL.init(string:))
|
||||
}
|
||||
|
||||
func startSync() {
|
||||
MXLog.info("Starting sync")
|
||||
@@ -305,7 +309,8 @@ class ClientProxy: ClientProxyProtocol {
|
||||
func logout() async {
|
||||
await Task.dispatch(on: clientQueue) {
|
||||
do {
|
||||
try self.client.logout()
|
||||
// We aren't currently handling the RP initiated sign out URL.
|
||||
_ = try self.client.logout()
|
||||
} catch {
|
||||
MXLog.error("Failed logging out with error: \(error)")
|
||||
}
|
||||
|
||||
@@ -76,6 +76,8 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
|
||||
|
||||
var restorationToken: RestorationToken? { get }
|
||||
|
||||
var accountURL: URL? { get }
|
||||
|
||||
var roomSummaryProvider: RoomSummaryProviderProtocol? { get }
|
||||
|
||||
var inviteSummaryProvider: RoomSummaryProviderProtocol? { get }
|
||||
|
||||
@@ -25,6 +25,7 @@ class MockClientProxy: ClientProxyProtocol {
|
||||
let deviceID: String?
|
||||
let homeserver = ""
|
||||
let restorationToken: RestorationToken? = nil
|
||||
let accountURL: URL?
|
||||
|
||||
var roomSummaryProvider: RoomSummaryProviderProtocol? = MockRoomSummaryProvider()
|
||||
|
||||
@@ -32,9 +33,10 @@ class MockClientProxy: ClientProxyProtocol {
|
||||
|
||||
var avatarURLPublisher: AnyPublisher<URL?, Never> { Empty().eraseToAnyPublisher() }
|
||||
|
||||
init(userID: String, deviceID: String? = nil, roomSummaryProvider: RoomSummaryProviderProtocol? = MockRoomSummaryProvider()) {
|
||||
init(userID: String, deviceID: String? = nil, accountURL: URL? = nil, roomSummaryProvider: RoomSummaryProviderProtocol? = MockRoomSummaryProvider()) {
|
||||
self.userID = userID
|
||||
self.deviceID = deviceID
|
||||
self.accountURL = accountURL
|
||||
self.roomSummaryProvider = roomSummaryProvider
|
||||
}
|
||||
|
||||
|
||||
@@ -42,8 +42,8 @@ extension MatrixRustSDK.Session: 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),
|
||||
slidingSyncProxy: container.decode(String.self, forKey: .slidingSyncProxy))
|
||||
// oidcData: container.decodeIfPresent(String.self, forKey: .oidcData)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
@@ -53,12 +53,11 @@ extension MatrixRustSDK.Session: 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(slidingSyncProxy, forKey: .slidingSyncProxy)
|
||||
// try container.encode(oidcData, forKey: .oidcData)
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case accessToken, refreshToken, userId, deviceId, homeserverUrl, slidingSyncProxy
|
||||
// case oidcData
|
||||
case accessToken, refreshToken, userId, deviceId, homeserverUrl, oidcData, slidingSyncProxy
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user