Witam,
Mam w aplikacji zaimplementowane logowanie z wykorzystaniem konta na
Facebook
Tweeter
LinkedIn
Google
i GitHub
użyte gemy:
gem 'omniauth'
gem 'omniauth-oauth2'
gem 'omniauth-facebook'
gem 'omniauth-github'
gem 'omniauth-google-oauth2'
gem 'omniauth-linkedin'
gem 'omniauth-twitter'
W aplikacji wykorzystuję Devise i w pliku config/initializers/devise.rb deklaracje providerów mam tak zrobione:
config.omniauth :facebook, ENV["FACEBOOK_KEY"], ENV["FACEBOOK_SECRET"], { :scope => 'email, offline_access', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}}
config.omniauth :twitter, ENV["TWITTER_KEY"], ENV["TWITTER_SECRET"], { :scope => 'r_fullprofile, r_emailaddress', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}}
config.omniauth :linkedin, ENV["LINKEDIN_KEY"], ENV["LINKEDIN_SECRET"], { :scope => 'r_fullprofile r_emailaddress', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}}
config.omniauth :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET'], scope: "user, public_repo"
config.omniauth :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'], {}
No pięknie działa ze wszystkimi portalami poza GitHub
Otrzymuję w Heroku logs takie coś:
Parameters: {"code"=>"e1536d0fdec9b4d23faf", "state"=>"e3118babae5dfe4faf560ff5798fd47be15f6fc7d42a75fb"}
2014-10-21T07:21:34.509614+00:00 app[web.1]: #<OmniAuth::AuthHash credentials=#<OmniAuth::AuthHash expires=false token="6d0cc7544f24f9e16a66bf23c5e7b46665f1adf6"> extra=#<OmniAuth::AuthHash raw_info=#<OmniAuth::AuthHash avatar_url="https://avatars.githubusercontent.com/u/8292687?v=2" bio=nil blog="" collaborators=0 company="" created_at="2014-07-28T19:20:17Z" disk_usage=18420 email="BSorbus@gmail.com" events_url="https://api.github.com/users/BSorbus/events{/privacy}" followers=0 followers_url="https://api.github.com/users/BSorbus/followers" following=0 following_url="https://api.github.com/users/BSorbus/following{/other_user}" gists_url="https://api.github.com/users/BSorbus/gists{/gist_id}" gravatar_id="" hireable=false html_url="https://github.com/BSorbus" id=8292687 location="" login="BSorbus" name="BSorbus" organizations_url="https://api.github.com/users/BSorbus/orgs" owned_private_repos=0 plan=#<OmniAuth::AuthHash collaborators=0 name="free" private_repos=0 space=307200> private_gists=0 public_gists=0 public_repos=4 received_events_url="https://api.github.com/users/BSorbus/received_events" repos_url="https://api.github.com/users/BSorbus/repos" site_admin=false starred_url="https://api.github.com/users/BSorbus/starred{/owner}{/repo}" subscriptions_url="https://api.github.com/users/BSorbus/subscriptions" total_private_repos=0 type="User" updated_at="2014-10-21T07:07:51Z" url="https://api.github.com/users/BSorbus">> info=#<OmniAuth::AuthHash::InfoHash email="BSorbus@gmail.com" image="https://avatars.githubusercontent.com/u/8292687?v=2" name="BSorbus" nickname="BSorbus" urls=#<OmniAuth::AuthHash Blog="" GitHub="https://github.com/BSorbus">> provider="github" uid="8292687">
2014-10-21T07:21:34.611357+00:00 app[web.1]:
2014-10-21T07:21:34.611360+00:00 app[web.1]: NoMethodError (undefined method `persisted?' for nil:NilClass):
2014-10-21T07:21:34.611361+00:00 app[web.1]: app/controllers/omniauth_callbacks_controller.rb:7:in `all'
2014-10-21T07:21:34.611362+00:00 app[web.1]:
2014-10-21T07:21:34.610054+00:00 app[web.1]: Completed 500 Internal Server Error in 101ms
2014-10-21T07:21:34.612275+00:00 heroku[router]: at=info method=GET path="/users/auth/github/callback?code=e1536d0fdec9b4d23faf&state=e3118babae5dfe4faf560ff5798fd47be15f6fc7d42a75fb" host=letter.herokuapp.com request_id=07fbee37-bed4-4074-861b-2d393107c192 fwd="31.61.131.215" dyno=web.1 connect=0ms service=1479ms status=500 bytes=1754
Czy ktoś z Was ma pomysł, o co chodzi z tym:
NoMethodError (undefined method `persisted?' for nil:NilClass):
2014-10-21T07:21:34.611361+00:00 app[web.1]: app/controllers/omniauth_callbacks_controller.rb:7:in `all'
kod:
1) class OmniauthCallbacksController < Devise::OmniauthCallbacksController
2)
3) skip_before_filter :authenticate_user!
4) def all
5) p env["omniauth.auth"]
6) user = User.from_omniauth(env["omniauth.auth"], current_user)
7) if user.persisted?
flash[:notice] = "You are in..!!! Go to edit profile to see the status for the accounts"
sign_in_and_redirect(user)
else
session["devise.user_attributes"] = user.attributes
redirect_to new_user_registration_url
end
end
.....
....
Wdzięczny będę za wszelkie sugestie