Skip to content

feat(auth, android): Play Games provider sign-in support#12201

Merged
russellwheatley merged 7 commits into
masterfrom
auth-12190
Jan 31, 2024
Merged

feat(auth, android): Play Games provider sign-in support#12201
russellwheatley merged 7 commits into
masterfrom
auth-12190

Conversation

@russellwheatley
Copy link
Copy Markdown
Member

@russellwheatley russellwheatley commented Jan 25, 2024

Description

Writing the code is easier than receiving the serverAuthCode for use in signing in with Play Games provider. Some changes required are already in the example app.

Configuration

Requires setting up a game app on the Play console and following the two sections in the Firebase documentation here:

Do not to forget to "publish" the app on the Play console. (For Invertase devs, it is on the Play console under "Play Game App").

Play Game SDK setup

I couldn't find any Dart packages that retrieve the serverAuthCode so I setup myself using the Play Games SDK.

I would not follow the Firebase docs as it has a tiny snippet of the deprecated Play Games SDK (v1) here: https://firebase.google.com/docs/auth/android/play-games#integrate_play_games_sign-in_into_your_game

I would follow the Play Games V2 SDK documentation here: https://developers.google.com/games/services/android/signin

I actually tested directly in the FlutterFirebaseAuthPlugin. A couple of required changes are included in this PR for the auth example app, but I had to add a dependency to the firebase_auth plugin build.gradle (not included in PR):

    dependencies {
        api firebaseCoreProject
        implementation platform("com.google.firebase:firebase-bom:${getRootProjectExtOrCoreProperty("FirebaseSDKVersion", firebaseCoreProject)}")
        implementation 'com.google.firebase:firebase-auth'
// THIS LINE
        implementation "com.google.android.gms:play-services-games-v2:19.0.0"
        implementation 'androidx.annotation:annotation:1.7.0'
    }

For implementation, I had to do the following to get the serverAuthCode:

GamesSignInClient gamesSignInClient = PlayGames.getGamesSignInClient(getActivity());  
  
gamesSignInClient  
    .signIn()  
    .addOnCompleteListener(  
        task -> {  
          if (task.isSuccessful()) {  
            gamesSignInClient  
                .requestServerSideAccess(  
                    "406099696497-a12gakvts4epfk5pkio7dphc1anjiggc.apps.googleusercontent.com",  
                    false)  
                .addOnCompleteListener(  
                    tasky -> {  
                      if (tasky.isSuccessful()) {  
						//SERVER AUTH CODE
                        String serverAuthCode = tasky.getResult();  
                      } else {  
                        result.error(  
                            FlutterFirebaseAuthPluginException.parserExceptionToFlutter(  
                                tasky.getException()));  
                      }  
                    });  
          } else {  
            result.error(  
                FlutterFirebaseAuthPluginException.parserExceptionToFlutter(  
                    task.getException()));  
          }  
        });

Also add in instance creation of class:

PlayGamesSdk.initialize(getActivity());

Related Issues

closes #12190

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 changed the title feat(auth, android): Play Services provider sign-in support feat(auth, android): Play Games provider sign-in support Jan 25, 2024
Copy link
Copy Markdown
Contributor

@Lyokone Lyokone left a comment

Choose a reason for hiding this comment

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

Looks good, I wonder if we should add a section in the docs as well?

Comment thread docs/auth/federated-auth.md
@russellwheatley russellwheatley merged commit 1fb9019 into master Jan 31, 2024
@russellwheatley russellwheatley deleted the auth-12190 branch January 31, 2024 09:42
@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] Authentication via Play Games Services on Android

4 participants