Secure Google Plus Sign-in into Web App via Android App

后端 未结 2 2252
独厮守ぢ
独厮守ぢ 2021-02-10 16:52

I\'m developing an Android app and I want users to sign-in to my app using Google+ Sign-In.

At the moment, I pass the user\'s name which I get from Google+ within a PHP

相关标签:
2条回答
  • 2021-02-10 17:23

    Google Plus uses OAuth 2.0 https://developers.google.com/+/api/oauth

    It has auth token. You can use auth token to access Google Plus from Android or server. On server you can verify token by accessing Google with that token.

    0 讨论(0)
  • 2021-02-10 17:28

    Google+ Sign-In uses OAuth 2.0 - which means the user does not authenticate directly with your server. Instead they authenticate with Google and obtain a token signed by Google. Your app gets that token (from Google Play services on Android) and can pass it to your servers as proof that the user authenticated with Google. You then associate the users Google+ ID with a new or existing user ID on your own servers. So whenever a user can prove that they authenticated with Google for a specific Google+ user ID, you treat them as authenticated on your own server.

    To implement, you have a few options depending on how you architect your system:

    1. When you simply want to authenticate your user to your own servers: On an Android device your user is very often already authenticated with Google because they have a Google account in the account manager. Your app can take advantage of this and obtain a token for a user in the account manager without them having to type any passwords. After the user clicks 'Sign in with Google' in your app, you can fetch an ID token for them using GoogleAuthUtils.getToken() and pass it to your server. Your server, after verifying the Google signature, can then safely associate the users session with the appropriate user account and permissions (ie. treat the session as authenticated). The process of getting the token and verifying it is discussed by Tim Bray here and by Ian Barber here.
    2. If you want to authenticate the user to your own servers and make Google+ API calls from your servers: Then you should take a look at the server side flow documentation on developers.google.com. This takes the same approach as option one, but in addition, when the users signs in for the very first time the Android app requests an authorization code instead of an ID token. This can be exchanged by the server for an access token and refresh token - which, in turn, can be used by your server to make API calls on behalf of the user, for example, by using the PHP client library.
    3. If you want to authenticate the user to your own servers, but also make Google API calls from the Android device: Then you should use the PlusClient provided by Google Play services to make Google API calls in addition to the steps you take to authenticate the user with your own server.

    You probably want to make Google API calls in your client or on your server so that you can pre-populate your registration form with data from the users Google+ profile, for example.

    0 讨论(0)
提交回复
热议问题