Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Auth #185

Closed
SaimonL opened this issue Mar 18, 2021 · 2 comments
Closed

Basic Auth #185

SaimonL opened this issue Mar 18, 2021 · 2 comments

Comments

@SaimonL
Copy link

SaimonL commented Mar 18, 2021

This maybe a silly question.
How do I deal with http basic auth?

Do I do something like this?

session.headers['username'] = 'abcd'
session.headers['password'] = 'secret'

So far I am getting:
#<Patron::Response @status_line='HTTP/1.1 401 Unauthorized'>

When I try to browse using the browser the user name and password is valid.

For example:

Rest Client

RestClient.post 'https://example.com/token/grant', 
  {"app_key":"my_app_key","app_secret":"my_app_secret"}.to_json,  
  {username: 'username', password: 'password', content_type: 'application/json'}

Curb

require 'curb'
request_path= 'https://example.com/token/grant'
payload = {
          app_key: 'app_key',
          app_secret: 'app_secret'
        }

http = Curl.post(request_path, payload.to_json) do |http|
          http.headers['username'] = 'user_name'
          http.headers['password'] = 'password'
          http.headers['Content-Type'] = 'application/json'
        end
JSON.parse(http.body_str)
@SaimonL
Copy link
Author

SaimonL commented Mar 18, 2021

Got it its

session.username = 'abcd'
session.password = 'secret'

the document needs to be better

@SaimonL SaimonL closed this as completed Mar 18, 2021
@toland
Copy link
Owner

toland commented Mar 18, 2021

I would be happy to merge a PR that improves the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants