Skip to content

Commit 456fa7f

Browse files
[google_sign_in] PR 2/4 Migrate the plugin class from Objective-C to Swift. (flutter#12655)
Migrates `FLTGoogleSignInPlugin` from Objective-C to Swift (`GoogleSignInPlugin.swift`). GID SDK wrappers and `ViewProvider` stay Obj-C for this PR. Intended as a 1:1 move of configure, restorePreviousSignIn, signIn, refreshedAuthorizationTokens, addScopes, signOut, disconnect, error-code mapping, URL handling, and the iOS view-controller / macOS window presentation paths. `presentingViewController` / `presentingWindow` on the Obj-C wrapper protocol become nullable. That matches existing runtime behavior: `FSIViewProvider.viewController` was already nullable. Bumps `google_sign_in_ios` to **6.3.3**. PR 2/4 of the Obj-C → Swift migration. Depends on PR 1/4 (SPM packaging). Continues flutter#119103 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 330115e commit 456fa7f

14 files changed

Lines changed: 597 additions & 540 deletions

File tree

‎packages/google_sign_in/google_sign_in_ios/CHANGELOG.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 6.3.4
2+
3+
* Migrates the plugin class from Objective-C to Swift.
4+
* Adds a CocoaPods placeholder header so the generated Swift header can import `google_sign_in_ios.h`.
5+
* Fixes scene URL handling to report whether Google Sign-In handled the URL.
6+
* Returns an error when Google Sign-In reports a user without a user ID.
7+
18
## 6.3.3
29

310
* Creates Swift Package Manager target for Swift implementation.

‎packages/google_sign_in/google_sign_in_ios/darwin/Tests/GoogleSignInTests.swift‎

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class TestSignIn: NSObject, FSIGIDSignIn {
8686

8787
#if os(iOS) || targetEnvironment(macCatalyst)
8888
func signIn(
89-
withPresenting presentingViewController: UIViewController,
89+
withPresenting presentingViewController: UIViewController?,
9090
hint: String?,
9191
additionalScopes: [String]?,
9292
nonce: String?,
@@ -107,7 +107,7 @@ class TestSignIn: NSObject, FSIGIDSignIn {
107107
}
108108
#else
109109
func signIn(
110-
withPresenting presentingWindow: NSWindow,
110+
withPresenting presentingWindow: NSWindow?,
111111
hint: String?,
112112
additionalScopes: [String]?,
113113
nonce: String?,
@@ -213,7 +213,7 @@ class TestGoogleUser: NSObject, FSIGIDGoogleUser {
213213
#if os(iOS) || targetEnvironment(macCatalyst)
214214
func addScopes(
215215
_ scopes: [String],
216-
presenting presentingViewController: UIViewController,
216+
presenting presentingViewController: UIViewController?,
217217
completion: (((any FSIGIDSignInResult)?, Error?) -> Void)?
218218
) {
219219
self.requestedScopes = scopes
@@ -226,7 +226,7 @@ class TestGoogleUser: NSObject, FSIGIDGoogleUser {
226226
#elseif os(OSX)
227227
func addScopes(
228228
_ scopes: [String],
229-
presenting presentingWindow: NSWindow,
229+
presenting presentingWindow: NSWindow?,
230230
completion: (((any FSIGIDSignInResult)?, Error?) -> Void)?
231231
) {
232232
self.requestedScopes = scopes
@@ -373,6 +373,35 @@ struct GoogleSignInPluginTests {
373373
}
374374
}
375375
}
376+
377+
@Test func restorePreviousSignInErrorsWhenUserIDIsNil() async {
378+
let (plugin, fakeSignIn) = createTestPlugin()
379+
let fakeUser = TestGoogleUser("mockID")
380+
fakeUser.userID = nil
381+
fakeSignIn.user = fakeUser
382+
383+
await confirmation("completion called") { confirmed in
384+
plugin.restorePreviousSignIn { result, error in
385+
#expect(result == nil)
386+
#expect(error?.code == "google_sign_in")
387+
#expect(error?.message == "Google Sign-In succeeded without a user ID.")
388+
confirmed()
389+
}
390+
}
391+
}
392+
393+
@Test func restorePreviousSignInNeitherUserNorError() async {
394+
let (plugin, _) = createTestPlugin()
395+
396+
await confirmation("completion called") { confirmed in
397+
plugin.restorePreviousSignIn { result, error in
398+
#expect(result == nil)
399+
#expect(error?.code == "(null): 0")
400+
#expect(error?.details as? String == "[Unsupported type: (null)]")
401+
confirmed()
402+
}
403+
}
404+
}
376405
}
377406

378407
@Suite("signIn") struct SignInTests {
@@ -728,17 +757,29 @@ struct GoogleSignInPluginTests {
728757
#expect(handled == false)
729758
#expect(fakeSignIn.handledURLs == [url])
730759
}
760+
#endif
731761

732-
@Test func handleURLs() {
733-
let (plugin, fakeSignIn) = createTestPlugin()
734-
let firstURL = URL(string: "com.googleusercontent.apps.test:/oauthredirect")!
735-
let secondURL = URL(string: "com.googleusercontent.apps.test:/another")!
762+
@Test func handleOpen() {
763+
let (plugin, fakeSignIn) = createTestPlugin()
764+
let firstURL = URL(string: "com.googleusercontent.apps.test:/oauthredirect")!
765+
let secondURL = URL(string: "com.googleusercontent.apps.test:/another")!
736766

737-
plugin.handleURLs([firstURL, secondURL])
767+
let handled = plugin.handleOpen([firstURL, secondURL])
738768

739-
#expect(fakeSignIn.handledURLs == [firstURL, secondURL])
740-
}
741-
#endif
769+
#expect(handled == true)
770+
#expect(fakeSignIn.handledURLs == [firstURL, secondURL])
771+
}
772+
773+
@Test func handleOpenReturnsHandleResult() {
774+
let (plugin, fakeSignIn) = createTestPlugin()
775+
let url = URL(string: "com.googleusercontent.apps.test:/oauthredirect")!
776+
fakeSignIn.handleURLResult = false
777+
778+
let handled = plugin.handleOpen([url])
779+
780+
#expect(handled == false)
781+
#expect(fakeSignIn.handledURLs == [url])
782+
}
742783
}
743784

744785
@Suite("errorMapping") struct ErrorMappingTests {
@@ -936,16 +977,16 @@ func loadGoogleServiceInfo() -> [String: Any]? {
936977
func createTestPlugin(
937978
viewProvider: TestViewProvider = TestViewProvider(),
938979
googleServiceProperties: [String: Any]? = nil
939-
) -> (FLTGoogleSignInPlugin, TestSignIn) {
980+
) -> (GoogleSignInPlugin, TestSignIn) {
940981
let fakeSignIn = TestSignIn()
941982
return (
942-
FLTGoogleSignInPlugin(
983+
GoogleSignInPlugin(
943984
signIn: fakeSignIn, viewProvider: viewProvider,
944985
googleServiceProperties: googleServiceProperties), fakeSignIn
945986
)
946987
}
947988

948-
func addSignedInUser(to plugin: FLTGoogleSignInPlugin) -> TestGoogleUser {
989+
func addSignedInUser(to plugin: GoogleSignInPlugin) -> TestGoogleUser {
949990
let identifier = "fakeID"
950991
let user = TestGoogleUser(identifier)
951992
plugin.usersByIdentifier[identifier] = user

‎packages/google_sign_in/google_sign_in_ios/darwin/google_sign_in_ios/Package.swift‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ let package = Package(
2424
.target(
2525
name: "google_sign_in_ios",
2626
dependencies: [
27-
"google_sign_in_ios_objc"
27+
.product(name: "GoogleSignIn", package: "GoogleSignIn-iOS"),
28+
"google_sign_in_ios_objc",
2829
],
2930
resources: [
3031
.process("Resources")
@@ -37,7 +38,8 @@ let package = Package(
3738
],
3839
publicHeadersPath: "include",
3940
cSettings: [
40-
.headerSearchPath("include/google_sign_in_ios")
41+
.headerSearchPath("include/google_sign_in_ios"),
42+
.headerSearchPath("include/google_sign_in_ios_objc"),
4143
]
4244
),
4345
]

0 commit comments

Comments
 (0)