Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stub controller for logging in with OAuth #1931

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
}
8 changes: 6 additions & 2 deletions Kickstarter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -3056,6 +3057,7 @@
E10BE8E52B151CC800F73DC9 /* BlockUserInputTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockUserInputTests.swift; sourceTree = "<group>"; };
E10D06622ACF385E00470B5C /* FetchBackerProjectsQuery.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = FetchBackerProjectsQuery.json; sourceTree = "<group>"; };
E10D06642AD48C9C00470B5C /* FetchBackerProjectsQueryRequestForTests.graphql_test */ = {isa = PBXFileReference; lastKnownFileType = text; path = FetchBackerProjectsQueryRequestForTests.graphql_test; sourceTree = "<group>"; };
E11CFE492B6C41B400497375 /* OAuth.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OAuth.swift; sourceTree = "<group>"; };
E170B9102B20E83B001BEDD7 /* MockGraphQLClient+CombineTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MockGraphQLClient+CombineTests.swift"; sourceTree = "<group>"; };
E1889D8D2B6065D6004FBE21 /* CombineTestObserverTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CombineTestObserverTests.swift; sourceTree = "<group>"; };
E1A1491D2ACDD76700F49709 /* FetchBackerProjectsQuery.graphql */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = FetchBackerProjectsQuery.graphql; sourceTree = "<group>"; };
Expand All @@ -3066,7 +3068,7 @@
E1BB25632B1E81AA000BD2D6 /* Publisher+Service.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Publisher+Service.swift"; sourceTree = "<group>"; };
E1EA34EE2AE1B28400942A04 /* Signal+Combine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Signal+Combine.swift"; sourceTree = "<group>"; };
E1EEED282B684AA7009976D9 /* PKCE.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PKCE.swift; sourceTree = "<group>"; };
E1EEED2A2B686829009976D9 /* PKCETest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PKCETest.swift; path = KsApi/PKCETest.swift; sourceTree = "<group>"; };
E1EEED2A2B686829009976D9 /* PKCETest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PKCETest.swift; sourceTree = "<group>"; };
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just kind of floating at the top of the project navigator; small change to fix it.

E1FDB1E72AEAAC6100285F93 /* CombineTestObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CombineTestObserver.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -6143,7 +6146,6 @@
A7E06C701C5A6EB300EBDCC2 = {
isa = PBXGroup;
children = (
E1EEED2A2B686829009976D9 /* PKCETest.swift */,
802800561C88F62500141235 /* Configs */,
E10BE8CE2B02975C00F73DC9 /* RichPushNotifications */,
A7E06DBC1C5C027800EBDCC2 /* Frameworks */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
12 changes: 12 additions & 0 deletions Library/OAuth.swift
Original file line number Diff line number Diff line change
@@ -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
}
}