Omniauth with FourSquare issue - ruby-on-rails

UPDATE 2011/05/01:
I later carefully read through FourSquare's API document, and found it says:
(Note that the request parameters are not JSON, they are standard HTTP keys and values.) All authentication is via OAuth2, which means that all requests MUST be https.
Could this be the problem that I don't have a SSL connection in my development machine?
Hi all! I am trying to connect FourSquare via Omniauth, I followed the Railscast toturial below, and change the provider into foursquare. But the return is always "invalid_credentials". I googled around and find that there's a discussion about this on GitHub(links below), but seems no conclusion yet.
Anyone has idea what went wrong?
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, "XXXXXXX","XXXXXXX"
provider :foursquare, 'XXXXXXX',
'XXXXXXX'
end
RailsCast Link
Discussion on GitHub

I have a gem which will work with omniauth for foursquare.
https://github.com/arunagw/omniauth-foursquare

try to modify your provider initializer to point to your system's certificate path ("/etc/ssl/certs" on Ubuntu)
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, "XXXXXXX","XXXXXXX"
provider :foursquare, 'XXXXXXX', {:client_options => {:ssl => {:ca_path => "/etc/ssl/certs"}}}
end

Your config looks fine, although you probably don't want to share your token/secret keys publicly.
Does the callback url that you used when registering your foursquare oauth consumer match the URL that you're testing with? If you used http://www.foo.com/auth/foursquare/callback when registering your consumer, but are testing on your dev environment (http://localhost:3000/..), you'll see that auth/failure error.

Here's what I did: OmniAuth Invalid Response Error

Related

Omniauth-facebook Rails 6: Invalid App ID

I am using Rails 6.0.0, Devise 4.7.1, and , omniauth-facebook 5.0.0.
I was able to get omniauth to work successfully with twitter via omniauth-twitter (which I notice currently happens to use oauth 1.0 as opposed to oauth 2.0).
I was also able to get omniauth to work successfully with google via omniauth-google-oauth2 which uses oauth 2.0.
I am not having the same luck with omniauth-facebook (which happens to use oauth 2.0).
The initalizers/devise.rb file is where the main config is in order to specify the provider and then the app_id and app_secret for each provider. Here is what I have (of course with a placeholder for the real app_id and secret):
config.omniauth :facebook, "my-app-id", "my-app-secret-key", scope: "email"
config.omniauth :twitter, "my-app-id", "my-key"
config.omniauth :google_oauth2, "my-client-id", "my-client-seceret"
Again, it works just fine with twitter and google. But when I click the "Sign in With Facebook" link it shows this on facebook:
I am stumped because I know I entered the app ID correctly. The status of the app is "Live" as opposed to "Development (which required me to provide a Privacy Policy URL).
Since omniauth-twitter works, it makes me wonder if something is wrong on the provider end (facebook) or perhaps there is something wrong with the omniauth-facebook gem? Of course: I will never rule out that I am missing something obvious.
I am using https for my app (https now appears to be a requirement in order to use this service from facebook), so that isn't the issue either.
I was able to solve this by simply changing:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ENV['APP ID'], ENV['APP SECRET']
end
to
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, 'APP ID','APP SECRET'
end

Oauth Unauthorized Ruby

I'm having trouble configuring my Twitter Oauth in a RubyonRails webapp.
The full trace error: http://pastebin.com/2yf1cE8E
The User.rb http://pastebin.com/UUTiTKvy
The app controller http://pastebin.com/bK9ghUJR
The session controller http://pastebin.com/kxYRd1TU
The routes.rb http://pastebin.com/bt7HMRFy
Omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, 'JsR9zFGrVuDYuFueRnBQK9tpp', ' tDubF5v9uDRvfio7UBZd2XlFYUQQrftE7Qzk6FPaNOucOTWVlf'
end
Thanks, Alex.
Looking at the error, I think you did not define the callback url of Twitter. You have to go into twitter applications and define the URL of your webapp in your callback.
Looking at the error and the code you provided, you're not properly authenticating to Twitter. The 401 response is basically telling you that Twitter doesn't like the identity information you're passing in. So I would verify your keys are correct, and that OmniAuth doesn't require any additional configurations (e.g. specific endpoints Your second key in the Omniauth middleware code appears to have additional spaces in it, you may have done that for security purposes, but I'm pretty sure that keys shouldn't start with spaces.
IMPORTANT NOTE: Once you've confirmed a fix, you should request new keys for your Twitter account, as they have been posted publicly to this forum.

OAuth::Unauthorized 400 error with Google+ login API

I'm trying to set up Google+ login with Devise and omniauth in an app I'm working on and running into an OAuth::Unauthorized 400 error. I'm using the omniauth-google gem. My Devise config sets up omniauth for Google:
config.omniauth :google, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'], scope: 'plus.login'
I'm running the site locally on dev.app.com:3000, and in my app settings in the Google Developers Console I've set the JavaScript origin to be http://dev.app.com:3000 and the redirect URI to be http://dev.app.com:3000/users/auth/google/callback. I've confirmed that my key and secret are correct. What's the problem here?
I am not seeing any problem there, you can get better picture with this tutorial
[https://www.digitalocean.com/community/tutorials/how-to-configure-devise-and-omniauth-for-your-rails-application
or u can try
omniauth-google-oauth2
https://github.com/zquestz/omniauth-google-oauth2
The omniauth-google 1.0 strategy for google is deprecated. That said, nothing appears wrong with your configuration.
You're better of switching to OAuth 2.0, unless you have a very compelling reason not to. Notice that the provider symbol has changed from :google to :google_oauth2. After you switch, it should look like:
provider :google_oauth2, ENV["GOOGLE_KEY"], ENV["GOOGLE_SECRET"]

403 Insufficient permissions error while trying to get Google Analytics data

I'm developing RoR application, which allows user to login with google account and download/upload report data from one of his analytics account.
I use omniauth-google-oauth2 gem for authorization with google account and google-api-client for interaction with Google Analytics.
The problem is that when I try to get accounts list with analytics.management.accounts.list method, passing google token as one of authorization parameters, GA responds with 403 Insufficient permissions error.
I suppose, I have to make user to give permission for reading Analytics data in process of authorization. How can I do this?
I've read a lot of related questions, but didn't find solution to my exact problem.
Here is the code:
require 'google/api_client'
client = Google::APIClient.new(:application_name => 'something you like', :application_version => '1')
client.authorization.access_token = 'HERE_GOES_TOKEN'
ga = client.discovered_api('analytics', 'v3')
client.execute(:api_method => ga.management.accounts.list)
Solved the problem! I had to write proper scopes in OAuth configs.
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, PROVIDER_KEY, PROVIDER_SECRET,
{
:scope => "email, profile, https://www.googleapis.com/auth/analytics, https://www.googleapis.com/auth/analytics.edit, https://www.googleapis.com/auth/analytics.manage.users, https://www.googleapis.com/auth/analytics.readonly",
}
end

Connection failed for google open_id using omniauth

I am trying to add open-id functionality to my app, I am using omniauth and omniauth-openid gems for same.
I have done the installation steps added it to initializer as middleware,
require 'omniauth-openid'
require 'openid/store/filesystem'
Rails.application.config.middleware.use OmniAuth::Builder do
provider :open_id, :store => OpenID::Store::Filesystem.new('/tmp')
end
and a routes for andling callback
match '/auth/:provider/callback' => 'callback#myauthentication'
when I try to hit this url, to connect to google provider
http://[mydomain]/auth/open_id?openid_url=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2Fid
I get connection failed error everytime
For Yahoo
http://[mydomain]/auth/open_id?openid_url=http%3A%2F%2Fme.yahoo.com%2F
Furthur if I try with yahoo open id , even after authenticating correctly I get invalid_credentials error
Update 1:
I am using apache web server, and thin/webrick app server. I verified that if I am not behind a apache web server and run directly as localhost:3000 it works fine. Why does omniauth behave differently
Try this gem https://github.com/zquestz/omniauth-google-oauth2, I've had good results with it.

Resources