gpt4 book ai didi

android - 在基于 Android 的嵌入式设备上使用 Google OAuth 2

转载 作者:可可西里 更新时间:2023-11-01 18:48:04 29 4
gpt4 key购买 nike

我们有一个基于 Android 的嵌入式设备的应用程序,它使用 WebView,我们在其中使用 Google OAuth 2 登录该应用程序。遗憾Google will soon block OAuth 2 inside WebView ,我们有很多限制:

  • 该设备没有安装 Google 服务,所以可能没有 'official' way of logging in会工作(或者其中任何一个在没有 Google 服务的情况下也能工作?)
  • 我们不能只调用 Android 浏览器进行登录,因为它显示地址栏,这将允许用户上网,这是我们不允许的
  • 我们无法完全控制设备上安装的软件:无法安装 Google 服务、更新 Android 版本、安装 Google Chrome 等...,我们只能更新我们的应用。

有了这些限制,我们还能做什么?

最佳答案

通过浏览器实现:

1) 注册自定义 URI 方案 ( How to implement my very own URI scheme on Android ),例如 app-oauth2://

2) 在用户浏览器中发起访问请求

https://accounts.google.com/o/oauth2/v2/auth?
scope=...
access_type=offline&
include_granted_scopes=true&
state=state_parameter_passthrough_value&
redirect_uri=http://example.com/oauth2-handler&
response_type=code&
client_id=...

3) 如果用户在确认对话框中接受或拒绝请求的权限,它将被重定向到带有一些参数的redirect_uri ( http://example.com/oauth2-handler )

4) 在 redirect_uri 处理程序 ( http://example.com/oauth2-handler ) 一侧,使用参数重定向到自定义 URI 方案:

  • 成功: app-oauth2://?state=state_parameter_passthrough_value&code=...&scope=...#
  • 失败 app-oauth2://?error=access_denied&state=state_parameter_passthrough_value#

5) 在您的应用中,您可以从选项 4 中解析 URI 方案 app-oauth2:// 并接收代码以供将来使用或显示给用户的错误。

关于android - 在基于 Android 的嵌入式设备上使用 Google OAuth 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42947866/

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