-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(authentication): support Game Center Sign-In (#235)
Co-authored-by: Mike Solomon <mikesol@Mikes-MacBook-Pro.local> Co-authored-by: Robin Genz <mail@robingenz.dev>
- Loading branch information
1 parent
9c66a04
commit fcb0f25
Showing
12 changed files
with
174 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@capacitor-firebase/authentication": minor | ||
--- | ||
|
||
feat(ios): support Game Center Sign-In |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Set up authentication using Game Center Sign-In | ||
|
||
## Android | ||
|
||
🚧 Currently not supported. | ||
|
||
## iOS | ||
|
||
1. Add `gc.apple.com` to the `providers` [configuration](https://github.com/capawesome-team/capacitor-firebase/tree/main/packages/authentication#configuration) array. | ||
1. Make sure you register your Apple app with Firebase. This means entering your app's bundle ID in the registration section along with additional optional information such as App Store ID and Team ID, etc. This will be required for securely verifying the audience of the user's Game Center credential before completing sign-in. | ||
1. Enable Game Center as a sign-in provider for your Firebase project. | ||
|
||
## Web | ||
|
||
🚧 Currently not supported. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/authentication/ios/Plugin/Handlers/GameCenterAuthProviderHandler.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import Foundation | ||
import Capacitor | ||
import FirebaseCore | ||
import FirebaseAuth | ||
import AuthenticationServices | ||
import GameKit | ||
|
||
class GameCenterAuthProviderHandler: NSObject { | ||
public let errorGetCredentialFailed = "getCredential failed." | ||
private var pluginImplementation: FirebaseAuthentication | ||
|
||
init(_ pluginImplementation: FirebaseAuthentication) { | ||
self.pluginImplementation = pluginImplementation | ||
super.init() | ||
} | ||
|
||
func signIn(call: CAPPluginCall) { | ||
startSignInWithGameCenterFlow(call, isLink: false) | ||
} | ||
|
||
func link(call: CAPPluginCall) { | ||
startSignInWithGameCenterFlow(call, isLink: true) | ||
} | ||
|
||
func startSignInWithGameCenterFlow(_ call: CAPPluginCall, isLink: Bool) { | ||
GKLocalPlayer.local.authenticateHandler = { viewController, error in | ||
if let viewController = viewController { | ||
DispatchQueue.main.async { | ||
self.pluginImplementation.getPlugin().bridge?.viewController?.present(viewController, animated: true, completion: nil) | ||
} | ||
return | ||
} | ||
if error != nil { | ||
if isLink { | ||
self.pluginImplementation.handleFailedLink(message: nil, error: error) | ||
} else { | ||
self.pluginImplementation.handleFailedSignIn(message: nil, error: error) | ||
} | ||
return | ||
} | ||
GameCenterAuthProvider.getCredential { (credential, error) in | ||
if error != nil { | ||
if isLink { | ||
self.pluginImplementation.handleFailedLink(message: nil, error: error) | ||
} else { | ||
self.pluginImplementation.handleFailedSignIn(message: nil, error: error) | ||
} | ||
return | ||
} | ||
guard let credential = credential else { | ||
if isLink { | ||
self.pluginImplementation.handleFailedLink(message: self.errorGetCredentialFailed, error: nil) | ||
} else { | ||
self.pluginImplementation.handleFailedSignIn(message: self.errorGetCredentialFailed, error: nil) | ||
} | ||
return | ||
} | ||
if isLink { | ||
self.pluginImplementation.handleSuccessfulLink(credential: credential, idToken: nil, nonce: nil, accessToken: nil) | ||
} else { | ||
self.pluginImplementation.handleSuccessfulSignIn(credential: credential, idToken: nil, nonce: nil, accessToken: nil) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters