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

feat(auth, apple): Game Center sign-in support #12228

Merged
merged 8 commits into from Jan 31, 2024
Merged

Conversation

russellwheatley
Copy link
Member

@russellwheatley russellwheatley commented Jan 31, 2024

Description

I've had to change the way we get the AuthCredential on Apple platforms. Game Center credential is different to the other providers. It requires a callback to receive. See link: https://firebase.google.com/docs/auth/ios/game-center#authenticate_with_firebase
Here is the snippet:

// Get Firebase credentials from the player's Game Center credentials
[FIRGameCenterAuthProvider getCredentialWithCompletion:^(FIRAuthCredential *credential,
                                                         NSError *error) {
  // The credential can be used to sign in, or re-auth, or link or unlink.
  if (error == nil) {
    [[FIRAuth auth] signInWithCredential:credential
                              completion:^(FIRUser *user, NSError *error) {
      // If error is nil, player is signed in.
    }];
  }
}];

Previously, we called a synchronous method to get the credential: https://github.com/firebase/flutterfire/blob/master/packages/firebase_auth/firebase_auth/ios/Classes/FLTFirebaseAuthPlugin.m#L641C33-L641C66

But I had to make this a callback to allow for Game Center credential retrieval: https://github.com/firebase/flutterfire/pull/12228/files#diff-926b26fe3f9119fb3548066f1b05028306ff8766f9a04abba0fefdb5dac5c0b2R642-R645

This method is used for signInWithCredential, linkWithCredential(), reauthenticateWithCredential() & updatePhoneNumber() API which will allow the user to call these methods signInWithCredential, linkWithCredential(), reauthenticateWithCredential() with Game Center credential.

Testing Game Center sign-in

  1. Add Game Center capability on Xcode project which also brings in framework for Game Player.
  2. Create an app in "App Store Connect" and select the "Game Center" option to allow authentication.
  3. Implement the following in AppDelegate to login with Game Center:
__weak GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *gcAuthViewController,
                                    NSError *error) {
  if (gcAuthViewController != nil) {
    // Pause any activities that require user interaction, then present the
    // gcAuthViewController to the player.
  } else if (localPlayer.isAuthenticated) {
    // Player is signed in to Game Center. Can now login with Game Center credential
	NSLog(@"logged in with Game Center");
  } else {
    // Error
  }
};
  1. Now able to login with Game Center with Firebase.

Tested signInWithCredential(), linkWithCredential() & reauthenticateWithCredential()

Screenshot 2024-01-31 at 09 26 56

Related Issues

closes #12191
closes #9441

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
This will ensure a smooth and quick review process. Updating the pubspec.yaml and changelogs is not required.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (melos run analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

@russellwheatley russellwheatley marked this pull request as ready for review January 31, 2024 10:16
Comment on lines +642 to +645
- (void)getFIRAuthCredentialFromArguments:(NSDictionary *)arguments
app:(AuthPigeonFirebaseApp *)app
completion:(void (^)(FIRAuthCredential *credential,
NSError *error))completion {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see any Pigeon related changes on the Dart part, is there some files missing?

Copy link
Member Author

Choose a reason for hiding this comment

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

This method is internal to the plugin and isn't part of Pigeon API.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh nice didn't realise thanks :)

@russellwheatley russellwheatley merged commit ac625ec into master Jan 31, 2024
20 of 22 checks passed
@russellwheatley russellwheatley deleted the auth-12191 branch January 31, 2024 11:23
@firebase firebase locked and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 [firebase_auth] Authenticate via Game Center [auth] Add support for GameCenter and Play SignIn
3 participants