diff --git a/Kickstarter-iOS/Features/LoginTout/Controller/LoginToutViewController.swift b/Kickstarter-iOS/Features/LoginTout/Controller/LoginToutViewController.swift index 894753f45b..9d6c4e65ce 100644 --- a/Kickstarter-iOS/Features/LoginTout/Controller/LoginToutViewController.swift +++ b/Kickstarter-iOS/Features/LoginTout/Controller/LoginToutViewController.swift @@ -400,8 +400,20 @@ public final class LoginToutViewController: UIViewController, MFMailComposeViewC } fileprivate func pushLoginViewController() { - self.navigationController?.pushViewController(LoginViewController.instantiate(), animated: true) - self.navigationItem.backBarButtonItem = UIBarButtonItem.back(nil, selector: nil) + if featureLoginWithOAuthEnabled() { + let session = ASWebAuthenticationSession( + url: OAuth.authorizationURL(), + callbackURLScheme: OAuth.redirectScheme + ) { _, _ in + // TODO: MBL-1159: Get required information from the callback; call mutation to login. + } + + session.presentationContextProvider = self + session.start() + } else { + self.navigationController?.pushViewController(LoginViewController.instantiate(), animated: true) + self.navigationItem.backBarButtonItem = UIBarButtonItem.back(nil, selector: nil) + } } fileprivate func pushTwoFactorViewController(facebookAccessToken token: String) { @@ -623,3 +635,15 @@ extension LoginToutViewController: ASAuthorizationControllerPresentationContextP return window } } + +// MARK: - ASWebAuthenticationPresentationContextProviding + +extension LoginToutViewController: ASWebAuthenticationPresentationContextProviding { + public func presentationAnchor(for _: ASWebAuthenticationSession) -> ASPresentationAnchor { + guard let window = self.view.window else { + return ASPresentationAnchor() + } + + return window + } +} diff --git a/Kickstarter.xcodeproj/project.pbxproj b/Kickstarter.xcodeproj/project.pbxproj index cd657aed83..9d510e13c6 100644 --- a/Kickstarter.xcodeproj/project.pbxproj +++ b/Kickstarter.xcodeproj/project.pbxproj @@ -1488,6 +1488,7 @@ E10D06632ACF385E00470B5C /* FetchBackerProjectsQuery.json in Resources */ = {isa = PBXBuildFile; fileRef = E10D06622ACF385E00470B5C /* FetchBackerProjectsQuery.json */; }; E10D06652AD48C9C00470B5C /* FetchBackerProjectsQueryRequestForTests.graphql_test in Resources */ = {isa = PBXBuildFile; fileRef = E10D06642AD48C9C00470B5C /* FetchBackerProjectsQueryRequestForTests.graphql_test */; }; E10F75E82B6937FA00024AD1 /* PKCETest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1EEED2A2B686829009976D9 /* PKCETest.swift */; }; + E11CFE4B2B6C42CE00497375 /* OAuth.swift in Sources */ = {isa = PBXBuildFile; fileRef = E11CFE492B6C41B400497375 /* OAuth.swift */; }; E170B9112B20E83B001BEDD7 /* MockGraphQLClient+CombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E170B9102B20E83B001BEDD7 /* MockGraphQLClient+CombineTests.swift */; }; E1A1491E2ACDD76800F49709 /* FetchBackerProjectsQuery.graphql in Resources */ = {isa = PBXBuildFile; fileRef = E1A1491D2ACDD76700F49709 /* FetchBackerProjectsQuery.graphql */; }; E1A149202ACDD7BF00F49709 /* FetchProjectsEnvelope+FetchBackerProjectsQueryData.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1A1491F2ACDD7BF00F49709 /* FetchProjectsEnvelope+FetchBackerProjectsQueryData.swift */; }; @@ -3056,6 +3057,7 @@ E10BE8E52B151CC800F73DC9 /* BlockUserInputTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockUserInputTests.swift; sourceTree = ""; }; E10D06622ACF385E00470B5C /* FetchBackerProjectsQuery.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = FetchBackerProjectsQuery.json; sourceTree = ""; }; E10D06642AD48C9C00470B5C /* FetchBackerProjectsQueryRequestForTests.graphql_test */ = {isa = PBXFileReference; lastKnownFileType = text; path = FetchBackerProjectsQueryRequestForTests.graphql_test; sourceTree = ""; }; + E11CFE492B6C41B400497375 /* OAuth.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OAuth.swift; sourceTree = ""; }; E170B9102B20E83B001BEDD7 /* MockGraphQLClient+CombineTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MockGraphQLClient+CombineTests.swift"; sourceTree = ""; }; E1889D8D2B6065D6004FBE21 /* CombineTestObserverTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CombineTestObserverTests.swift; sourceTree = ""; }; E1A1491D2ACDD76700F49709 /* FetchBackerProjectsQuery.graphql */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = FetchBackerProjectsQuery.graphql; sourceTree = ""; }; @@ -3066,7 +3068,7 @@ E1BB25632B1E81AA000BD2D6 /* Publisher+Service.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Publisher+Service.swift"; sourceTree = ""; }; E1EA34EE2AE1B28400942A04 /* Signal+Combine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Signal+Combine.swift"; sourceTree = ""; }; E1EEED282B684AA7009976D9 /* PKCE.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PKCE.swift; sourceTree = ""; }; - E1EEED2A2B686829009976D9 /* PKCETest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PKCETest.swift; path = KsApi/PKCETest.swift; sourceTree = ""; }; + E1EEED2A2B686829009976D9 /* PKCETest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PKCETest.swift; sourceTree = ""; }; E1FDB1E72AEAAC6100285F93 /* CombineTestObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CombineTestObserver.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -5991,6 +5993,7 @@ A78537F71CB5803B00385B73 /* NSHTTPCookieStorageType.swift */, 37EB3E4B228CF4A400076E4C /* NumberFormatter.swift */, 37EB3E4D228CF4FB00076E4C /* NumberFormatterTests.swift */, + E11CFE492B6C41B400497375 /* OAuth.swift */, 94C92E7B2659EDBF00A96818 /* PaddingLabel.swift */, A77D7B061CBAAF5D0077586B /* Paginate.swift */, A7ED1F1C1E830FDC00BFFA01 /* PaginateTests.swift */, @@ -6143,7 +6146,6 @@ A7E06C701C5A6EB300EBDCC2 = { isa = PBXGroup; children = ( - E1EEED2A2B686829009976D9 /* PKCETest.swift */, 802800561C88F62500141235 /* Configs */, E10BE8CE2B02975C00F73DC9 /* RichPushNotifications */, A7E06DBC1C5C027800EBDCC2 /* Frameworks */, @@ -6513,6 +6515,7 @@ D6C9A20D1F755FE200981E64 /* GraphSchemaTests.swift */, D01587761EEB2ED6006E7684 /* MockService.swift */, E1EEED282B684AA7009976D9 /* PKCE.swift */, + E1EEED2A2B686829009976D9 /* PKCETest.swift */, D01588261EEB2ED7006E7684 /* ServerConfig.swift */, D01588271EEB2ED7006E7684 /* Service.swift */, E1BB25632B1E81AA000BD2D6 /* Publisher+Service.swift */, @@ -7612,6 +7615,7 @@ 064B007827A463D2007B21FE /* ImageViewElementCellViewModel.swift in Sources */, A7F441E51D005A9400FE6FC5 /* SearchViewModel.swift in Sources */, 370F527A2254267900F159B9 /* UIApplicationType.swift in Sources */, + E11CFE4B2B6C42CE00497375 /* OAuth.swift in Sources */, A75C81171D210BD700B5AD03 /* ShareViewModel.swift in Sources */, 6049D0202AA776B40015BB0D /* DesignSystemColors.swift in Sources */, A757EAF01D1ABE7400A5C978 /* ActivitySurveyResponseCellViewModel.swift in Sources */, diff --git a/Library/OAuth.swift b/Library/OAuth.swift new file mode 100644 index 0000000000..7374142659 --- /dev/null +++ b/Library/OAuth.swift @@ -0,0 +1,12 @@ +import Foundation + +public struct OAuth { + public init() {} + + public static let redirectScheme = "ksrauth2" + public static func authorizationURL() -> URL { + let base = AppEnvironment.current.apiService.serverConfig.webBaseUrl + // TODO: MBL-1159: This will take URL parameters, as defined in the ticket, for PKCE + return base + } +}