2014-09-01 2 views
1

구글과 페이스 북 모두 사용자 인증을 위해 devise omniauthable을 사용하고 있습니다. Google은 잘 작동하지만 페이스 북은 리디렉션 페이지에 갇혀 있지만 플랫폼에 따라 사용자가 올바르게 로그인합니다 (페이스 북에서).기기 페이스 북 oAuth가 리디렉션 페이지에 머물러 있습니다.

입니다 로그 내가 얻을 :

2014-09-01T15:26:41.996884+00:00 app[web.1]: (facebook) Request phase initiated. 
2014-09-01T15:26:42.211524+00:00 app[web.1]: (facebook) Request phase initiated. 
2014-09-01T15:26:41.994627+00:00 app[web.1]: Started GET "https://stackoverflow.com/users/auth/facebook?locale=es" for 190.15.201.45 at 2014-09-01 15:26:41 +0000 
2014-09-01T15:26:42.205674+00:00 app[web.1]: Started GET "https://stackoverflow.com/users/auth/facebook?locale=es" for 190.15.201.45 at 2014-09-01 15:26:42 +0000 
2014-09-01T15:26:42.217355+00:00 heroku[router]: at=info method=GET path="https://stackoverflow.com/users/auth/facebook?locale=es" host=myapp.herokuapp.com request_id=2b9aab45-c511-4ac9-b36f-4e6925cba3aa fwd="190.15.201.45" dyno=web.1 connect=2ms service=16ms status=302 bytes=1284 

내 경로 :

devise_for :users, :controllers => { omniauth_callbacks: "users/omniauth_callbacks" } 

내 omniauth_callbacks_controller :

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController 

def self.provides_callback_for(provider) 
class_eval %Q{ 
    def #{provider} 
    @user = User.find_for_oauth(env["omniauth.auth"], current_user) 

    if @user.persisted? 
     sign_in_and_redirect @user, event: :authentication 
     set_flash_message(:notice, :success, kind: "#{provider}".capitalize) if is_navigational_format? 
    else 
     session["devise.#{provider}_data"] = env["omniauth.auth"] 
     redirect_to new_user_registration_url 
    end 
    end 
} 
end 

[:google_oauth2, :facebook].each do |provider| 
    provides_callback_for provider 
end 

내 사용자 모델 :

class User < ActiveRecord::Base 

devise :database_authenticatable, :confirmable, :registerable, 
    :recoverable, :rememberable, :trackable, :validatable, :omniauthable 

belongs_to :company 

before_save :create_user_company 

def create_user_company 
    if self.company_id.nil? 
    company = Company.new 
    company.email = self.email 
    company.save 
    self.company_id = company.id 
    self.admin = true 
    end 
end 

def self.find_for_oauth(auth, signed_in_resource = nil) 
    identity = Identity.find_for_oauth(auth) 
    user = signed_in_resource ? signed_in_resource : identity.user 

    if user.nil? 
    email = auth.info.email 
    user = User.where(:email => email).first if email 

    if user.nil? 
     user = User.new(
     name: auth.extra.raw_info.name, 
     email: email ? email : "[email protected]", 
     password: Devise.friendly_token[0,20] 
    ) 
     user.skip_confirmation! 
     user.save! 
    end 
    end 

    if identity.user != user 
    identity.user = user 
    identity.save! 
    end 

    user 

end 

end 
,691,363 (210)

고안 이니셜은 기본입니다 :

config.omniauth :facebook, ENV['FB_APP_ID'], ENV['FB_APP_SECRET'] 

그러나 나는 또한 this (didnt 한 작업) 시도 :

config.omniauth :facebook, ENV['FB_APP_ID'], ENV['FB_APP_SECRET'],{client_options: {ssl: {ca_file: Rails.root.join('lib/assets/cacert.pem').to_s}}} 

그리고 메신저 사용이 보석 :

gem 'omniauth' 
gem 'omniauth-google-oauth2' 
gem 'omniauth-facebook' 
gem 'devise' 
gem 'figaro' #for safe saving of env vars 

내가 어떤 감사하겠습니다을 힌트를 가질 수 있습니다. 미리 감사드립니다.

PS : this 대답하지

+0

뭔가가에 "방법 = 경로를 GET ="/ 사용자/인증/페이스 북/"= 경로를 GET = 방법"만에. "콜백/사용자/인증/페이스 북 얻는다되지 않습니다 "그리고 나서 그것은 붙어 있습니다. – ntonnelier

+0

+ 브라우저에서 네트워크 콘솔에 "500 내부 서버 오류"가 표시됩니다. – ntonnelier

답변

0

좋아 사람이 같은 문제가 발생하면,이 그것을 고정 :

  • 입력 (developers.facebook) 당신의 페이스 북의 개발자 콘솔로 이동하여 응용 프로그램 :
    1. 설정 연락처 이메일을 추가해야합니다.
    2. 상태 및 리뷰에서이 질문 (이전 샌드 박스)을 찾을 수 있습니다. "이 앱과 모든 실시간 기능을 일반인이 사용할 수 있도록 하시겠습니까?" "예"를 클릭하십시오. 고려 걸릴