I'm using facebook and linkedin authentications with omniauth. I have replaced the keys for both facebook and linkedin (provided by facebook and linkedin). Facebook works like a champ, linkedin gives me an invalid_signature error even though I'm using the api credentials linkedin provided. Is there something I'm missing with the linkedin api? Has anyone run into similar problems and come up with a solution.
I have the following omniauth gems installed
gem 'omniauth'
gem 'oauth2'
gem 'omniauth-twitter'
gem 'omniauth-facebook'
gem 'omniauth-linkedin'
In /config/initializer/omniauth.rb I have
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, 'XXX', 'XXX', :strategy_class => OmniAuth::Strategies::Facebook
provider :linkedin, 'XXX', 'XXX'
end
I have also tried
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, 'XXX', 'XXX', :strategy_class => OmniAuth::Strategies::Facebook
provider :linkedin, 'XXX', 'XXX', :strategy_class => OmniAuth::Strategies::LinkedIn
end
You've probably solved this by now, but for future searchers the omniauth-linkedin-oauth2 gem is what you'll want: https://github.com/decioferreira/omniauth-linkedin-oauth2/
Related
In our application, we allow the user to access their data at different providers (Google Calendar, Microsoft Outlook, Facebook timeline, etc.) through the available API's, using Omniauth. For this we have an omniauth.rb with all the necessary configs, like:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], scope: 'email,user_posts,user_status,public_profile,manage_pages,instagram_basic'
provider :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET'],
name: 'google',
scope: 'email, profile, calendar.readonly',
access_type: 'offline',
prompt: 'select_account consent'
# etc...
end
Now we like to add login with Google as an alternative way to log in. Since we use Devise for our user session management, we'd like to use Devise's Omniauth features to implement login with an OAuth provider like Google. However, as soon as we make our model "omniauthable", the existing Omniauth functionality stops working throwing an No route matches [GET] "/auth/facebook" when trying to add an oauth account to access an API.
What is the correct way of combining the use of Omniauth in both Devise and in our own plain vanilla OAuth flow?
I found the answer myself: it's a matter of not using the thin wrapper of functionality that Devise adds to OmniAuth, but instead taking care of the OmniAuth routing yourself. I have described this approach here in the Devise Wiki.
This gem ("devise_token_auth") is used for token authentication for applications using JSON APIs for front-end development.
Can we use this gem for server side rendering? If yes, then how to add the token from a previous response to the current request?
I don't know if this is still a pressing matter for you, but I'd like to throw in some advice.
For your API you can throw in devise_token_auth and it will do what everything you need for authentication there.
And if you need authentication with server-side rendering of pages (such as login forms, reset password forms, etc.) just throw in regular devise too. It will work with your exact same User model and table, and there will be little friction to get things up and running with the same resources you use with devise_token_auth.
Gemfile
#autentication and authorization
gem 'devise', '~> 3.5', '>= 3.5.6'
gem 'devise_token_auth', '0.1.37'
Then run
bundle
Run the installer for devise:
rails generate devise:install
Then generate your user model:
rails generate devise User
Install devise_token_auth now:
rails g devise_token_auth:install User "auth"
And make sure your database is migrated:
rake db:migrate
I think devise_token_auth may overwrite your user model, I'm not certain, but if it does, keep the migrations for devise_token_auth only and ignore the migrations for Devise.
Then make sure your routes.rb matches this:
Rails.application.routes.draw do
devise_for :users
root "home#index"
namespace :api, defaults: { format: :json } do
namespace :v1 do #I namespace my routes
mount_devise_token_auth_for "User", at: "auth"
end
end
end
devise_for must come before mount_devise_token_auth.
Then just refer to the official devise and devise token auth documentation to get both solutions working for you.
Hope this helps anyone who reaches this point and has a need to authenticate users on mobile app and on browser web app.
I get 'error=invalid_client_id' from Uber when I try to authenticate using the omniauth-uber gem on localhost. I registered my app with Uber and have triple checked my clientID. Is it possible that it is related to me being on localhost and uber not recognizing my app for that?
config/initializer/omniauth.rb file (i've specified my secret key in .env):
Rails.application.config.middleware.use OmniAuth::Builder do
provider :uber, ENV['UBER_CLIENT_ID'], ENV['UBER_CLIENT_SECRET'], :scope => 'profile,history'
end
The snippet from the view that makes the request.
<div id="sign-in">
<%= link_to "Sign in with Uber", "/auth/uber" %>
</div>
The Url that I have specified in the uber app registration under the authentication section:
Redirect URL: https://localhost:3000/auth/uber/callback
Origin URI: https://localhost:3000/
I was able to fix the problem by changing my uber app urls from HTTPS to HTTP. I then also removed the ENV from my omniauth.rb file and put the secret key directly in it:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :uber, 'UBER_CLIENT_ID', 'UBER_CLIENT_SECRET', :scope => 'profile,history'
end
This is the tutorial I followed. Scroll down to the Google open-id integration:
https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
On the server I get the following rejection message after clicking the login with google link:
WARNING: making https request to https://www.google.com/accounts/o8/id without verifying server certificate; no CA path was specified.
processing by users omniauthcallbackscontroller failure as html
EDIT the following two lines fixed the CA path Warning but did nothing to fix the failure as html problem or move me forward
require "openid/fetchers"
OpenID.fetcher.ca_file = "/etc/ssl/certs/ca-certificates.crt"
It then re-routes me to users/sign_in.
My devise config line looks like this:
config.omniauth :open_id, :store => OpenID::Store::Filesystem.new('/tmp'), :name => 'google', :identifier => 'https://www.google.com/acounts/o8/id', :require => 'omniauth-openid'
My research tells me that I'm probably hitting the openID servers but that I'm getting rejected. Is there anyway to get more info from some sort of rejection notice? What could be wrong with my request?
One thing I thought of was credentials for open ID but I didn't see anywhere in the tutorial where I was supposed to get or enter any credentials.
Try to specify the ca_path:
config.omniauth :open_id, :store => OpenID::Store::Filesystem.new('/tmp'),
:name => 'google',
:identifier => 'https://www.google.com/acounts/o8/id',
:require => 'omniauth-openid',
:client_options => {:ssl => {:ca_path => '/etc/ssl/certs'}}
And see if it works.
I just got setup using Rails 3, Devise and OmniAuth via https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview.
I want integrate my app with vkontakte.ru. When i'm using this config everything goes fine i can create user and i can access user data.
config.omniauth :vkontakte, 'xxx', 'xxx'
But when i'm adding a scope param
config.omniauth :vkontakte, 'xxx', 'xxx', {
:scope => "notify,friends,photos,notes,docs,pages,wall,offline"
}
omniauth raise failure(redirects me on user sign up page and dont store data in env["omniauth.auth"]).
I'll be appreciated for any help.
Seems like that's because of the attribute expires_in=0 in the VK oauth response, that indicates the long-living token that was requested by the 'offline' scope and leads to the instant token refreshing by omniauth.
I've just submitted patch here.