Vishal Aher
Vishal Aher

Reputation: 21

How can I retrieve Basic Authentication credentials from the header in ruby?

Can anyone explain to me how to get a username and password from a request header in ruby?

While communicating with another system, before I was sending the user name and password and now I have changed the user name and password in both the system. But still, I'm getting #<Net::HTTPUnauthorized 401 Unauthorized readbody=true> error

Upvotes: 0

Views: 705

Answers (2)

Shannarra
Shannarra

Reputation: 559

Simplest way to do so is to access request.headers

request.headers[:password]
# or
request.headers['password']

If you're unsure about the headers you're sending/receiving you can always do

raise request.headers.inspect

Upvotes: 0

Edil Talantbekov
Edil Talantbekov

Reputation: 84

maybe this one request.headers

E.g request.headers['username']

Upvotes: 0

Related Questions