Incorrect routes for Devise + LinkedIn (OmniAuth) - ruby-on-rails

I am trying to implement sign up through LinkedIn to the current Devise gem. These are the current routes:
devise_for :users, :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret',
:confirmation => 'verification', :unlock => 'unlock', :registration => 'register',
:sign_up => 'signup' }, :controllers => {:omniauth_callbacks => "omniauth_callbacks"}
And the view: = link_to "Sign in with Linkedin",user_omniauth_authorize_path(:linkedin)
Returns to this error:
No route matches {:controller=>"omniauth_callbacks", :action=>"passthru", :provider=>:linkedin, :format=>nil} missing required keys: [:provider]
I've tried to add provider key too, like: = link_to "Sign in with Linkedin",user_omniauth_authorize_path(:provider => 'linkedin')
But then I got:
No route matches {:controller=>"omniauth_callbacks", :action=>"passthru", :provider=>"linkedin"} missing required keys: [:provider]
What am I missing at this point?
Thank you very much

Add the line in devise.rb
config.omniauth :linkedin, 'APP_ID', 'APP_SECRET'
Devise will automatically add a signin link using linkedin.
In omniauth_callbacks_controller.rb add a method as:-
def linkedin
#code for authorization using linkedin callback credentials
end

Related

Authenticating Rails Application With Omniauth Github in Local

I am working on authenticating users using GitHub in local development mode.
I am using using omniauth-github Rubygem.
I have bellow code in config/initializers/omniauth.rb
OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET'],
{
:client_options => {
:site => 'https://github.com/api/v3',
:authorize_url => 'https://github.com/login/oauth/authorize',
:token_url => 'https://github.com/login/oauth/access_token',
}
}
end
In view layout I have
<%= link_to "Sign in with Github", "/auth/github" %>
In routes.rb I have
match 'auth/:provider/callback' => 'session#create', :via => [:get, :post]
match 'signout' => 'session#destroy', :via => [:delete], :as => 'signout'
I have registered new application in github with
Homepage URL : http://localhost:3000
, Authorization callback URL : http://localhost:3000/callback
After clicking on Sign in with Github, I am getting following error.
http://localhost:3000/callback?error=redirect_uri_mismatch&error_description=The redirect_uri MUST match the registered callback URL for this application.&error_uri=https://developer.github.com/v3/oauth/#redirect-uri-mismatch&state=14216a2416431297d9690e68efe0723a03aa7a1eaee51db3
Kindly help me to set proper values for site ,authorize_url , token_url to work in local system.

Rails 4, Devise Routes

I've created custom routes to route to the devise login and logout paths:
devise_scope :admin do
get "logout" => "devise/sessions#destroy", as: :logout
get "login" => "devise/sessions#new", as: :login
end
This works. The only problem is that if the the login fails it redirects back to admins/sign_in instead of /login.
Any ideas?
According to this answer and this description, it seems the proper way to achieve what you're attempting to do is to make use of the :path_names option. According to the description from the Devise wiki:
devise_for :admin, :path => '', :path_names => {:sign_in => 'login', :sign_out => 'logout'}
will create the normal admin routes for you, and will assign the /sign_in and /sign_out route to /login/ and /logout respectively.
Using the :path option, you can further alter the URL, such as using :path=>"admins" will yield routes like /admin/login, etc.

Issue with rails controller

I have a controller pages as follow:
class PagesController < ApplicationController
def home
end
def about
end
def login
end
end
i have the views corresponding also , and in my routes.rb, i have the following
devise_for :users
get 'log in' => 'pages#login'
get 'about' => 'pages#about'
root :to => 'pages#home'
when i try to go to the login page it's gave me an error :
undefined local variable or method `login_path' for #<#:0x2b9a298>
i try to match the controller to the actions ,same error . i'm new with rails , i'm trying to understand what i did wrong , because it works for the 'about' page. thanks
Your routes should be:
match 'login', :to => "pages#login", :as => :login
match 'about', :to => "pages#about", :as => :about
To learn more about Rails routing, check out the routing guide.
get 'log in' => 'pages#login'
Is there a space in "log in" or is that just how it appears here?
I think Devise also has some special setup in how you customize the routes. Here is an example provided on their GitHub page:
devise_for :users, :path => "auth", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock', :registration => 'register', :sign_up => 'cmon_let_me_in' }
It's at https://github.com/plataformatec/devise under Configuring Routes.

Devise showing error 'invalid email or password' upon going to login

I'm using Rails 3 with Devise and have setup my routes.rb file like so:
devise_for :users,
:path_names => { :sign_in => 'login', :sign_out => 'logout'}
devise_scope :user do
get '/login' => 'devise/sessions#create'
get '/logout' => 'devise/sessions#destroy'
end
resources :users
When I go to /login I get the flash messages:
Signed out successfully.
Invalid email or password.
The first message is a notice and I'm not worried about it, but the second one is an alert and is annoying as the user hasn't hit sign in yet and it's already complaining that there is no password.
Is there an easy way to suppress this message? Have I setup devise wrong maybe.
I'm using username field to login instead of email.
I have changed my devise.rb to have
config.authentication_keys = [ :username ]
This was an easy mistake when I look back at it with a fresh head:
This
get '/login' => 'devise/sessions#create'
Should be
get '/login' => 'devise/sessions#new'

What is the correct way to allow a user to delete their account with Devise?

I'm using devise for user accounts. What is the correct way to let users delete their accounts?
My devise setup already has an overridden registrations controller
devise_for :users, :path_names =>
{:sign_up => "register"}, :controllers
=> {:registrations => 'registrations'}
This is how I've tried to setup the account removal process:
registrations_controller.rb
def delete_account
#remove data associated with account, then the user object itself
end
routes.rb
map.delete_account 'delete_account', :controller => 'registrations', :action => 'delete_account'
and try to link to it
<%= button_to 'temo', delete_account_path %>
I get this error when I click the link
Unknown action
AbstractController::ActionNotFound
Why isn't this working? Thanks for reading.
You're using a named route.
map.delete_account 'delete_account', :controller => 'registrations', :action => 'delete_account'
In which case you can do this
<%= button_to 'temo', '/delete_account' %>

Resources