Google OAuth 2授权 - 错误:redirect_uri_mismatch

本文翻译自:Google OAuth 2 authorization - Error: redirect_uri_mismatch

On the website https://code.google.com/apis/console I have registered my application, set up generated Client ID: and Client Secret to my app and tried to log in with Google. 在网站https://code.google.com/apis/console上我已经注册了我的应用程序,为我的应用设置了生成的客户端ID:客户端密钥 ,并尝试使用Google登录。 Unfortunately, I got the error message: 不幸的是,我收到了错误消息:

Error: redirect_uri_mismatch
The redirect URI in the request: http://127.0.0.1:3000/auth/google_oauth2/callback did not match a registered redirect URI

scope=https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email
response_type=code
redirect_uri=http://127.0.0.1:3000/auth/google_oauth2/callback
access_type=offline
approval_prompt=force
client_id=generated_id

What does mean this message, and how can I fix it? 这条消息是什么意思,我该如何解决? I use the gem omniauth-google-oauth2 . 我使用gem omn​​iauth-google-oauth2


#1楼

参考:https://stackoom.com/question/mBqJ/Google-OAuth-授权-错误-redirect-uri-mismatch


#2楼

The redirect URI (where the response is returned to) has to be registered in the APIs console, and the error is indicating that you haven't done that, or haven't done it correctly. 重定向URI(返回响应的位置)必须在API控制台中注册,错误表明您没有这样做,或者没有正确完成。

Go to the console for your project and look under API Access. 转到项目的控制台,查看API Access。 You should see your client ID & client secret there, along with a list of redirect URIs. 您应该在那里看到您的client IDclient secret ,以及重定向URI列表。 If the URI you want isn't listed, click edit settings and add the URI to the list. 如果未列出所需的URI,请单击编辑设置并将URI添加到列表中。

EDIT: (From a highly rated comment below) Note that updating the google api console and that change being present can take some time. 编辑:(从下面评价很高的评论)请注意,更新谷歌api控制台和存在的更改可能需要一些时间。 Generally only a few minutes but sometimes it seems longer. 一般只有几分钟但有时似乎更长。


#3楼

When you register your app at https://code.google.com/apis/console and make a Client ID, you get a chance to specify one or more redirect URIs. 当您在https://code.google.com/apis/console上注册应用并创建客户端ID时,您有机会指定一个或多个重定向URI。 The value of the redirect_uri parameter on your auth URI has to match one of them exactly. auth URI上redirect_uri参数的值必须与其中一个完全匹配。


#4楼

If you're using Google+ javascript button , then you have to use postmessage instead of the actual URI. 如果您使用的是Google+ javascript按钮 ,那么您必须使用postmessage而不是实际的URI。 It took me almost the whole day to figure this out since Google's docs do not clearly state it for some reason. 由于Google的文档由于某种原因没有明确说明,我花了差不多整整一天的时间来解决这个问题。


#5楼

Try to do these checks: 尝试进行这些检查:

  1. Bundle ID in console and in your application. 在控制台和应用程序中捆绑ID。 I prefer set Bundle ID of application like this "org.peredovik.${PRODUCT_NAME:rfc1034identifier}" 我更喜欢设置应用程序的Bundle ID,例如“org.peredovik。$ {PRODUCT_NAME:rfc1034identifier}”
  2. Check if you added URL types at tab Info just type your Bundle ID in Identifier and URL Schemes, role set to Editor 检查是否在选项卡上添加了URL类型信息只需在标识符和URL方案中键入您的Bundle ID,将角色设置为Editor
  3. In console at cloud.google.com "APIs & auth" -> "Consent screen" fill form about your application. 在cloud.google.com“API&auth” - >“同意屏幕”的控制台中填写有关您的应用程序的表单。 "Product name" is required field. “产品名称”是必填字段。

Enjoy :) 请享用 :)


#6楼

Make sure to check the protocol "http://" or "https://" as google checks protocol as well. 确保检查协议“http://”或“https://”作为谷歌检查协议。 Better to add both URL in the list. 最好在列表中添加两个URL。

你可能感兴趣的:(authentication,oauth-2.0,google-signin)