简体   繁体   English

Google Oauth2 的 invalid_grant 错误问题

[英]Issue with invalid_grant error with Google Oauth2

Cheers everybody, we have been deeply reading google documentation on exchanging access_token from google in order our (delphi)desktop application to SSO with google from server side.大家干杯,我们一直在深入阅读关于从谷歌交换 access_token 的谷歌文档,以便我们的(delphi)桌面应用程序从服务器端与谷歌进行 SSO。 Here is the payload we send first look like:这是我们首先发送的有效载荷,如下所示:

https://accounts.google.com/o/oauth2/v2/auth?client_id=1000217514248-t1lojs6f8ed7l9ocrpbm98leahtum8n1.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&state=E1DF2FBA-0A66-4D69-B594-5EB8F7828AF7&scope=openid+profile&include_granted_scopes=true&code_challenge=C832DA50-E55A-499D-89B8-493BB4123C94&login_hint=test@Speelkriebel.be https://accounts.google.com/o/oauth2/v2/auth?client_id=1000217514248-t1lojs6f8ed7l9ocrpbm98leahtum8n1.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&state=E1DF2FBA-0A66- 4D69-B594-5EB8F7828AF7&scope=openid+profile&include_granted_scopes=true&code_challenge=C832DA50-E55A-499D-89B8-493BB4123C94&login_hint=test@Speelkriebel.be

Normally after this it redirects me to login in to our test user and after this according to the documentation we send a POST request to the end point token in order to get the access_token and refresh_token...: 'https://oauth2.googleapis.com/token with the following parameters, the 'code' is generated we also send it as follow:通常在此之后它会重定向我登录到我们的测试用户,然后根据文档我们向端点令牌发送 POST 请求以获取 access_token 和 refresh_token ...:'https://oauth2.googleapis .com/token 使用以下参数,生成“代码”,我们也将其发送如下:

 client_id=1000217514248-t1lojs6f8ed7l9ocrpbm98leahtum8n1.apps.googleusercontent.com grant_type=authorization_code client_secret=****** code= 4/1AY0e-g4GlavO38PI5Oo3vq04Pc4lMWN77et-02UiVWOsT-IyRQnU1lq19qo redirect_uri = urn:ietf:wg:oauth:2.0:oob

The response is always回应总是

 { "error_description": "Missing code verifier.", "error": "invalid_grant" }

We have tried to send the client secret id also, Does it have to do with our code_challenge?我们也尝试发送客户端秘密 ID,这与我们的 code_challenge 有关系吗? are the end points url and initial url okay?端点 url 和初始 url 好吗? What are we missing?我们缺少什么? We are using CEF4Delphi as "browser like experience in order for the user to type in their google credentials. We have been reading this: https://developers.google.com/identity/protocols/oauth2/web-server#offline We were also trying the playground: https://developers.google.com/oauthplayground/ we were sending the initial url in a chrome which generated a "code" and in the playground we inserted the code, and still got the same error of missing code verifier.我们使用 CEF4Delphi 作为“类似浏览器的体验,以便用户输入他们的谷歌凭据。我们一直在阅读: https://developers.google.com/identity/protocols/oauth2/web-server#offline我们是还尝试了操场: https://developers.google.com/oauthplayground/我们发送初始 url 的 chrome 生成了一个“代码”,在操场上我们插入了代码,但仍然得到相同的缺少代码的错误验证者。

Thanks Guys多谢你们

You seam to have URL encoded a lot of the values try not doing that.你接缝有 URL 编码了很多值尝试不这样做。 Also try using the basic call, before you start adding everything else.在开始添加其他所有内容之前,还可以尝试使用基本调用。 It should help you figure out which one of those extra parameters you are sending that's causing your issues.它应该可以帮助您确定您发送的那些额外参数中的哪一个导致了您的问题。

https://accounts.google.com/o/oauth2/auth?client_id={clientid}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=profile&response_type=code

Also make sure that the client id is from an installed / other type client还要确保客户端 ID 来自已安装/其他类型的客户端

This may also help Google 3 Legged OAuth2 Flow这也可能有助于Google 3 Legged OAuth2 Flow

For installed apps, the code challenge and verifier are parameters for enhancing the security of the OAuth flow through PKCE [1].对于已安装的应用程序,代码质询和验证程序是用于增强 OAuth 流通过 PKCE [1] 的安全性的参数。

There is additional documentation about generating a code challenge and verifier here [2].这里有关于生成代码质询和验证器的附加文档 [2]。

[1] https://tools.ietf.org/html/rfc7636 [1] https://tools.ietf.org/html/rfc7636

[2] https://developers.google.com/identity/protocols/oauth2/native-app#step1-code-verifier [2] https://developers.google.com/identity/protocols/oauth2/native-app#step1-code-verifier

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM