Hi,
I am trying to add linkedin login feature in my rails application using
omniauth gem..I used omniauth gem for Fb login and it''s working
fine..but
it''s not working for linkedin login
this is my code
/model/user.rb
class User < ActiveRecord::Base
attr_accessible :name, :oauth_expires_at, :oauth_token, :provider, :uid
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name
user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.save!
end
end
/controller/sessions_controller.rb
class SessionsController < ApplicationController
def create
user = User.from_omniauth(env["omniauth.auth"])
session[:user_id] = user.id
redirect_to root_url
end
def destroy
session[:user_id] = nil
redirect_to root_url, :notice => "Signed out!"
end
end
/config/initializer/omniauth.rb
OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ''###########'',
''###########''
provider :linkedin, "##########", "##############", :scope
=>
''r_fullprofile r_emailaddress r_network'', :fields =>
["id",
"email-address", "first-name", "last-name",
"headline", "industry",
"picture-url", "public-profile-url", "location",
"connections"]
end
end
Error:
TypeError in SessionsController#create
can''t convert nil into an exact number
Application
Trace<http://localhost:3000/auth/linkedin/callback?oauth_token=ed161640-d196-4fc6-adfe-771d5f6fd322&oauth_verifier=57451#>
| Framework
Trace<http://localhost:3000/auth/linkedin/callback?oauth_token=ed161640-d196-4fc6-adfe-771d5f6fd322&oauth_verifier=57451#>
| Full
Trace<http://localhost:3000/auth/linkedin/callback?oauth_token=ed161640-d196-4fc6-adfe-771d5f6fd322&oauth_verifier=57451#>
app/models/user.rb:12:in `at''
app/models/user.rb:12:in `block in from_omniauth''
app/models/user.rb:7:in `tap''
app/models/user.rb:7:in `from_omniauth''
app/controllers/sessions_controller.rb:6:in `create''
Request
*Parameters*:
{"oauth_token"=>"ed161640-d196-4fc6-adfe-771d5f6fd322",
"oauth_verifier"=>"57451",
"provider"=>"linkedin"}
Show session
dump<http://localhost:3000/auth/linkedin/callback?oauth_token=ed161640-d196-4fc6-adfe-771d5f6fd322&oauth_verifier=57451#>
Show env
dump<http://localhost:3000/auth/linkedin/callback?oauth_token=ed161640-d196-4fc6-adfe-771d5f6fd322&oauth_verifier=57451#>
Response
*Headers*:
None
I am not sure what fields I need to add or remove from user table and what
changes required in controller and model
please help
Thanks
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/fdc6d6ec-eac8-4ac6-b507-1e45408255ba%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
On 26 August 2013 21:39, Rekha Benada <rekha.benada-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I am trying to add linkedin login feature in my rails application using > omniauth gem..I used omniauth gem for Fb login and it''s working fine..but > it''s not working for linkedin login > > this is my code > > /model/user.rb > > class User < ActiveRecord::Base > attr_accessible :name, :oauth_expires_at, :oauth_token, :provider, :uid > > > > def self.from_omniauth(auth) > where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user| > user.provider = auth.provider > user.uid = auth.uid > user.name = auth.info.name > user.oauth_token = auth.credentials.token > user.oauth_expires_at = Time.at(auth.credentials.expires_at) > user.save! > end > end > ... > Error: > > TypeError in SessionsController#create > > can''t convert nil into an exact number > > > Application Trace | Framework Trace | Full Trace > > app/models/user.rb:12:in `at''You have not told us which line this is, but I presume it is user.oauth_expires_at = Time.at(auth.credentials.expires_at) What is the value of auth.credentials.expires_at, which seems to be the value it is complaining about? Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvyNkRXCXvqwEaBxOEr%2BRG3PVNNbhWX6VwRY%3DPw%3DEBrFw%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
oauth_expires_at is a column in user table and It gives date and time...which I used for facebook login...But why it''s giving problem with linkedin.? On Monday, August 26, 2013 1:58:34 PM UTC-7, Colin Law wrote:> > On 26 August 2013 21:39, Rekha Benada <rekha....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <javascript:>> > wrote: > > Hi, > > > > I am trying to add linkedin login feature in my rails application using > > omniauth gem..I used omniauth gem for Fb login and it''s working > fine..but > > it''s not working for linkedin login > > > > this is my code > > > > /model/user.rb > > > > class User < ActiveRecord::Base > > attr_accessible :name, :oauth_expires_at, :oauth_token, :provider, > :uid > > > > > > > > def self.from_omniauth(auth) > > where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user| > > user.provider = auth.provider > > user.uid = auth.uid > > user.name = auth.info.name > > user.oauth_token = auth.credentials.token > > user.oauth_expires_at = Time.at(auth.credentials.expires_at) > > user.save! > > end > > end > > ... > > Error: > > > > TypeError in SessionsController#create > > > > can''t convert nil into an exact number > > > > > > Application Trace | Framework Trace | Full Trace > > > > app/models/user.rb:12:in `at'' > > You have not told us which line this is, but I presume it is > user.oauth_expires_at = Time.at(auth.credentials.expires_at) > What is the value of auth.credentials.expires_at, which seems to be > the value it is complaining about? > > Colin >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/80e10dfe-7567-41f2-b47f-07ffbddbf56a%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.