将代码更新到新范围时遇到问题。目前我使用userinfo.profile
并且一切正常。
根据Google+ OAuth 2.0 范围,新plus.me
范围允许应用程序知道用户是谁,并plus.login
提供额外的访问权限(年龄、语言、圈子等)。
如果我替换userinfo.profile
为plus.me
- 一切正常:方法WebServerClient.RequestUserAuthorization
授权用户并ProcessUserAuthorization
给我一个令牌。
但是,如果我plus.login
改为询问范围 - Google 会在我的回调和下一次调用WebServerClient.ProcessUserAuthorization
失败时添加额外的查询参数,因为实现使用当前 rul 来生成新redirect_url
的、条带化“已知”参数并留下“新未知”Google 参数。他redirect_url
在 Google Api Console 中注册时不匹配,并且 Google 服务器返回 400 响应。
这是来自授权范围的成功响应plus.me
(来自 NetOpenAuth.Messaging.Channel 日志):
Incoming HTTP request: GET http://localhost:40004/Me/LoginComplete?from=Google&state=TWXf6Zq3XYSlwyfCDt3GiQ&code=4/qC_KeuiykcVm1sayIyEdnBjiklxz.AoMfk5TqaXQcsNf4jSVKMpY-GxwThAI
After binding element processing, the received EndUserAuthorizationSuccessAuthCodeResponse (2.0) message is:
code: 4/qC_KeuiykcVm1sayIyEdnBjiklxz.AoMfk5TqaXQcsNf4jSVKMpY-GxwThAI
state: TWXf6Zq3XYSlwyfCDt3GiQ
from: Google
这是(成功)具有plus.login
范围的授权响应:
Incoming HTTP request: GET http://localhost:40004/Me/LoginComplete?from=Google&state=26R-O3YN6u3-5EKIlJzFFw&code=4/zOoeVq8vec068x2-CyPq4PjPNtRT.osemzp8Zl7sQsNf4jSVKMpbcmWQThAI&authuser=0&prompt=consent&session_state=27ca4bd2e70d0721bc1fa781b900a558e59fe4c7..d409
After binding element processing, the received EndUserAuthorizationSuccessAuthCodeResponse (2.0) message is:
code: 4/zOoeVq8vec068x2-CyPq4PjPNtRT.osemzp8Zl7sQsNf4jSVKMpbcmWQThAI
state: 26R-O3YN6u3-5EKIlJzFFw
from: Google
authuser: 0
prompt: consent
session_state: 27ca4bd2e70d0721bc1fa781b900a558e59fe4c7..d409
Call for token (for plus.me
scope) 将成功:
Prepared outgoing AccessTokenAuthorizationCodeRequestC (2.0) message for https://accounts.google.com/o/oauth2/token:
code: 4/qC_KeuiykcVm1sayIyEdnBjiklxz.AoMfk5TqaXQcsNf4jSVKMpY-GxwThAI
redirect_uri: http://localhost:40004/Me/LoginComplete?from=Google
grant_type: authorization_code
client_id: 175802076419.apps.googleusercontent.com
client_secret: ********
但是使用plus.login
范围 3 新参数(authuser、prompt、session_state)被转移到redirect_url
参数:
Prepared outgoing AccessTokenAuthorizationCodeRequestC (2.0) message for https://accounts.google.com/o/oauth2/token:
code: 4/zOoeVq8vec068x2-CyPq4PjPNtRT.osemzp8Zl7sQsNf4jSVKMpbcmWQThAI
redirect_uri: http://localhost:40004/Me/LoginComplete?from=Google&authuser=0&prompt=consent&session_state=27ca4bd2e70d0721bc1fa781b900a558e59fe4c7..d409
grant_type: authorization_code
client_id: 175802076419.apps.googleusercontent.com
client_secret: ********
一旦此 redirect_url 与已注册不匹配,我就会收到错误:
https://accounts.google.com/o/oauth2/token returned 400 BadRequest: Bad Request
OAuth2 规范说在授权响应中需要这些参数code
,state
并说要注意添加其他参数。但它也说
客户端必须忽略无法识别的响应参数
这是否意味着这是 DNOA 问题而不是 Google 问题?
可能是 DNOA 必须将可为空的 responseUri 参数添加到 ProcessUserAuthorization 并使用它而不是从当前 url 猜测...
最简单的解决方法是什么(使用 Google 库除外)?
更新:
这是对 /oauth 的原始请求
Prepared outgoing EndUserAuthorizationRequestC (2.0) message for https://accounts.google.com/o/oauth2/auth:
client_id: 175802076419.apps.googleusercontent.com
redirect_uri: http://localhost:40004/Me/LoginComplete?from=Google
state: TWXf6Zq3XYSlwyfCDt3GiQ
scope: https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/plus.me
response_type: code