복붙노트

[RUBY-ON-RAILS] 유증에 대한 사용자 인증 전략

RUBY-ON-RAILS

유증에 대한 사용자 인증 전략

나는 https://github.com/plataformatec/devise에 대한 사용자 정의 인증 전략을 쓸 필요가 있지만 문서있을 것 같지 않습니다. 그것은 어떻게 할거야?

해결법

  1. ==============================

    1.나는 유증 구글 그룹에이 스레드에서이 매우 도움이 조각을 발견

    나는 유증 구글 그룹에이 스레드에서이 매우 도움이 조각을 발견

    초기화 / some_initializer.rb :

    Warden::Strategies.add(:custom_strategy_name) do 
      def valid? 
        # code here to check whether to try and authenticate using this strategy; 
        return true/false 
      end 
    
      def authenticate! 
        # code here for doing authentication; 
        # if successful, call  
        success!(resource) # where resource is the whatever you've authenticated, e.g. user;
        # if fail, call 
        fail!(message) # where message is the failure message 
      end 
    end 
    

    초기화에 다음 / devise.rb 추가

      config.warden do |manager| 
         manager.default_strategies.unshift :custom_strategy_name 
      end 
    
  2. from https://stackoverflow.com/questions/4223083/custom-authentication-strategy-for-devise by cc-by-sa and MIT license