{ "error" : "redirect_uri_mismatch" }

28 views
Skip to first unread message

cunhasb1

unread,
Jan 12, 2018, 8:44:20 PM1/12/18
to Google API Client for Ruby
Hello I'm trying to setup up an oauth2 webapp (front end written in react, backend in rails). On the front end I'm able to get authenticate and ket my access code, after that through my callback function on redirected to my back server, where I'm trying to exchange my front end code for a token, below is my code on the back end. 
I am initializing a new auth_client and it is being updated properly (client_secrets and code). The problem is when I'm requesting my exchange token, it is giving me a 

*** Signet::AuthorizationError Exception: Authorization failed.  Server message:

{

  "error" : "redirect_uri_mismatch"

}


I don't know how to solve that, the redirect address is being loaded from the client_secret, I've confirmed it, I tried to update it again using auth_client.update!, same problems. My routes do exist, tried them, I was using localhost before, but was getting same error, through web search was able to find recommendations of the use of lvh.me

I don't know what else to try, I would really appreciate if someone could give me some direction, this is for a capstone project due on Wednesday, and I everything else depends on it...

Thank you in advance for any help ....







require 'google/api_client/client_secrets'
require 'fileutils'
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!(
      :redirect_uri => 'http://lvh.me:3000/api/v1/current_user'
      :additional_parameters => {
        "access_type" => "offline",         # offline access
        "include_granted_scopes" => "true"  # incremental auth
      }
    )
    auth_client.code = params["code"]
    result = auth_client.fetch_access_token!
  end
  def show
    byebug
  end

end

client_secrets.json

{
  "web": {
    "client_id":
      "<MY_CLIENT_ID",
    "project_id": "storied-pixel-191717",
    "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/current_user"],
    "scope":
  }
}

cunhasb1

unread,
Jan 13, 2018, 9:44:21 PM1/13/18
to Google API Client for Ruby
Ok... so I was able to make it work just had to replace my redirect_uri with  'postmessage', that did the trick. 
Reply all
Reply to author
Forward
0 new messages