Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit 3f43d56

Browse files
committed
Remove no-longer-necessary params from NewGoogleAuthenticator inits
See work done in the previous two commits.
1 parent 9a0c2b5 commit 3f43d56

File tree

4 files changed

+4
-43
lines changed

4 files changed

+4
-43
lines changed

Demo/AuthenticatorDemo/ViewController.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class ViewController: UIViewController {
3535
clientId: GoogleClientId(string: APICredentials.googleLoginClientId)!,
3636
scheme: APICredentials.googleLoginSchemeId,
3737
audience: APICredentials.googleLoginServerClientId,
38-
viewController: self,
3938
urlSession: URLSession.shared
4039
)
4140

WordPressAuthenticator/GoogleSignIn/NewGoogleAuthenticator.swift

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,18 @@ public class NewGoogleAuthenticator: NSObject {
55
let clientId: GoogleClientId
66
let scheme: String
77
let audience: String
8-
let contextProvider: ASWebAuthenticationPresentationContextProviding
9-
108
let oauthTokenGetter: GoogleOAuthTokenGetting
119

1210
public convenience init(
1311
clientId: GoogleClientId,
1412
scheme: String,
1513
audience: String,
16-
viewController: UIViewController,
17-
urlSession: URLSession
18-
) {
19-
self.init(
20-
clientId: clientId,
21-
scheme: scheme,
22-
audience: audience,
23-
contextProvider: WebAuthenticationPresentationContext(viewController: viewController),
24-
oautTokenGetter: GoogleOAuthTokenGetter(dataGetter: urlSession)
25-
)
26-
}
27-
28-
public convenience init(
29-
clientId: GoogleClientId,
30-
scheme: String,
31-
audience: String,
32-
contextProvider: ASWebAuthenticationPresentationContextProviding,
3314
urlSession: URLSession
3415
) {
3516
self.init(
3617
clientId: clientId,
3718
scheme: scheme,
3819
audience: audience,
39-
contextProvider: contextProvider,
4020
oautTokenGetter: GoogleOAuthTokenGetter(dataGetter: urlSession)
4121
)
4222
}
@@ -45,14 +25,12 @@ public class NewGoogleAuthenticator: NSObject {
4525
clientId: GoogleClientId,
4626
scheme: String,
4727
audience: String,
48-
contextProvider: ASWebAuthenticationPresentationContextProviding,
4928
oautTokenGetter: GoogleOAuthTokenGetting
5029
) {
5130
self.clientId = clientId
5231
self.scheme = scheme
5332
self.audience = audience
5433
self.oauthTokenGetter = oautTokenGetter
55-
self.contextProvider = contextProvider
5634
}
5735

5836
/// Get the user's OAuth token from their Google account. This token can be used to authenticate with the WordPress backend.

WordPressAuthenticator/Unified Auth/GoogleAuthenticator.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,10 @@ extension GoogleAuthenticator {
307307

308308
trackRequestAuthorizitation(type: authType)
309309

310-
// We might want to change this in subsequent iterations, perhaps by moving the
311-
// `contextProvider` to the `getOAuthToken()` method so to allow it to be stored
312-
// as a `lazy` property?
313310
let sdkLessGoogleAuthenticator = NewGoogleAuthenticator(
314311
clientId: authConfig.googleClientId,
315312
scheme: authConfig.googleLoginScheme,
316313
audience: authConfig.googleLoginServerClientId,
317-
contextProvider: WebAuthenticationPresentationContext(viewController: viewController),
318314
urlSession: .shared
319315
)
320316

WordPressAuthenticatorTests/GoogleSignIn/NewGoogleAuthenticatorTests.swift

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ class NewGoogleAuthenticatorTests: XCTestCase {
88
func testRequestingOAuthTokenThrowsIfCodeCannotBeExtractedFromURL() async throws {
99
// Notice the use of a stub that returns a successful value.
1010
// This way, if we get an error, we can be more confident it's legit.
11-
let authenticator = await NewGoogleAuthenticator(
11+
let authenticator = NewGoogleAuthenticator(
1212
clientId: fakeClientId,
1313
scheme: "scheme",
1414
audience: "audience",
15-
contextProvider: FakeContextProvider(),
1615
oautTokenGetter: GoogleOAuthTokenGettingStub(response: .fixture())
1716
)
1817
let url = URL(string: "https://test.com?without=code")!
@@ -35,11 +34,10 @@ class NewGoogleAuthenticatorTests: XCTestCase {
3534
}
3635

3736
func testRequestingOAuthTokenRethrowsTheErrorItRecives() async throws {
38-
let authenticator = await NewGoogleAuthenticator(
37+
let authenticator = NewGoogleAuthenticator(
3938
clientId: fakeClientId,
4039
scheme: "scheme",
4140
audience: "audience",
42-
contextProvider: FakeContextProvider(),
4341
oautTokenGetter: GoogleOAuthTokenGettingStub(error: TestError(id: 1))
4442
)
4543
let url = URL(string: "https://test.com?code=a_code")!
@@ -59,11 +57,10 @@ class NewGoogleAuthenticatorTests: XCTestCase {
5957
}
6058

6159
func testRequestingOAuthTokenThrowsIfIdTokenMissingFromResponse() async throws {
62-
let authenticator = await NewGoogleAuthenticator(
60+
let authenticator = NewGoogleAuthenticator(
6361
clientId: fakeClientId,
6462
scheme: "scheme",
6563
audience: "audience",
66-
contextProvider: FakeContextProvider(),
6764
oautTokenGetter: GoogleOAuthTokenGettingStub(response: .fixture(rawIDToken: .none))
6865
)
6966
let url = URL(string: "https://test.com?code=a_code")!
@@ -85,11 +82,10 @@ class NewGoogleAuthenticatorTests: XCTestCase {
8582
}
8683

8784
func testRequestingOAuthTokenReturnsTokenIfSuccessful() async throws {
88-
let authenticator = await NewGoogleAuthenticator(
85+
let authenticator = NewGoogleAuthenticator(
8986
clientId: fakeClientId,
9087
scheme: "scheme",
9188
audience: "audience",
92-
contextProvider: FakeContextProvider(),
9389
oautTokenGetter: GoogleOAuthTokenGettingStub(response: .fixture(rawIDToken: JSONWebToken.validJWTStringWithEmail))
9490
)
9591
let url = URL(string: "https://test.com?code=a_code")!
@@ -107,11 +103,3 @@ class NewGoogleAuthenticatorTests: XCTestCase {
107103
}
108104
}
109105
}
110-
111-
import AuthenticationServices
112-
113-
class FakeContextProvider: UIViewController, ASWebAuthenticationPresentationContextProviding {
114-
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
115-
return view.window!
116-
}
117-
}

0 commit comments

Comments
 (0)