rails login facebook api debug - ruby-on-rails

I'm using devise and omniauth-facebook authentication in my rails application.
Facebook has moved on to v2.x graph API. (deadline for api migration is April 30, 2015).
I configure my omniauth-facebook in initializer file as:
provider :facebook, ENV['APP_ID'], ENV['APP_SECRET'],
:scope => 'email,read_stream',
:client_options => {
:site => 'https://graph.facebook.com/v2.0',
:authorize_url => "https://www.facebook.com/v2.0/dialog/oauth"
}
But...how I can know that the calls are actually doing in the 2.x api version and not the 1.x I had before?.
Thanks

You could add the gem http_logger to your gemfile. You will then see the server-side http requests in your log:
[DEBUG] HTTP POST (123.07ms) https://graph.facebook.com:443/v2.0/oauth/access_token

Related

Site url getting overridden using rails oauth2 plugin

I am using ruby oauth2 gem
I have my site URL as
site = "https://192.168.5.15:9443/oauth2/authorize"
but once i call
client.auth_code.authorize_url(:redirect_uri => redirect_uri)
My URL is changed to
https://192.168.5.15:9443/oauth/authorize?client_id=J7H_LoEIdaf9aVXF_opqtVMLgwoa&redirect_uri
So my oauth2/authorize is being replaced by oauth/authorize
Is there any way to fix this?
Thank you in advance.
You need to pass the :authorize_url attribute.
require 'oauth2'
client = OAuth2::Client.new('client_id', 'client_secret', :authorize_url => '/oauth2/authorize', :site => 'https://192.168.5.15:9443')

Omniauth-google-oauth2 not correctly passing "scope" for oauth

First, the context: I'm writing a little web app to do some custom Google Analytics reporting for me.
In my Gemfile:
gem 'omniauth'
gem 'omniauth-google-oauth2'
In my config/initializers/omniauth.rb:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, ENV["GOOGLE_KEY"], ENV["GOOGLE_SECRET"]
{
:scope => "userinfo.email,userinfo.profile,analytics.readonly",
:approval_prompt => "auto"
}
end
When I get to the auth screen on google, it's only asking me for userinfo.email and userinfo.profile permissions, and nothing for analytics.readonly.
Looking at the URL when I'm auth'ing, I can see that it's only requesting the first two permissions. If I manually add the analytics permission, it grants the correct permissions. So, I've narrowed the issue down to
How I'm passing scope to the omniauth-google-oauth2 strategy, or
How the strategy is handling/ignoring the scope hash.
Also, I have double-checked that the Analytics API is turned on for my OAuth keys in the Google API Console.
Poorly formatted code, I was missing a comma after ENV["GOOGLE_SECRET"]. Below is the fixed code.
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, ENV["GOOGLE_KEY"], ENV["GOOGLE_SECRET"],
{
:scope => "userinfo.email,userinfo.profile,analytics.readonly",
:approval_prompt => "auto"
}
end

devise + omniauth auth/failure?message=invalid_credentials

after i added an application in twitter when i request for an authentication in twitter (/auth/twitter) i get these error message
http://localhost:3000/auth/failure?message=invalid_credentials
Routing Error
No route matches "/auth/failure"
how can i add a valid credential or is there any ssl certificate that must be included in requesting for twitter auth??
my facebook authentication just works fine after i added a parameter ssl certificate that looks like this
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook,'xxx', 'xx', { :scope => 'publish_stream,offline_access,email',:client_options => { :ssl =>{ :ca_path => "/etc/ssl/certs" } }}
provider :twitter, 'xx','xxx' #,{ :client_options => { :ssl =>{ :ca_path => "/etc/ssl/certs" } }}
end
i've same problem with you, it happen because oauth_token in twitter login only valid on once request. May be your application trying to refresh when authentication to twitter.
when i've problem like you, my apps trying to refresh the webpage with
window.opener.location = "#{request.fullpath}";
Until now i'couldn't find how to popup a window when login using twitter. I'm using omniauth and rails 3.0.3. Thanks
This is all you need
site url http://localhost:3000/

How do I use the access token in omniauth for Facebook?

I have set this in the initializer
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook , 'app' , 'secret' , {:scope => "manage_pages"}
end
And I have saved the token in User model after the callback.
How do I use the token to request for https://graph.facebook.com/${current_user.uid}/accounts?
With the Facebook ID you can query the Facebook Graph. Have a look at fb_graph gem: https://github.com/nov/fb_graph, it is a Facebook API wrapper.

Devise and google oauth. (ror3)

Is it possible to use devise and google oauth together?
I have successfully setup facebook in devise, but the following
google config doesn't work. Do I have to use oauth2 directly?
config.oauth :google, 'anonymous', 'anonymous',
:site => 'https://www.google.com',
:request_token_path => "/accounts/OAuthGetRequestToken",
:access_token_path => "/accounts/OAuthGetAccessToken",
:authorize_path => "/accounts/OAuthGetAuthorizeToken",
:signature_method => "RSA-SHA1",
:private_key_file => '/rsakey.pem',
:scope => "https://www.google.com/m8/feeds/"
Ok my mistake. Google uses oauth whereas devise supports only oauth2 and they are not backwards compatible as far I understand. So I have to use my own implementation.

Resources