首页 > 解决方案 > 谷歌设备认证后转发用户

问题描述

我有用户使用OAuth2ForDevices方法链接他们的 Google 套件帐户。将帐户链接到设备后,我想将用户转发到带有说明的另一个页面,而不是将它们留在通用谷歌页面“成功!设备已连接”。

这是当前的流程:

1) 从 POST 获取 device_code 和 user_code到 URL:https ://accounts.google.com/o/oauth2/device/code

curl -X POST \
  https://accounts.google.com/o/oauth2/device/code \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/x-www-form-urlencoded' \
  -d 'client_id=<hidden>&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar'

回复

{
  "device_code": "ab-cdef...",
  "user_code": "ABCD-ABCD",
  "expires_in": 1800,
  "interval": 5,
  "verification_url": "https://www.google.com/device"
}

如果我附加诸如foo=barforward_url=之类的参数,则响应仍然与上面相同。

redirect_uri= http://localhost:8080会报错,所以这个参数显然是被识别的。

{
  "error": "invalid_request",
  "error_description": "Invalid redirect URI"
}

问题似乎不是 URL,因为以下请求工作正常:我管理 t

https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=<client_id>&redirect_uri=http://localhost:8080&scope=https://www.googleapis.com/auth/calendar

2)让用户确认verification_url(https://www.google.com/device

3)“成功!设备已连接”

我尝试了一堆域和 URL:s 已在谷歌搜索控制台中确认并添加到https://console.cloud.google.com中的域验证

值得一提*:我注意到谷歌云平台的行为方式很奇怪,删除了早期验证的域——当我添加新域时:https ://console.cloud.google.com/apis/credentials/domainverification?project= &pli=1&authuser=1

我的理论:1)在使用OAuth2ForDevices方法时,根本不可能添加 redirect_uri 。2) Google Cloud Platform 中有一个错误*,它显示我的域,但这是缓存数据。

*越野车??谷歌

标签: restapioauth-2.0google-apigoogle-cloud-platform

解决方案


推荐阅读