大约一周以来,我一直无法处理 YouTube API 的 Google OAuth。
当我像这样请求授权时:
http://accounts.google.com:443/o/oauth2/v2/auth?state=STATE&client_id=CLIENT_ID&redirect_uri=REDIRECT_URI&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube.force-ssl+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&access_type=offline
范围明确定义,无需 openid。
但是,在回调时,这就是返回的内容
/youtube/auth/callback?state=STATE&code=CODE&scope=email+profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube.force-ssl+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube+openid&authuser=0&prompt=none
开放 ID 已添加到范围中
完成令牌的代码交换后,响应现在包含 id_token 而不是刷新_token,并且范围不同(持续)
{"access_token"=>"ACCESS_TOKEN", "expires_in"=>3599, "scope"=>"https://www.googleapis.com/auth/youtube.force-ssl https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/youtube openid", "token_type"=>"Bearer", "id_token"=>"ID_TOKEN"}
这是什么原因造成的?
任何开放 ID 范围或签名范围都会导致返回令牌 ID。
这些是我确信会的,电子邮件也可以,但我不确定。
您没有获得刷新令牌的原因是,网络应用程序仅在您第一次授权用户时返回刷新令牌,Google 假定您已存储该令牌以供以后使用。因此,再次撤销用户访问请求访问权限,您应该会得到一个刷新令牌。如果这不起作用,请用户在安全状态下进入他们的谷歌个人资料,并让他们在那里删除它。