2011-12-20 2 views
3

내 프로젝트에는 구직자와 고용 관리자라는 두 가지 유형의 사용자가 있습니다. 구직자는 모델이 없으며 Omniauth를 통해 인증하는 동안 제 3 자 제공 업체로부터받은 데이터를 사용하여 작업을 신청할 수 있습니다. 고용 관리자 정보는 기기 사용자 모델에 저장됩니다. 채용 관리자는 회사의 Google 이메일 계정으로 로그인 할 수 있어야합니다.Devise omniauthable가 '경로에 대한 유효한 매핑을 찾을 수 없습니다.'와 함께 Omniauth 인증을 깨 웠습니다.

omniauth.rb

require 'omniauth-openid' 
require 'openid/store/filesystem' 
Rails.application.config.middleware.use OmniAuth::Builder do 
    provider :openid, :store => OpenID::Store::Filesystem.new('./tmp'), :name => 'google', :identifier => 'https://www.google.com/accounts/o8/id' 
    provider :facebook, "xxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxx", 
    {:scope => 'email, offline_access, publish_stream', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}} 
    provider :twitter, "xxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxx" 
    provider :linkedin, "xxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxx" 
end 

routes.rb에 :

match '/auth/:provider/callback', :to => 'sessions#authenticate_jobseeker' 
match '/auth/failure', :to => 'sessions#failure' 

def authenticate_jobseeker 
    session[:jobseeker] = request.env['omniauth.auth'] 

    if valid_job_seeker? 
    redirect_to new_job_application_path(...) 
    else 
    redirect_to request.env['omniauth.origin'] || root_path, alert: "Authentication failure" 
    end 
end 
sessions_controller.rb에서 그래서 먼저 내가 3.1.3 레일, Omniauth 1.0.0 사용 구직자 '인증을 구축

까지이 시점까지 everythin g 잘 처리되었습니다. 그러나 사용자 모델에 대한 Google 로그인을 구현하기 시작했을 때 거기에 omniauthable을 추가하면 구직자 인증이 끊어졌습니다.

config.omniauth :open_id, :store => OpenID::Store::Filesystem.new('./tmp'), :name => 'google', :identifier => 'https://www.google.com/accounts/o8/id', :require => 'omniauth-openid' 

routes.rb에 : devise.rb

user.rb

class User < ActiveRecord::Base 
    #... 
    devise :database_authenticatable, :registerable, 
     ... :lockable, :omniauthable 
    #... 
end 

: 나는 고안 1.5.2을 사용하고

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } do 
    get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru' 
end 

이 시점에서, 사용자의 인증이 작동했지만 구직자들은하지 않았다. 잠시 동안 검색 한 후에 omniauth.rb에있는 모든 공급자에게 :path_prefix => "/auth"을 추가하여 문제가 해결되었습니다.

Could not find a valid mapping for path "/auth/twitter/callback" 
Parameters: 
{"denied"=>"mKjVfMRwRAN12ZxQ9cxCoD4rYSLJIRLnEqgiI"} 

최고 : 구직자 (즉 프레스는 "허용 안 함"및 응용 프로그램에 다시 온다), 나는 모든 공급자에 대한 RuntimeError에 따라 얻을 데이터에 대한 액세스를 허용하지 않는 경우 이제 유일한 문제는, 추적의 :

devise (1.5.2) lib/devise/mapping.rb:48:in `find_by_path!' 
devise (1.5.2) lib/devise/omniauth.rb:17:in `block in <top (required)>' 
omniauth (1.0.0) lib/omniauth/strategy.rb:418:in `call' 
omniauth (1.0.0) lib/omniauth/strategy.rb:418:in `fail!' 
omniauth-oauth (1.0.0) lib/omniauth/strategies/oauth.rb:63:in `rescue in callback_phase' 
omniauth-oauth (1.0.0) lib/omniauth/strategies/oauth.rb:45:in `callback_phase' 
omniauth (1.0.0) lib/omniauth/strategy.rb:200:in `callback_call' 
omniauth (1.0.0) lib/omniauth/strategy.rb:166:in `call!' 
omniauth (1.0.0) lib/omniauth/strategy.rb:148:in `call' 
omniauth (1.0.0) lib/omniauth/strategy.rb:168:in `call!' 
omniauth (1.0.0) lib/omniauth/strategy.rb:148:in `call' 
omniauth (1.0.0) lib/omniauth/strategy.rb:168:in `call!' 
omniauth (1.0.0) lib/omniauth/strategy.rb:148:in `call' 
omniauth (1.0.0) lib/omniauth/builder.rb:30:in `call' 

나는 지금 당분간 그것을 해보기를 시도하고있다. 어떤 도움이라도 대단히 감사합니다. 추가 정보를 제공 할 수 있다면 알려주세요.

답변

1

내 질문에 답하는 중입니다. 그래서 최종 결정은 순수 Omniauth 구현으로 진행되었습니다. 을 User 모델에서 제거하고 config.omniauth...devise.rb에서 제거하고 :omniauth_callbacks 개를 제거한 후 routes.rb에서 삭제합니다. 그래서, (상관없이 역할) AME 콜백 경로를 사용하고 sessions_controller#authenticate_jobseeker 조치를 공격하는 모든 사용자 (작업 이름을 바꾸는 생각해야합니까?) :

def authenticate_jobseeker 
    auth_hash = request.env['omniauth.auth'] 

    unless auth_hash.present? 
    redirect_to request.env['omniauth.origin'] || root_path, alert: "Sorry, we were not able to authenticate you" and return 
    end 

    @user = User.find_from_oauth(auth_hash) 
    if @user.present? 
    flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google" 
    sign_in_and_redirect @user, :event => :authentication and return 
    else 
    session[:jobseeker] = auth_hash["info"] 
    if valid_job_seeker? 
     redirect_to new_job_application_path(...) 
    end 
    end 
end 

User.find_from_oauth :

def self.find_from_oauth(auth_hash) 
    if auth_hash 
    user = User.where(:email => auth_hash["info"]["email"]).first 
    end 
    user 
end 

이 구현은 모두를 만족 요구 사항 중.

0

모델에 omniauth [ "user_info"]를 사용하고 있습니까? 제 경우에는

omniauth["user_info"]["email"] 

에 액세스하고 있었는데 충돌이 발생하고 동일한 오류가 발생하여 devise에 걸렸습니다.

내 앱에서도 Omniauth를 직접 (기업용) 사용하고 사용자 로그인 용 기기 + 페이스 북을 사용합니다.

Havent는 아직 궁리에 사로 잡힌 실패를 얻지 못했다. Devise는 자체 실패 응용 프로그램임을 등록합니다. 내가 알아낼 때 업데이 트됩니다.

업데이트 : 죄송합니다. 귀하의 질문 중 일부를 잘못 읽은 것으로 보입니다. 원격 웹 응용 프로그램에서 권한을 부여하는 명확한 실패를 볼 수 있습니다.이 오류는 코드에서 가면 처리 된 예외는 아니지만 (필자의 경우처럼).

+0

'omniauth [ "user_info"] [ "email"]'을 고려하십시오. 나는이'request.env [ "omniauth.auth"]'와 같은 인증 제공자로부터받은 auth_hash에 접근했다. 그리고 나서 나는 그것 [''info "] ["email "]'에 대해 이야기한다. 새로운 버전의 devis는'autn_hash.info [ 'email']'를 사용합니다. –

관련 문제