Skip to content

Commit

Permalink
#40: Remove SSO and replace fallback with OIDC.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Jun 21, 2022
1 parent c0f5d7b commit cb807d3
Show file tree
Hide file tree
Showing 17 changed files with 163 additions and 379 deletions.
14 changes: 1 addition & 13 deletions ElementX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 52;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -102,7 +102,6 @@
56F0A22972A3BB519DA2261C /* HomeScreenViewModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24F5530B2212862FA4BEFF2D /* HomeScreenViewModelProtocol.swift */; };
59C41313AED7566C3AC51163 /* RoomSummary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A953B6C0C431DBF4DD00B4 /* RoomSummary.swift */; };
5B2C4C17888FC095ED6880B2 /* SplashViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 48971F1FFD7FC5C466889FC7 /* SplashViewController.xib */; };
5C8AFBF168A41E20835F3B86 /* LoginScreenUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DB34B0C74CD242FED9DD069 /* LoginScreenUITests.swift */; };
5CABC57F620FBB39F4EC127C /* TemplateSimpleScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9BA045DC4CA12D030ACF558 /* TemplateSimpleScreen.swift */; };
5D430CDE11EAC3E8E6B80A66 /* RoomTimelineViewFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FEE631F3A4AFDC6652DD9DA /* RoomTimelineViewFactory.swift */; };
5E0F2E612718BB4397A6D40A /* TextRoomTimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9E785D5137510481733A3E8 /* TextRoomTimelineView.swift */; };
Expand All @@ -122,7 +121,6 @@
6FC10A00D268FCD48B631E37 /* ViewFrameReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = EFF7BF82A950B91BC5469E91 /* ViewFrameReader.swift */; };
7002C55A4C917F3715765127 /* MediaProviderProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = C888BCD78E2A55DCE364F160 /* MediaProviderProtocol.swift */; };
7405B4824D45BA7C3D943E76 /* Application.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D0CBC76C80E04345E11F2DB /* Application.swift */; };
7434A7F02D587A920B376A9A /* LoginScreenViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A43964330459965AF048A8C /* LoginScreenViewModelTests.swift */; };
7756C4E90CABE6F14F7920A0 /* BugReportUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6FEA87EA3752203065ECE27 /* BugReportUITests.swift */; };
77D7DAA41AAB36800C1F2E2D /* RoomTimelineProviderProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 095AED4CF56DFF3EB7BB84C8 /* RoomTimelineProviderProtocol.swift */; };
77E192BA943B90F9F310CA23 /* WeakDictionaryKeyReference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FFCC48E7F701B6C24484593 /* WeakDictionaryKeyReference.swift */; };
Expand All @@ -141,7 +139,6 @@
80E04BE80A89A78FBB4863BB /* UserIndicatorViewPresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 193FB285430D3956B6E61E4D /* UserIndicatorViewPresentable.swift */; };
85AFBB433AD56704A880F8A0 /* FramePreferenceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4798B3B7A1E8AE3901CEE8C6 /* FramePreferenceKey.swift */; };
86C2E93920FD15AD17E193A9 /* BugReportViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E532D95330139D118A9BF88 /* BugReportViewModel.swift */; };
86EDD75DDB092EC422524A7A /* AuthenticationSSOButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA7D7BD7319A30E46CC194CA /* AuthenticationSSOButton.swift */; };
8775F46AE3234A5A5688C19D /* UserIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD73FAAA4A76CE4A1F3014D9 /* UserIndicator.swift */; };
8810A2A30A68252EBB54EE05 /* HomeScreenModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71BC7CA1BC1041E93077BBA1 /* HomeScreenModels.swift */; };
899E0BE9298DB30F762D65CB /* AuthenticationModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6482B10F8CDCA39D88D44D6 /* AuthenticationModels.swift */; };
Expand Down Expand Up @@ -295,7 +292,6 @@
1A18F6CE4D694D21E4EA9B25 /* Strings+Untranslated.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Strings+Untranslated.swift"; sourceTree = "<group>"; };
1A63815AD6A5C306453342F2 /* ImageRoomTimelineItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageRoomTimelineItem.swift; sourceTree = "<group>"; };
1C429043E986008B97736636 /* ab */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ab; path = ab.lproj/Localizable.strings; sourceTree = "<group>"; };
1DB34B0C74CD242FED9DD069 /* LoginScreenUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginScreenUITests.swift; sourceTree = "<group>"; };
1E508AB0EDEE017FF4F6F8D1 /* DTHTMLElement+AttributedStringBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DTHTMLElement+AttributedStringBuilder.swift"; sourceTree = "<group>"; };
2112A6CFEA46E672D90EBF54 /* kab */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = kab; path = kab.lproj/Localizable.strings; sourceTree = "<group>"; };
218AB05B4E3889731959C5F1 /* EventBasedTimelineItemProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventBasedTimelineItemProtocol.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -379,7 +375,6 @@
56F01DD1BBD4450E18115916 /* LabelledActivityIndicatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelledActivityIndicatorView.swift; sourceTree = "<group>"; };
5773C86AF04AEF26515AD00C /* sl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sl; path = sl.lproj/Localizable.strings; sourceTree = "<group>"; };
5872785B9C7934940146BFBA /* MXLogger.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXLogger.h; sourceTree = "<group>"; };
5A43964330459965AF048A8C /* LoginScreenViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginScreenViewModelTests.swift; sourceTree = "<group>"; };
5A9AB74614131D6706894E0C /* AppCoordinatorStateMachine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinatorStateMachine.swift; sourceTree = "<group>"; };
5B2F9D5C39A4494D19F33E38 /* SettingsViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewModelProtocol.swift; sourceTree = "<group>"; };
5B9D5F812E5AD6DC786DBC9B /* NavigationRouterStoreProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationRouterStoreProtocol.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -597,7 +592,6 @@
F9BA045DC4CA12D030ACF558 /* TemplateSimpleScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemplateSimpleScreen.swift; sourceTree = "<group>"; };
F9E785D5137510481733A3E8 /* TextRoomTimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextRoomTimelineView.swift; sourceTree = "<group>"; };
FA154570F693D93513E584C1 /* RoomMessageFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomMessageFactory.swift; sourceTree = "<group>"; };
FA7D7BD7319A30E46CC194CA /* AuthenticationSSOButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationSSOButton.swift; sourceTree = "<group>"; };
FC9A76C6178717E2734C900F /* AuthenticationLoginScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationLoginScreen.swift; sourceTree = "<group>"; };
FDB9C37196A4C79F24CE80C6 /* KeychainControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainControllerTests.swift; sourceTree = "<group>"; };
FE2DF459F1737A594667CC46 /* EmoteRoomMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmoteRoomMessage.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -968,7 +962,6 @@
FDB9C37196A4C79F24CE80C6 /* KeychainControllerTests.swift */,
C070FD43DC6BF4E50217965A /* LocalizationTests.swift */,
3DC1943ADE6A62ED5129D7C8 /* LoggingTests.swift */,
5A43964330459965AF048A8C /* LoginScreenViewModelTests.swift */,
93CF7B19FFCF8EFBE0A8696A /* RoomScreenViewModelTests.swift */,
F03C9D319676F3C0DC6B0203 /* ScreenshotDetectorTests.swift */,
3D487C1185D658F8B15B8F55 /* SettingsViewModelTests.swift */,
Expand Down Expand Up @@ -1113,7 +1106,6 @@
7D0CBC76C80E04345E11F2DB /* Application.swift */,
C6FEA87EA3752203065ECE27 /* BugReportUITests.swift */,
4D6E4C37E9F0E53D3DF951AC /* HomeScreenUITests.swift */,
1DB34B0C74CD242FED9DD069 /* LoginScreenUITests.swift */,
086B997409328F091EBA43CE /* RoomScreenUITests.swift */,
E3E29F98CF0E960689A410E3 /* SettingsUITests.swift */,
325A2B3278875554DDEB8A9B /* SplashScreenUITests.swift */,
Expand Down Expand Up @@ -1339,7 +1331,6 @@
7F6A6C1154F2FD610F5810FC /* AuthenticationHomeserverViewData.swift */,
C6482B10F8CDCA39D88D44D6 /* AuthenticationModels.swift */,
C0B7F5EBD408DA994DF2F490 /* AuthenticationServerInfoSection.swift */,
FA7D7BD7319A30E46CC194CA /* AuthenticationSSOButton.swift */,
9E6D88E8AFFBF2C1D589C0FA /* UIConstants.swift */,
90F48FEF84016ED42A94BA24 /* LoginScreen */,
);
Expand Down Expand Up @@ -1689,7 +1680,6 @@
EEC40663922856C65D1E0DF5 /* KeychainControllerTests.swift in Sources */,
0033481EE363E4914295F188 /* LocalizationTests.swift in Sources */,
149D1942DC005D0485FB8D93 /* LoggingTests.swift in Sources */,
7434A7F02D587A920B376A9A /* LoginScreenViewModelTests.swift in Sources */,
46562110EE202E580A5FFD9C /* RoomScreenViewModelTests.swift in Sources */,
EA31DD9043B91ECB8E45A9A6 /* ScreenshotDetectorTests.swift in Sources */,
206F0DBAB6AF042CA1FF2C0D /* SettingsViewModelTests.swift in Sources */,
Expand Down Expand Up @@ -1723,7 +1713,6 @@
9B2F6D16D9B5CE577426742B /* AuthenticationLoginViewModel.swift in Sources */,
A6754F104C50575EE1987BF0 /* AuthenticationLoginViewModelProtocol.swift in Sources */,
899E0BE9298DB30F762D65CB /* AuthenticationModels.swift in Sources */,
86EDD75DDB092EC422524A7A /* AuthenticationSSOButton.swift in Sources */,
212B2C774E91981AE425D52D /* AuthenticationServerInfoSection.swift in Sources */,
CB326BAB54E9B68658909E36 /* Benchmark.swift in Sources */,
38546A6010A2CF240EC9AF73 /* BindableState.swift in Sources */,
Expand Down Expand Up @@ -1886,7 +1875,6 @@
7405B4824D45BA7C3D943E76 /* Application.swift in Sources */,
7756C4E90CABE6F14F7920A0 /* BugReportUITests.swift in Sources */,
9DC5FB22B8F86C3B51E907C1 /* HomeScreenUITests.swift in Sources */,
5C8AFBF168A41E20835F3B86 /* LoginScreenUITests.swift in Sources */,
2F1CF90A3460C153154427F0 /* RoomScreenUITests.swift in Sources */,
490E606044B18985055FF690 /* SettingsUITests.swift in Sources */,
A00DFC1DD3567B1EDC9F8D16 /* SplashScreenUITests.swift in Sources */,
Expand Down
29 changes: 29 additions & 0 deletions ElementX/Sources/Other/Extensions/Client.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Client.swift
// ElementX
//
// Created by Doug on 17/06/2022.
// Copyright © 2022 Element. All rights reserved.
//

import MatrixRustSDK

extension Client {
static func new(_ address: String) throws -> Client {
do {
return try discoverClient(domain: address)
} catch {
return try newClient(homeserver: HomeserverAddress.sanitized(address))
}
}

func loginMode() -> LoginMode {
if let authenticationServer = authenticationServer(), let url = URL(string: authenticationServer) {
return .oidc(url)
} else if (try? supportsPasswordLogin()) == true {
return .password
} else {
return .unsupported
}
}
}
4 changes: 2 additions & 2 deletions ElementX/Sources/Other/SwiftUI/ErrorHandling/AlertInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ struct AlertInfo<T: Hashable>: Identifiable {
/// The alert's title.
let title: String
/// The alert's message (optional).
var message: String? = nil
var message: String?
/// The alert's primary button title and action. Defaults to an Ok button with no action.
var primaryButton: (title: String, action: (() -> Void)?) = (ElementL10n.ok, nil)
/// The alert's secondary button title and action.
var secondaryButton: (title: String, action: (() -> Void)?)? = nil
var secondaryButton: (title: String, action: (() -> Void)?)?
}

#warning("Remove the NSError extensions?")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ final class LabelledActivityIndicatorView: UIView {
static let padding = UIEdgeInsets(top: 20, left: 40, bottom: 15, right: 40)
static let activityIndicatorScale = CGFloat(1.5)
static let cornerRadius: CGFloat = 12.0
static let stackBackgroundOpacity: CGFloat = 0.9
static let stackSpacing: CGFloat = 15
static let backgroundOpacity: CGFloat = 0.5
}

private let stackBackgroundView: UIView = {
let view = UIView()
let view = UIVisualEffectView(effect: UIBlurEffect(style: .systemMaterial))
view.layer.cornerRadius = Constants.cornerRadius
view.alpha = Constants.stackBackgroundOpacity
view.backgroundColor = .gray.withAlphaComponent(0.75)
view.clipsToBounds = true
return view
}()

Expand Down Expand Up @@ -67,6 +65,7 @@ final class LabelledActivityIndicatorView: UIView {
private func setup(text: String) {
setupStackView()
label.text = text
label.textColor = .element.primaryContent
}

private func setupStackView() {
Expand Down
21 changes: 18 additions & 3 deletions ElementX/Sources/Other/UserIndicators/RoundedToastView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,27 @@ class RoundedToastView: UIView {

private func setup(viewState: ToastViewState) {

backgroundColor = .gray.withAlphaComponent(0.75)
backgroundColor = .clear
clipsToBounds = true

setupBackgroundMaterial()
setupStackView()
stackView.addArrangedSubview(toastView(for: viewState.style))
stackView.addArrangedSubview(label)
label.text = viewState.label
label.textColor = .element.primaryContent
}

private func setupBackgroundMaterial() {
let material = UIVisualEffectView(effect: UIBlurEffect(style: .systemMaterial))
addSubview(material)
material.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
material.topAnchor.constraint(equalTo: topAnchor),
material.bottomAnchor.constraint(equalTo: bottomAnchor),
material.leadingAnchor.constraint(equalTo: leadingAnchor),
material.trailingAnchor.constraint(equalTo: trailingAnchor)
])
}

private func setupStackView() {
Expand All @@ -101,10 +116,10 @@ class RoundedToastView: UIView {
case .loading:
return activityIndicator
case .success:
imageView.image = UIImage(systemName: "checkmark.circle")
imageView.image = UIImage(systemName: "checkmark")
return imageView
case .error:
imageView.image = UIImage(systemName: "x.circle")
imageView.image = UIImage(systemName: "xmark")
return imageView
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ class AuthenticationCoordinator: Coordinator {
MXLog.error("Failed logging in user with error: \(error)")
}
}
case .continueWithSSO(let provider):
break
case .fallback:
case .continueWithOIDC:
break
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ struct AuthenticationHomeserverViewData: Equatable {
let address: String
/// Whether or not the homeserver is matrix.org.
let isMatrixDotOrg: Bool
/// Whether or not to display the username and password text fields during login.
let showLoginForm: Bool
/// Whether or not to display the username and password text fields during registration.
let showRegistrationForm: Bool
/// The supported SSO login options.
let ssoIdentityProviders: [SSOIdentityProvider]
/// The types login supported by the homeserver.
let loginMode: LoginMode
}

// MARK: - Mocks
Expand All @@ -37,42 +33,21 @@ extension AuthenticationHomeserverViewData {
static var mockMatrixDotOrg: AuthenticationHomeserverViewData {
AuthenticationHomeserverViewData(address: "matrix.org",
isMatrixDotOrg: true,
showLoginForm: true,
showRegistrationForm: true,
ssoIdentityProviders: [
SSOIdentityProvider(id: "1", name: "Apple", brand: "apple", iconURL: nil),
SSOIdentityProvider(id: "2", name: "Facebook", brand: "facebook", iconURL: nil),
SSOIdentityProvider(id: "3", name: "GitHub", brand: "github", iconURL: nil),
SSOIdentityProvider(id: "4", name: "GitLab", brand: "gitlab", iconURL: nil),
SSOIdentityProvider(id: "5", name: "Google", brand: "google", iconURL: nil)
])
loginMode: .password)
}

/// A mock homeserver that supports login and registration via a password but has no SSO providers.
static var mockBasicServer: AuthenticationHomeserverViewData {
AuthenticationHomeserverViewData(address: "example.com",
isMatrixDotOrg: false,
showLoginForm: true,
showRegistrationForm: true,
ssoIdentityProviders: [])
loginMode: .password)
}

/// A mock homeserver that supports only supports authentication via a single SSO provider.
static var mockEnterpriseSSO: AuthenticationHomeserverViewData {
static var mockOIDC: AuthenticationHomeserverViewData {
AuthenticationHomeserverViewData(address: "company.com",
isMatrixDotOrg: false,
showLoginForm: false,
showRegistrationForm: false,
ssoIdentityProviders: [SSOIdentityProvider(id: "test", name: "SAML", brand: nil, iconURL: nil)])
}

/// A mock homeserver that supports only supports authentication via fallback.
static var mockFallback: AuthenticationHomeserverViewData {
AuthenticationHomeserverViewData(address: "company.com",
isMatrixDotOrg: false,
showLoginForm: false,
showRegistrationForm: false,
ssoIdentityProviders: [])
loginMode: .oidc(URL(string: "https://auth.company.com")!))
}

}
Loading

0 comments on commit cb807d3

Please sign in to comment.