Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a Google account to authenticate users in Unity?

Firebase Authentication allows you to authenticate using auth tokens from other sign in providers (Facebook, Twitter etc). My app is intended to release on iOS and Android. I figured that authenticating with Google and Apple would give me a 99% coverage of all potential users. So far I have found that authenticating users with Google in Unity is a dreadful experience.

https://firebase.google.com/docs/auth/unity/google-signin The Firebase guide about Google auth only gives a guide on how to exchange the Google auth token for a Firebase auth token. Unlike the pages for other Firebase auth providers it doesn't even give a hint as to how you can acquire the Google auth token in the first place, not even mentioning a possible plugin.

https://github.com/googlesamples/google-signin-unity There is a project online that lets a user log in to Google with a Unity project. However, sign in is only possible when the project has been built and run on iOS or Android, it is not possible in the editor. Particularly for iOS, this makes development exhausting. A helpful user posted a workaround so it can run in the editor but this solution seems out of date. If Google was serious about supporting Google sign in it would have added this functionality a long time ago. As it is the project has not been updated in over a year.

https://github.com/playgameservices/play-games-plugin-for-unity Google does seem to be actively developing the Google Play Games api for Unity. However, it no longer supports iOS. Moreover, my app is not a game and this could cause some confusion. I would like users to be able to log into my app with any Google account, not just the current Play Games account.

I'm not sure what to do from here. My searches are growing less and less fruitful. Google does not seem to want developers to be able to implement a sign in solution. Meanwhile Apple is forcefully making their new sign in solution a condition of app store approval. I don't know what to do. Can anybody help?

like image 568
Phedg1 Avatar asked Nov 15 '19 17:11

Phedg1


People also ask

Does Google support Unity?

Stay organized with collections Save and categorize content based on your preferences. Google's official packages for Unity extend the default capabilities of Unity, enabling you to optimize game performance, reach new users, understand user behavior, and more.

Can I upload Unity game to Google Play?

You need to have a Google developer account (which requires one-time payment of $25). After setting up your account, you can start adding and publishing your applications to Google Play.


1 Answers

Leaving an answer because I could not leave a comment. It might not be an ideal solution for some but definitely a working one. I used PassportJS in my applications to authenticate user sign in.

  • Create a web login page using NodeJS and PassportJS.
  • When user clicks "Login with Google" open this webpage with a device id.
  • After user logs in, associate the logged in user with device id.
  • When user goes back to Unity application ask your web service for associated Google id with the device id.

You can expire this device id from database when a user is logged in to allow a different user to login into same device.

like image 152
Abhay Avatar answered Oct 08 '22 13:10

Abhay