android - 谷歌播放服务 sdk : Requesting for offline access during auth

标签 android oauth-2.0 google-oauth google-play-services google-authentication

有没有办法在 Android 上使用 Google Play 服务 SDK 请求离线访问?我知道 raw HTTP api可以选择通过请求刷新 token 来执行此操作,但无法通过新的 Google Play services sdk 找到执行此操作的方法.

新的 SDK 使用 GoogleAuthUtil.getToken() 方法为应用程序提供访问 token ,但访问 token 每小时都会过期。我可以发出原始 http 请求并让用户从 WebView 或浏览器登录,但我更喜欢使用 sdk 在 native 执行此操作的方法,因为这对用户来说是更好的体验。

最佳答案

四处搜索谷歌文档,看起来这确实是可能的。 Google 在其 "Hybrid Apps" 下称此为“跨客户端身份”类别。

您显然可以修改传递给 GoogleAuthUtil.getToken(...) 方法的范围参数的字符串,以诱导它返回“授权代码”而不是 OAuth2 token 。 (对于它们之间的区别,我发现 this chart 很有帮助。)

详情为here ,特别是标题为 "Android app obtains offline access for Web back-end" 的最后一节.

看来您需要将以下内容作为“范围”字符串传递给 getToken:

oauth2:server:client_id:<your_server_client_id>:api_scope:<scope_url_1> <scope_url_2> ...

然后文档声称:

In this case, GoogleAuthUtil.getToken() will first require that the user has authorized this Project for access to the two scopes. Assuming this is OK, it will return, not an OAuth token, but a short-lived authorization code, which can be exchanged for an access token and a refresh token.

免责声明:我自己还没有尝试过;我们的 Android 开发人员很快就会。如果这对您有用,请报告。

关于android - 谷歌播放服务 sdk : Requesting for offline access during auth,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15513909/

相关文章:

ios - Google 登录页面 - 登录以继续使用 companyName

android - 显示空白的沉浸式模式

android - 获取选项卡式 Activity 中当前选项卡的编号

java - "Google play App - signing issue"NoSuchAlgorithmException异常

java - 可部署的 Spring Boot Wars OAuth2 拒绝异常

java - Vertx - 使用 OAuth2 保护路由时缺少 GET 参数

security - 为cordova 混合移动应用程序选择哪种Google Oauth 2.0 客户端ID 类型?

android - android中的"Ə"字符

java - 如何验证 Google Contacts API 的 Java 应用程序?

google-oauth - 如何在不使用 client_secret 的情况下为 Google Cloud 上的 OIDC 身份验证登录启用 PKCE 流程?