Google App Engine 和 Android App 的 Oauth2.0 流程
Oauth2.0 flow for Google App Engine and Android App
我看到一些与此问题相关的类似问题,但那些太老了,无法考虑,所以我会在这里再问一次。
我有一个 Android 应用程序需要对 Web 服务进行身份验证以交换将存储在 Google App Engine 上的数据。为此,我想使用 OAuth2.0 在我的应用程序和 Web 服务之间提供身份验证机制,如下所示:https://developers.google.com/identity/protocols/OAuth2WebServer?hl=en and here https://developers.google.com/identity/protocols/CrossClientAuth
我已经在 Web 服务端验证令牌,如文档中所示。我唯一不清楚的部分是在 Android 上获取刷新令牌并在 Web 服务上验证后,在 GAE Web 服务和 Android 上做什么。
问题是:
- 每次通信我都必须一直交换这个令牌吗
在应用程序和网络服务之间?它安全吗?
- 保持通信向前发展的最佳方式是什么?
对此进行研究后,我正在使用的身份验证流程:
- 按此处所示登录应用程序:https://developers.google.com/identity/sign-in/android/sign-in
- 登录后,获取token。
- 通过 HTTPS 将令牌发送到后端服务器
- 使用 GoogleIdTokenVerifier 验证程序(您也可以调用 tokeninfo 端点)在后端服务器上验证令牌,如下所示:https://developers.google.com/identity/sign-in/android/backend-auth
当您在后端服务器上收到令牌时,您应该:
After you receive the ID token by HTTPS POST, you must verify the integrity of the token. To verify that the token is valid, ensure that the following criteria are satisfied:
- The ID token is a JWT that is properly signed with an appropriate Google public key (available in JWK or PEM format).
- The value of aud in the ID token is equal to one of your app's client IDs. This check is necessary to prevent ID tokens issued to a malicious app being used to access data about the same user on your app's backend server.
- The value of iss in the ID token is equal to accounts.google.com or https://accounts.google.com.
- The expiry time (exp) of the ID token has not passed.
If your authentication request specified a hosted domain, the ID token has a hd claim that matches your Google Apps hosted domain.
- 用户已通过身份验证。每次与后端服务器通信,都必须在请求头上发送token,然后后端服务器每次都需要对其进行验证。
我看到一些与此问题相关的类似问题,但那些太老了,无法考虑,所以我会在这里再问一次。
我有一个 Android 应用程序需要对 Web 服务进行身份验证以交换将存储在 Google App Engine 上的数据。为此,我想使用 OAuth2.0 在我的应用程序和 Web 服务之间提供身份验证机制,如下所示:https://developers.google.com/identity/protocols/OAuth2WebServer?hl=en and here https://developers.google.com/identity/protocols/CrossClientAuth
我已经在 Web 服务端验证令牌,如文档中所示。我唯一不清楚的部分是在 Android 上获取刷新令牌并在 Web 服务上验证后,在 GAE Web 服务和 Android 上做什么。
问题是:
- 每次通信我都必须一直交换这个令牌吗 在应用程序和网络服务之间?它安全吗?
- 保持通信向前发展的最佳方式是什么?
对此进行研究后,我正在使用的身份验证流程:
- 按此处所示登录应用程序:https://developers.google.com/identity/sign-in/android/sign-in
- 登录后,获取token。
- 通过 HTTPS 将令牌发送到后端服务器
- 使用 GoogleIdTokenVerifier 验证程序(您也可以调用 tokeninfo 端点)在后端服务器上验证令牌,如下所示:https://developers.google.com/identity/sign-in/android/backend-auth
当您在后端服务器上收到令牌时,您应该:
After you receive the ID token by HTTPS POST, you must verify the integrity of the token. To verify that the token is valid, ensure that the following criteria are satisfied:
- The ID token is a JWT that is properly signed with an appropriate Google public key (available in JWK or PEM format).
- The value of aud in the ID token is equal to one of your app's client IDs. This check is necessary to prevent ID tokens issued to a malicious app being used to access data about the same user on your app's backend server.
- The value of iss in the ID token is equal to accounts.google.com or https://accounts.google.com.
- The expiry time (exp) of the ID token has not passed. If your authentication request specified a hosted domain, the ID token has a hd claim that matches your Google Apps hosted domain.
- 用户已通过身份验证。每次与后端服务器通信,都必须在请求头上发送token,然后后端服务器每次都需要对其进行验证。