简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM