安全谷歌加登入到通过Android应用程序的Web应用程序应用程序、登入、安全、Web

2023-09-05 04:26:47 作者:为他提剑平丘壑

我开发一个Android应用程序,我希望用户使用Google+登录功能来登录到我的应用程序。

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

目前,我通过我Google+中得到内PHP登录脚本的用户名。脚本加载新会话与用户的ID。

At the moment, I pass the user's name which I get from Google+ within a PHP login script. The script loads a new session with the user's ID.

目前,该网站是非常不安全的:谁知道其他用户的用户名可能会登录为它们

Currently, the site is highly insecure: anyone who knows another user's username can potentially login as them.

什么是安全的方式做到这一点?

What is a secure way to do this?

如何授权对我的服务器的用户?

How do I authorize a user against my server?

它看起来像我,谷歌是一个纯粹的社交API ...

It looks like to me, Google+ was purely a social networking API...

推荐答案

Google+登录功能使用的OAuth 2.0 - 这意味着用户不直接与您的服务器进行身份验证。相反,他们进行身份验证与谷歌,并获得由谷歌签署的令牌。您的应用程序获取令牌(从谷歌Play业务在Android),并可以将它传递到你的服务器,以证明用户身份验证与谷歌。然后,用自己的服务器上一个新的或现有的用户ID的用户的Google+ ID相关联。因此,只要用户能证明他们与谷歌认证的特定Google+的用户ID,你把他们当作验证自己的服务器上。

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:

如果你只是想你的用户来验证自己的服务器:因为他们在客户经理一个谷歌帐户在Android设备的用户往往已经与谷歌进行身份验证。您的应用程序可以利用这一点,并获得在帐户管理器的用户令牌他们无需输入任何密码。用户点击登录与谷歌在你的应用程序后,您可以使用 GoogleAuthUtils.getToken()获取他们一个ID令牌,并将其传递到你的服务器。您的服务器,验证了谷歌的签名后,就可以安全地将用户会话使用适当的用户帐户和权限相关联(即对待会话认证)。获得该令牌和验证它的过程由添布雷此处通过伊恩·巴伯这里。 如果你想给用户身份验证自己的服务器和从服务器让Google+的API调用:那你应该看看在的 developers.google.com上服务器端的流量文档。这需要同样的方法为选项之一,但除此之外,当为第一时间的Andr​​oid应用程序请求授权code,而不是一个ID令牌用户的迹象。 /:通过使用