Skip to content

Instantly share code, notes, and snippets.

@adam12

adam12/- Secret

Created May 23, 2015 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adam12/0ac5b3e4a42f410864a6 to your computer and use it in GitHub Desktop.
Save adam12/0ac5b3e4a42f410864a6 to your computer and use it in GitHub Desktop.
class Hurley::DigestAuth
attr_reader :client, :username, :password
def initialize(client, username, password)
@client = client
@username = username
@password = password
@client.after_call do |res|
if res.status_code == 401
url = res.request.url
verb = res.request.verb.to_s.upcase
header = res.header['WWW-Authenticate']
auth_header = DigestAuth.auth_header(url, verb, header, username, password)
res.request.header['Cookie'] = 'foo=bar'
res.request.header['Authorization'] = auth_header
new_request = @client.call(res.request)
# Swap res for new_request here
end
end
end
end
@client = Hurley::Client.new "http://localhost:8000"
Hurley::DigestAuth.new(@client, "username", "password")
p @client.get "/digest-auth/auth/user/passwd"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment