문제

Merb 오픈 소스 책 a 인증에 관한 장. 그러나, 그 인증 요청 섹션 테스트 예는 양식 기반 인증을 위해 할 수있는 일만 표시합니다. HTTP 기본 인증으로 테스트하고 싶은 웹 서비스가 있습니다. 어떻게할까요?

도움이 되었습니까?

해결책

내 질문을 게시 한 후, 나는 몇 가지를 더 시도하고 내 자신의 대답을 찾았습니다. 다음과 같은 일을 할 수 있습니다.

response = request('/widgets/2222', 
                   :method => "GET", 
                   "X_HTTP_AUTHORIZATION" => 'Basic ' + ["myusername:mypassword"].pack('m').delete("\r\n"))

나는 책을 업데이트 할 수 있지만 적어도이 정보는 Google이 다른 사람을 찾고 도울 수 있도록 여기에 있습니다.

다른 팁

다음은 컨트롤러 내부의 HTTP Basic Auth의 예입니다.

class MyMerbApp < Application
  before :authenticate, :only=>[:admin]

  def index
    render
  end

  def admin
    render
  end

  protected 

  def authenticate 
    basic_authentication("Protected Area") do |username, password| 
      username == "name" && password == "secret"  
    end 
  end

end

merb_auth_slice를 정의해야합니다 config/router.rb 아직 완료되지 않은 경우 :

Merb::Router.prepare do
  slice(:merb_auth_slice_password, :name_prefix => nil, :path_prefix => "")
end
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top