首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google >{ "error“:"redirect_uri_mismatch”}

Google >{ "error“:"redirect_uri_mismatch”}
EN

Stack Overflow用户
提问于 2018-01-13 03:57:03
回答 1查看 292关注 0票数 1

我正在尝试设置一个oauth2 end应用程序(前端用react编写,后端用rails编写)。在前端,我能够获得身份验证和插入我的访问代码,然后通过我的回调函数重定向到我的后端服务器,在那里我试图将我的前端代码交换成一个令牌,下面是我在后端的代码。

我正在初始化一个新的auth_client,并且正在正确地更新它(client_secrets和代码)。问题是当我要求换币的时候,它给了我一个

* Signet::AuthorizationError异常:授权失败。服务器消息: { “错误”:"redirect_uri_mismatch“ }

我不知道如何解决这个问题,重定向地址是从client_secret加载的,我已经确认了,我尝试使用auth_ ient.update!再次更新它,同样的问题。我的路线确实存在,尝试过,我以前也使用过本地主机,但也得到了同样的错误,通过网络搜索能够找到推荐使用lvh.me的方法。我还试图把它发送到一个不同的控制器(路由) http://localhost:3000/api/v1/users,它也有Post,但同样的错误.

我不知道还能做些什么,我真的很感激有人能给我一些指导,这是周三的一个顶点项目,我其他的一切都取决于它.

谢谢您的帮助.

代码语言:javascript
复制
require 'google/api_client/client_secrets'
class Api::V1::AuthController < ApplicationController
  def create
    client_secrets= Google::APIClient::ClientSecrets.load("client_secrets.json")
    auth_client = client_secrets.to_authorization
    auth_client.update!(
      :scope => 'profile https://www.googleapis.com/auth/gmail.readonly https://www.googleapis.com/auth/gmail.send',
      :redirect_uri => 'http://lvh.me:3000/api/v1/auth'
    )
    auth_client.code = params["code"]
    result = auth_client.fetch_access_token! <-----Breaks here------->
  end


end

我的路线..。

代码语言:javascript
复制
Rails.application.routes.draw do
  namespace :api do
    namespace :v1 do
      resources :users
      post '/auth',to:'auth#create'
      get '/current_user', to: 'auth#show'
    end
  end
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end

我授权在Google仪表板上重定向URI ..。

代码语言:javascript
复制
http://lvh.me:3000/api/v1/auth
http://localhost:3000/api/v1/auth
http://localhost:3000/api/v1/users
http://lvh.me:3000/api/v1/users

我的client_secrets.json。

client_secrets.json

代码语言:javascript
复制
{
  "web": {
    "client_id":
      "<MY_CLIENT_ID",
    "project_id": "storied-pixel-191717",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://accounts.google.com/o/oauth2/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "<MY_CLIENT_SECRET>",
    "redirect_uris": ["http://lvh.me:3000/api/v1/auth", "http://localhost:3000/api/v1/auth","http://localhost:3000/api/v1/users","http://lvh.me:3000/api/v1/users"],
    "scope":
      "profile https://www.googleapis.com/auth/gmail.readonly https://www.googleapis.com/auth/gmail.send",
  }
}
EN

回答 1

Stack Overflow用户

发布于 2018-01-14 02:47:24

好的..。我能够让它开始工作,只需要用'postmessage‘代替我的redirect_uri。这对我起了作用。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48236799

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档