2

레일즈 애플리케이션에서 다이제스트 인증 서비스를 호출하려고하는데 항상 잘못된 요청 오류 400을 반환합니다.잘못된 루비에서 다이제스트 인증 서비스를 호출하려고합니다

net-http-digest_auth gem을 사용하여 헤더를 만들었지 만 뭔가 놓친 것 같습니다.

def get_digest(url) 
    uri = URI.parse(url) 

    http = Net::HTTP.new uri.host, uri.port 
    http.use_ssl = true 
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER 

    req = Net::HTTP::Get.new(uri.request_uri) 

    # Fist call with the 401 and auth headers 
    digest_response = http.request(req) 

    digest_auth_request = Net::HTTP::DigestAuth.new 

    uri.user = digest_auth[:user] 
    uri.password = digest_auth[:password] 

    auth = digest_auth_request.auth_header uri, digest_response['www-authenticate'], 'GET', true 

    req.add_field 'Authorization', auth 

    response = http.request(req) 
    # Response is always #<Net::HTTPBadRequest 400 Bad Request readbody=true> 

    if response.code.to_i == 200 
    response_body = response.body 
    else 
    error 
    end 

    response_body 
end 

요청의 헤더

는 다음과 같다 :

Digest username=\"[email protected]\", realm=\"Digest\", algorithm=MD5-sess, qop=\"auth\", uri=\"/path/WS/my%20user/path/path/path/path/service.svc\", nonce=\"+Upgraded+v1e3f88bce1c32bd15avn421e440ca6622ebadd4522f7ed201fab1421c39d8fd15b771b972c9eb59894f8879307b9e6a5544476bc05cc7885a\", nc=00000000, cnonce=\"d42e6ea8a37aadsasdbea1231232456709\", response=\"7fbfc75cc3aasdasd342230ebf57ac37df\"" 

내가 무슨 일이 일어나고 있는지 알아낼 수 없습니다,이 더 쉽게 만드는 다른 보석이?

답변

0

마지막으로 브라우저 헤더와 루비 헤더를 비교하여 문제를 발견했습니다.

"nc"(카운터 호출)가 올바르게 계산되지 않았습니다. +1을 추가하면 401 오류가 반환되기 시작합니다 (이제는 다른 문제가 있습니다.)).