gpt4 book ai didi

java - 使用 Google 验证用户身份

转载 作者:行者123 更新时间:2023-12-01 12:45:30 25 4
gpt4 key购买 nike

我很难理解如何在 REST 服务中对用户进行身份验证。我计划使用 Google 登录(即在 Android 上)。我不太清楚如何在我的服务器上对用户进行身份验证。我不想获得任何授权(除了验证用户的身份之外),我想做的就是当我收到请求时,验证用户是否是他(或她)所说的人。

我的理解是,用户将登录,从 Google 获取某种 token ,然后将该 token 连同他的请求一起发送到我的服务器,我将用它来验证他的身份。然而,根据我的阅读,用户将在 JWT(json Web token )中对他们的请求进行编码,然后我将使用它来验证他们的身份,而无需直接与 Google 服务器对话。我理解正确吗?

在 Google 上 documentation ,它说

If you do not require offline access, you can retrieve the access token and send it to your server over a secure connection. You can obtain the access token directly using GoogleAuthUtil.getToken() by specifying the scopes without your server's OAuth 2.0 client ID.

但它没有说明服务器应该如何处理 token 。

最佳答案

您有一个 Android 应用程序,允许用户通过 Google+ 登录进行登录,然后此 Android 应用程序将调用您的 REST API。您想要的是您的服务如何验证此请求。此 Android 客户端将使用 token 向您的服务发送请求,您需要验证此 token 以进行身份​​验证。我的理解对吗?

如果是这样,您需要验证发送到您的服务的 token 。您提到的引用资料适用于 Google API 调用(就您而言);这是您自己的服务 API 调用。对于Android端,只需按照引用,在您的服务端您可以使用TokenInfo validation对用户进行身份验证。

关于java - 使用 Google 验证用户身份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24740838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com