Skip to content

Commit

Permalink
Support for Single-Sign-On Provider (StanfordSpezi#45)
Browse files Browse the repository at this point in the history
# Support for Single-Sign-On Provider

## ♻️ Current situation & Problem
Currently, we only support an E-Mail-Password-based authentication.
SpeziAccount and SpeziFirebase just recently added support for Sign in
with Apple. This PR incorporates those updated libraries.


## ⚙️ Release Notes 
* Added support for Sign in with Apple


## 📚 Documentation
--
## ✅ Testing
Similar to SpeziFirebase, we do not test Sign in with Apple in the
Simulator directly as this cannot really be reliably achieved. Current
test cases cover all the other changes made in this PR.

## 📝 Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
Supereg authored Oct 23, 2023
1 parent cf19568 commit 5796d90
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 132 deletions.
23 changes: 14 additions & 9 deletions TemplateApplication.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
97D8B2A42A7653E600715F50 /* ProcessInfo+PreviewSimulator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D8B2A32A7653E600715F50 /* ProcessInfo+PreviewSimulator.swift */; };
97D8B2AB2A769A6E00715F50 /* OnboardingFlow+PreviewSimulator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D8B2AA2A769A6E00715F50 /* OnboardingFlow+PreviewSimulator.swift */; };
A92525A72ABC4B5F00640379 /* AccountUpdateModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = A92525A62ABC4B5F00640379 /* AccountUpdateModifier.swift */; };
A92525A92ABC4C7800640379 /* AccountRequiredModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = A92525A82ABC4C7800640379 /* AccountRequiredModifier.swift */; };
A92525AB2ABC4EB200640379 /* AccountRequiredKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A92525AA2ABC4EB200640379 /* AccountRequiredKey.swift */; };
A9720E432ABB68CC00872D23 /* AccountSetupHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9720E422ABB68CC00872D23 /* AccountSetupHeader.swift */; };
A9DFE8A92ABE551400428242 /* AccountButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9DFE8A82ABE551400428242 /* AccountButton.swift */; };
Expand Down Expand Up @@ -153,7 +152,6 @@
97D8B2A32A7653E600715F50 /* ProcessInfo+PreviewSimulator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ProcessInfo+PreviewSimulator.swift"; sourceTree = "<group>"; };
97D8B2AA2A769A6E00715F50 /* OnboardingFlow+PreviewSimulator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OnboardingFlow+PreviewSimulator.swift"; sourceTree = "<group>"; };
A92525A62ABC4B5F00640379 /* AccountUpdateModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountUpdateModifier.swift; sourceTree = "<group>"; };
A92525A82ABC4C7800640379 /* AccountRequiredModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountRequiredModifier.swift; sourceTree = "<group>"; };
A92525AA2ABC4EB200640379 /* AccountRequiredKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountRequiredKey.swift; sourceTree = "<group>"; };
A9720E422ABB68CC00872D23 /* AccountSetupHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSetupHeader.swift; sourceTree = "<group>"; };
A9DFE8A82ABE551400428242 /* AccountButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountButton.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -385,7 +383,6 @@
A9FE7ACF2AA39BAB0077B045 /* AccountSheet.swift */,
A9720E422ABB68CC00872D23 /* AccountSetupHeader.swift */,
A92525A62ABC4B5F00640379 /* AccountUpdateModifier.swift */,
A92525A82ABC4C7800640379 /* AccountRequiredModifier.swift */,
A92525AA2ABC4EB200640379 /* AccountRequiredKey.swift */,
A9DFE8A82ABE551400428242 /* AccountButton.swift */,
);
Expand Down Expand Up @@ -642,7 +639,6 @@
56F6F2A02AB441930022FE5A /* ContributionsList.swift in Sources */,
566155292AB8447C00209B80 /* Package+LicenseType.swift in Sources */,
5680DD392AB8983D004E6D4A /* PackageCell.swift in Sources */,
A92525A92ABC4C7800640379 /* AccountRequiredModifier.swift in Sources */,
A92525A72ABC4B5F00640379 /* AccountUpdateModifier.swift in Sources */,
2F5E32BD297E05EA003432F8 /* TemplateAppDelegate.swift in Sources */,
2FE5DC5229EDD7FA004B9AB4 /* TemplateApplicationScheduler.swift in Sources */,
Expand Down Expand Up @@ -749,7 +745,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.6;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -787,6 +783,7 @@
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
INFOPLIST_KEY_UITemplateApplicationlicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UITemplateApplicationlicationSupportsIndirectInputEvents = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -814,6 +811,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 637867499T;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = edu.stanford.spezi.templateapplication.tests;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -832,6 +830,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 637867499T;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = edu.stanford.spezi.templateapplicationuitests;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -893,7 +892,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.6;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -949,7 +948,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.6;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -987,6 +986,7 @@
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
INFOPLIST_KEY_UITemplateApplicationlicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UITemplateApplicationlicationSupportsIndirectInputEvents = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -1032,6 +1032,7 @@
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
INFOPLIST_KEY_UITemplateApplicationlicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UITemplateApplicationlicationSupportsIndirectInputEvents = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -1059,6 +1060,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 637867499T;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = edu.stanford.spezi.templateapplication.tests;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -1078,6 +1080,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 637867499T;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = edu.stanford.spezi.templateapplication.tests;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -1096,6 +1099,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 637867499T;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = edu.stanford.spezi.templateapplicationuitests;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -1114,6 +1118,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 637867499T;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = edu.stanford.spezi.templateapplicationuitests;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -1199,7 +1204,7 @@
repositoryURL = "https://github.com/StanfordSpezi/SpeziAccount.git";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 0.5.2;
minimumVersion = 0.6.0;
};
};
2FE5DC6529EDD894004B9AB4 /* XCRemoteSwiftPackageReference "SpeziContact" */ = {
Expand All @@ -1223,7 +1228,7 @@
repositoryURL = "https://github.com/StanfordSpezi/SpeziFirebase.git";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 0.6.0;
minimumVersion = 0.7.0;
};
};
2FE5DC8229EDD934004B9AB4 /* XCRemoteSwiftPackageReference "SpeziQuestionnaire" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
{
"identity" : "healthkitonfhir",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordBDHG/HealthKitOnFHIR.git",
"location" : "https://github.com/StanfordBDHG/HealthKitOnFHIR",
"state" : {
"revision" : "fdf8e4543718a940643598e4bd5e750e9c4c5540",
"version" : "0.2.4"
Expand Down Expand Up @@ -149,8 +149,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziAccount.git",
"state" : {
"revision" : "1eca29373a5c27e7dfe7871be77be306ca626989",
"version" : "0.5.3"
"revision" : "2f88e04a66bb3f1444763f7e3c103353b9be6f77",
"version" : "0.6.0"
}
},
{
Expand All @@ -176,8 +176,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziFirebase.git",
"state" : {
"revision" : "56dd7fb9204f9ec48f54c5c867f9755bec50b8ac",
"version" : "0.6.0"
"revision" : "774c5e311c94e411f4f7c49b846d82e5e3755a55",
"version" : "0.7.0"
}
},
{
Expand Down Expand Up @@ -237,28 +237,28 @@
{
"identity" : "speziviews",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziViews",
"location" : "https://github.com/StanfordSpezi/SpeziViews.git",
"state" : {
"revision" : "4b7cc423fd823123d354ec1d541ca7d2e0a9d6e3",
"version" : "0.5.1"
}
},
{
"identity" : "swift-collections",
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "a902f1823a7ff3c9ab2fba0f992396b948eda307",
"version" : "1.0.5"
"revision" : "8f4d2753f0e4778c76d5f05ad16c74f707390531",
"version" : "1.2.3"
}
},
{
"identity" : "swift-argument-parser",
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "8f4d2753f0e4778c76d5f05ad16c74f707390531",
"version" : "1.2.3"
"revision" : "a902f1823a7ff3c9ab2fba0f992396b948eda307",
"version" : "1.0.5"
}
},
{
Expand Down
52 changes: 0 additions & 52 deletions TemplateApplication/Account/AccountRequiredModifier.swift

This file was deleted.

6 changes: 3 additions & 3 deletions TemplateApplication/Account/AccountSetupHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ struct AccountSetupHeader: View {
.padding(.top, 30)
Text("ACCOUNT_SUBTITLE")
.padding(.bottom, 8)
if !account.signedIn || setupState == .loadingExistingAccount {
Text("ACCOUNT_SETUP_DESCRIPTION")
} else {
if account.signedIn, case .generic = setupState {
Text("ACCOUNT_SIGNED_IN_DESCRIPTION")
} else {
Text("ACCOUNT_SETUP_DESCRIPTION")
}
}
.multilineTextAlignment(.center)
Expand Down
40 changes: 25 additions & 15 deletions TemplateApplication/Account/AccountSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ struct AccountSheet: View {
@EnvironmentObject var account: Account
@Environment(\.accountRequired) var accountRequired

@State var isInSetup = false
@State var overviewIsEditing = false


var body: some View {
NavigationStack {
ZStack {
if account.signedIn {
if account.signedIn && !isInSetup {
AccountOverview(isEditing: $overviewIsEditing) {
NavigationLink {
ContributionsList()
Expand All @@ -33,26 +34,35 @@ struct AccountSheet: View {
.onDisappear {
overviewIsEditing = false
}
.toolbar {
if !overviewIsEditing {
closeButton
}
}
} else {
AccountSetup(header: {
AccountSetupHeader()
})
}
}
.onChange(of: account.signedIn) { newValue in
if newValue {
AccountSetup { _ in
dismiss() // we just signed in, dismiss the account setup sheet
} header: {
AccountSetupHeader()
}
}
.toolbar {
if !overviewIsEditing && (account.signedIn || !accountRequired) {
ToolbarItem(placement: .cancellationAction) {
Button("CLOSE") {
dismiss()
.onAppear {
isInSetup = true
}
.toolbar {
if !accountRequired {
closeButton
}
}
}
}
}
}
}

var closeButton: some ToolbarContent {
ToolbarItem(placement: .cancellationAction) {
Button("CLOSE") {
dismiss()
}
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions TemplateApplication/Home.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ struct HomeView: View {
}
.sheet(isPresented: $presentingAccount) {
AccountSheet()
.interactiveDismissDisabled(!account.signedIn)
}
.accountRequired(!FeatureFlags.disableFirebase && !FeatureFlags.skipOnboarding, sheetPresented: $presentingAccount)
.accountRequired(!FeatureFlags.disableFirebase && !FeatureFlags.skipOnboarding) {
AccountSheet()
}
.verifyRequiredAccountDetails(!FeatureFlags.disableFirebase && !FeatureFlags.skipOnboarding)
}
}

Expand Down
21 changes: 9 additions & 12 deletions TemplateApplication/Onboarding/AccountOnboarding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,22 @@ struct AccountOnboarding: View {


var body: some View {
AccountSetup {
AccountSetup { _ in
Task {
// Placing the nextStep() call inside this task will ensure that the sheet dismiss animation is
// played till the end before we navigate to the next step.
onboardingNavigationPath.nextStep()
}
} header: {
AccountSetupHeader()
} continue: {
OnboardingActionsView(
"ACCOUNT_NEXT",
action: {
onboardingNavigationPath.nextStep()
}
)
} header: {
AccountSetupHeader()
}
.onChange(of: account.signedIn) { newValue in
if newValue {
Task {
// Placing the nextStep() call inside this task will ensure that the sheet dismiss animation is
// played till the end before we navigate to the next step.
onboardingNavigationPath.nextStep()
}
}
}
}
}

Expand Down
Loading

0 comments on commit 5796d90

Please sign in to comment.