question

gokcek avatar image
gokcek asked

iOS: Integrating Playfab with Google SignIn

We are trying to integrate Google SignIn to an iOS project that will use Playfab as a backend. Playfab requires that we create a "web client" on Google Cloud Console. However when we configure our app with a web client configuration, Google refuses to display the login page insisting that we use a iOS Client config.

As far as we understand, the web client is required to login to Playfab with the current OAuth 2.0 implementation which needs a ServerAuthCode and Client Secret pair. Google does not provide the Client Secret for iOS clients.

We understand that token-based authentication is deprecated on Playfab's side yet the auth token is all we have.

Does anyone know what would be the correct way to authenticate with GoogleSignIn on iOS, given the conundrum described above?

apis
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

gokcek avatar image
gokcek answered

Thanks for the answers, we finally figured out the issue! It was in the way we configured Google SignIn in our iOS project.

Google SignIn allows two clientID's to be configured on iOS. One is called clientID and the other is serverClientID. We were initially using the iOS clientID for both, which caused us to receive an invalid ServerAuthCode.

Here's the correct id's to be passed to Google in order to obtain a working ServerAuthCode:

GIDSignIn.sharedInstance().clientID = [YourGoogleCloudiOSClientID]

GIDSignIn.sharedInstance().serverClientID = [YourGoogleCloudWebClientID]

I hope this helps other people trying to integrate with a iOS/Google/Playfab configuration.

Thanks!

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

JayZuo avatar image
JayZuo answered

I'm not familiar with iOS development, but based on my experience, you will first integrate Google Sign-In into your iOS app. When you create an OAuth client ID, you should select "iOS" and this should automatically create a Web application type client named something like Web client (Auto-created for Google Sign-in).This Web application is the one that you used in PlayFab's Google Add-On page. You can configure the Web application and Google Add-On like what in this document: https://api.playfab.com/docs/tutorials/landing-players/sign-in-with-google.

Then in your iOS app, you should Enable Server-Side Access. The serverClientID is your Web application's Client ID. After that you would get serverAuthCode. Once you got serverAuthCode, you should be able to LoginWithGoogleAccount.


3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

gokcek avatar image gokcek commented ·

Hi Jay, Thanks for your detailed response, however this method does not work in iOS. On an iPhone, Google SignIn explicitly requires an "iOS Client" type to be used, and it does not present the login view if the client is configured as a "Web Client". As I explained in my question an iOS Client setup does not provide a Client Secret that Playfab requires in the setup.

0 Likes 0 ·
Andy avatar image Andy ♦♦ gokcek commented ·

I'm reading through some of the documentation here: https://developers.google.com/identity/sign-in/ios/offline-access

This specific comment seemed relevant:

// Set path to the Web application client_secret_*.json file you downloaded from the
// Google API Console: https://console.developers.google.com/apis/credentials
// You can also find your Web application client ID and client secret from the
// console and specify them directly when you create the GoogleAuthorizationCodeTokenRequest// object.

Is it possible that the client secret is obtained differently for an iOS client?

0 Likes 0 ·
JayZuo avatar image JayZuo ♦ gokcek commented ·

As I've said, you should use "iOS" for your iOS app, and use the Auto-created Web client (if there is no web client in your Credentials, you should create one) for PlayFab's Google Add-On page.

The iOS one is for your app in iPhone and the Web application one is for PlayFab's Google Add-On.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.