redirect_uri_mismatch. Login with Google using Ruby on Rails
Try to downgrade the gem (could be compatibility problem) :
gem 'omniauth-oauth2', '~> 1.3.1'
Getting Error: redirect_uri_mismatch with google_oauth2
It looks like the request is hitting http://localhost:3000/auth/google_oauth2/callback
, but your specified redirect URI matching the similar pattern is for https
. Adding http://localhost:3000/auth/google_oauth2/callback
to your list of redirects may potentially solve that issue.
EDIT: Another potential fix is including a trailing /
in the corresponding redirect URIs, which appeared to work in this case.
redirect_uri_mismatch with OmniAuth Google oauth2 on Heroku
I figured out what the problem was. On the google developer console for my app, on
OAuth 2.0 Client IDs, I had created an ID with type "Other" instead of "Web application".
Creating a new one on https://console.cloud.google.com/apis/credentials?project=myproject with the type "Web application" and adding the callback url (both http and https) to Authorized redirect URIs solved the problem.
Error: redirect_uri_mismatch when using omniauth-google-oauth2
In console.developers.google.com. Enter your app’s URL plus
“/auth/google_oauth2/callback”
in “Authorized redirect URIs field. So It should be:
http://localhost:3000/auth/google_oauth2/callback
Google OAuth 2.0 and Devise - error : redirect_uri_mismatch
Allright, finally found out what was the problem...
The 'omniauth-google-oauth2'
gem only works with version 1.3.1 of the 'omniauth-oauth2'
gem.
So I changed my Gemfile like this:
# Social Networks Authentification
gem 'omniauth-oauth2', '~> 1.3.1' # Don't touch that unless you don't want Google omniauth to work!
gem 'omniauth-twitter'
gem 'omniauth-facebook'
gem 'omniauth-linkedin'
gem 'omniauth-google-oauth2' # Works only with omniauth-oauth2 v 1.3.1
And now everything works fine!
See this thread for more details.
Authorization Error, Error 400: redirect_uri_mismatch Gmail API
There are several types of auth lets look at two of them. The first being web which would be designed to work on a web server where the authorization is returned to the webservier itself to handle it. The second being an installed application which would return the response to local host or the endpoint which sent the reuqest.
The code you are following Ruby quick start states at the top that it is designed to work as a console application or installed app which is why you are seeing urn:ietf:wg:oauth:2.0:oob,that means localhost
Complete the steps described in the rest of this page to create a simple Ruby command-line application that makes requests to the Gmail API.
THe code used to authenticate with the two different types of clients is different. the code in your example is designed to work with an installed application there for for it to work you need to create installed native credentials on google developer console you have created web credentials which will not work with the code you are using.
for a web server application you should be following webauth
require 'google/apis/drive_v2'
require 'google/api_client/client_secrets'
client_secrets = Google::APIClient::ClientSecrets.load
auth_client = client_secrets.to_authorization
auth_client.update!(
:scope => 'https://www.googleapis.com/auth/drive.metadata.readonly',
:redirect_uri => 'http://www.example.com/oauth2callback',
:additional_parameters => {
"access_type" => "offline", # offline access
"include_granted_scopes" => "true" # incremental auth
}
)
Related Topics
Prefer %W(...) to a Literal Array
Are There Primitive Types in Ruby
Select Checkbox Pass Array in Ruby on Rails
How Do Version Numbers Work for Mri Ruby
How to Parse a Url and Extract the Required Substring
How to Click on a Specific Coordinates of an Element
How to Stringize/Serialize Ruby Code
How to Memoize a Method That May Return True, False, or Nil in Ruby
Error Installing SQLite3 Gem via Bundler
Ruby on Linux Pty Goes Away Without Eof, Raises Errno::Eio
Obtaining a Facebook Auth Token for a Command-Line (Desktop) Application
Is Regexp.Last_Match Thread Safe
How to Fix an Accidental 'Sudo Bundle Install Dir_Name'
How to Summarize Array of Integers as an Array of Ranges