Skip to content

Authorization Header

No GUI edited this page Apr 7, 2018 · 6 revisions

Use the #basic_auth method to perform HTTP Basic Authentication using a username and password:

HTTP.basic_auth(:user => "user", :pass => "pass")
# <HTTP::Headers {"Authorization"=>"Basic dXNlcjpwYXNz"}>

You can pass a raw authorization header using the #auth method:

HTTP.auth("Bearer VGhlIEhUVFAgR2VtLCBST0NLUw")
# <HTTP::Headers {"Authorization"=>"Bearer VGhlIEhUVFAgR2VtLCBST0NLUw"}>

Once you've added the desired authorization, make an HTTP request as usual:

HTTP.basic_auth(:user => "user", :pass => "pass")
  .get("https://example.com")

See Also