diff --git a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Assets.xcassets/Auth Provider Icons/Contents.json b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Assets.xcassets/Auth Provider Icons/Contents.json
index da4a164c918..73c00596a7f 100644
--- a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Assets.xcassets/Auth Provider Icons/Contents.json
+++ b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Assets.xcassets/Auth Provider Icons/Contents.json
@@ -1,6 +1,6 @@
{
"info" : {
- "version" : 1,
- "author" : "xcode"
+ "author" : "xcode",
+ "version" : 1
}
-}
\ No newline at end of file
+}
diff --git a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Assets.xcassets/Auth Provider Icons/Game Center.imageset/Contents.json b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Assets.xcassets/Auth Provider Icons/Game Center.imageset/Contents.json
new file mode 100644
index 00000000000..8cd53c205c6
--- /dev/null
+++ b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Assets.xcassets/Auth Provider Icons/Game Center.imageset/Contents.json
@@ -0,0 +1,21 @@
+{
+ "images" : [
+ {
+ "idiom" : "universal",
+ "scale" : "1x"
+ },
+ {
+ "filename" : "gamecontroller.png",
+ "idiom" : "universal",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "universal",
+ "scale" : "3x"
+ }
+ ],
+ "info" : {
+ "author" : "xcode",
+ "version" : 1
+ }
+}
diff --git a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Assets.xcassets/Auth Provider Icons/Game Center.imageset/gamecontroller.png b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Assets.xcassets/Auth Provider Icons/Game Center.imageset/gamecontroller.png
new file mode 100644
index 00000000000..14b182a9c45
Binary files /dev/null and b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Assets.xcassets/Auth Provider Icons/Game Center.imageset/gamecontroller.png differ
diff --git a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/AuthenticationExample.entitlements b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/AuthenticationExample.entitlements
index 2402d248da7..075352dfe1b 100644
--- a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/AuthenticationExample.entitlements
+++ b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/AuthenticationExample.entitlements
@@ -10,6 +10,8 @@
com.apple.developer.associated-domains
+ com.apple.developer.game-center
+
keychain-access-groups
$(AppIdentifierPrefix)com.google.firebase.auth.keychainGroup1
diff --git a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Models/AuthMenu.swift b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Models/AuthMenu.swift
index b0abf158c96..711c60a0680 100644
--- a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Models/AuthMenu.swift
+++ b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Models/AuthMenu.swift
@@ -24,6 +24,7 @@ enum AuthMenu: String {
case gitHub = "github.com"
case yahoo = "yahoo.com"
case facebook = "facebook.com"
+ case gameCenter = "gc.apple.com"
case emailPassword = "password"
case passwordless = "emailLink"
case phoneNumber = "phone"
@@ -54,6 +55,8 @@ enum AuthMenu: String {
return "Yahoo"
case .facebook:
return "Facebook"
+ case .gameCenter:
+ return "Game Center"
case .emailPassword:
return "Email & Password Login"
case .passwordless:
@@ -91,6 +94,8 @@ enum AuthMenu: String {
self = .yahoo
case "Facebook":
self = .facebook
+ case "Game Center":
+ self = .gameCenter
case "Email & Password Login":
self = .emailPassword
case "Email Link/Passwordless":
@@ -114,7 +119,7 @@ enum AuthMenu: String {
extension AuthMenu: DataSourceProvidable {
private static var providers: [AuthMenu] {
- [.google, .apple, .twitter, .microsoft, .gitHub, .yahoo, .facebook]
+ [.google, .apple, .twitter, .microsoft, .gitHub, .yahoo, .facebook, .gameCenter]
}
static var settingsSection: Section {
diff --git a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/ViewControllers/AccountLinkingViewController.swift b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/ViewControllers/AccountLinkingViewController.swift
index 05f59f0c2b8..410c7adc624 100644
--- a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/ViewControllers/AccountLinkingViewController.swift
+++ b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/ViewControllers/AccountLinkingViewController.swift
@@ -14,6 +14,7 @@
import FirebaseAuth
import FirebaseCore
+import GameKit
import UIKit
// For Account Linking with Sign in with Google.
@@ -93,6 +94,9 @@ class AccountLinkingViewController: UIViewController, DataSourceProviderDelegate
case .twitter, .microsoft, .gitHub, .yahoo:
performOAuthAccountLink(for: provider)
+ case .gameCenter:
+ performGameCenterAccountLink()
+
case .emailPassword:
performEmailPasswordAccountLink()
@@ -233,6 +237,35 @@ class AccountLinkingViewController: UIViewController, DataSourceProviderDelegate
}
}
+ private func performGameCenterAccountLink() {
+ // Step 1: Ensure Game Center Authentication
+ guard GKLocalPlayer.local.isAuthenticated else {
+ print("Error: Player not authenticated with Game Center.")
+ return
+ }
+
+ // Step 2: Get Game Center Credential for Linking
+ GameCenterAuthProvider.getCredential { credential, error in
+ if let error = error {
+ print("Error getting Game Center credential: \(error.localizedDescription)")
+ return
+ }
+
+ guard let credential = credential else {
+ print("Error: Missing Game Center credential")
+ return
+ }
+
+ // Step 3: Link Credential with Current Firebase User
+ Auth.auth().currentUser?.link(with: credential) { authResult, error in
+ if let error = error {
+ print("Error linking Game Center to Firebase: \(error.localizedDescription)")
+ return
+ }
+ }
+ }
+ }
+
// MARK: - Email & Password Login Account Linking 🔥
private func performEmailPasswordAccountLink() {
diff --git a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/ViewControllers/AuthViewController.swift b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/ViewControllers/AuthViewController.swift
index 4cc7d4597f0..20a00d3b086 100644
--- a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/ViewControllers/AuthViewController.swift
+++ b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/ViewControllers/AuthViewController.swift
@@ -18,6 +18,7 @@ import FirebaseAuth
// [START auth_import]
import FirebaseCore
+import GameKit
// For Sign in with Google
// [START google_import]
@@ -71,6 +72,9 @@ class AuthViewController: UIViewController, DataSourceProviderDelegate {
case .twitter, .microsoft, .gitHub, .yahoo:
performOAuthLoginFlow(for: provider)
+ case .gameCenter:
+ performGameCenterLoginFlow()
+
case .emailPassword:
performDemoEmailPasswordLoginFlow()
@@ -210,6 +214,42 @@ class AuthViewController: UIViewController, DataSourceProviderDelegate {
}
}
+ private func performGameCenterLoginFlow() {
+ // Step 1: System Game Center Login
+ GKLocalPlayer.local.authenticateHandler = { viewController, error in
+ if let error = error {
+ // Handle Game Center login error
+ print("Error logging into Game Center: \(error.localizedDescription)")
+ } else if let authViewController = viewController {
+ // Present Game Center login UI if needed
+ self.present(authViewController, animated: true)
+ } else {
+ // Game Center login successful, proceed to Firebase
+ self.linkGameCenterToFirebase()
+ }
+ }
+ }
+
+ // Step 2: Link to Firebase
+ private func linkGameCenterToFirebase() {
+ GameCenterAuthProvider.getCredential { credential, error in
+ if let error = error {
+ // Handle Firebase credential retrieval error
+ print("Error getting Game Center credential: \(error.localizedDescription)")
+ } else if let credential = credential {
+ Auth.auth().signIn(with: credential) { authResult, error in
+ if let error = error {
+ // Handle Firebase sign-in error
+ print("Error signing into Firebase with Game Center: \(error.localizedDescription)")
+ } else {
+ // Firebase sign-in successful
+ print("Successfully linked Game Center to Firebase")
+ }
+ }
+ }
+ }
+ }
+
private func performDemoEmailPasswordLoginFlow() {
let loginController = LoginController()
loginController.delegate = self
diff --git a/FirebaseAuth/Tests/SampleSwift/AuthenticationExampleUITests/AuthenticationExampleUITests.swift b/FirebaseAuth/Tests/SampleSwift/AuthenticationExampleUITests/AuthenticationExampleUITests.swift
index 1dc9bddd718..c70795dc548 100644
--- a/FirebaseAuth/Tests/SampleSwift/AuthenticationExampleUITests/AuthenticationExampleUITests.swift
+++ b/FirebaseAuth/Tests/SampleSwift/AuthenticationExampleUITests/AuthenticationExampleUITests.swift
@@ -36,11 +36,6 @@ class AuthenticationExampleUITests: XCTestCase {
XCTAssertTrue(app.navigationBars["Firebase Auth"].exists)
}
- func testAuthOptions() {
- // There are 15 sign in methods, each with its own cell
- XCTAssertEqual(app.tables.cells.count, 15)
- }
-
func testAuthAnonymously() {
app.staticTexts["Anonymous Authentication"].tap()