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

Support For HTTP Basic Auth hasn't (yet) been officially released #136

Closed
dvjones89 opened this issue May 19, 2019 · 3 comments
Closed

Support For HTTP Basic Auth hasn't (yet) been officially released #136

dvjones89 opened this issue May 19, 2019 · 3 comments

Comments

@dvjones89
Copy link

Hi Sonny,

Thanks for pulling together this excellent OAuth package. I've been working on an OAuth integration this evening and spent an hour or so banging my head against a 401 unauthorized response. I compared the request being sent by this package against a (successful) Postman request and saw that the only different was how the client_idand code were being sent. Postman sends the credentials as HTTP Basic Auth headers whilst currently your package sends as query params. Whilst I think this should work, the OAuth provides wasn't happy. I spotted your fix to #128 had been merged to master, though not yet released. If I pin my dependency to your master branch then the 401 error is immediately resolved. To avoid other people potentially bumping into this in the future, and indeed so I can avoid referencing your master branch, could your fix be released officially?

Thanks again!

@scrogson
Copy link
Member

Excellent! Thanks for pinging me on this. I will work on a new release this week.

@DavidOliver
Copy link

DavidOliver commented Jun 11, 2019

I ran into this today. :)

It's a simple workaround, but in case it's of use to anyone else, I used this in my custom strategy:

def get_token(client, params, headers) do
  client
  |> put_header("accept", "application/json")
  |> put_header("Authorization", "Basic #{get_token_basic_auth()}")
  |> OAuth2.Strategy.AuthCode.get_token(params, headers)
end

defp get_token_basic_auth do
  [@client_id, @client_secret]  # these are module attributes here as I'm only testing with a sandbox
  |> Enum.join(":")
  |> Base.encode64()
end

Edit: when looking through client.ex I noticed it already has a basic_auth function, so this is all I needed:

def get_token(client, params, headers) do
  client
  |> put_header("accept", "application/json")
  |> basic_auth()
  |> OAuth2.Strategy.AuthCode.get_token(params, headers)
end

@scrogson
Copy link
Member

Published 2.0 to hex. Thanks for your patience!

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

3 participants