Skip to content

how to use simple "auth" for API_KEY in post request #1018

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

Closed
AbhimanyuAryan opened this issue Mar 7, 2023 · 1 comment
Closed

how to use simple "auth" for API_KEY in post request #1018

AbhimanyuAryan opened this issue Mar 7, 2023 · 1 comment

Comments

@AbhimanyuAryan
Copy link
Contributor

Hey, I want to send payload for that I want to set auth. In javascript axios I can do it like this

const res = await axios.post('https://httpbin.org/basic-auth/foo/bar', {
  // Axios looks for the `auth` option, and, if it is set, formats a
  // basic auth header for you automatically.
  auth: {
    username: 'my_key',
  }
});

not sure how to achieve this in HTTP.jl

The only only auth related stuff I found is basicauth where it sets "Basic _____" Authorization in header. But Authorization and api auth are different things

axios.get(webApiUrl, { headers: {"Authorization" : `Bearer ${tokenStr}`} });

???

from google

API keys if you expect developers to build internal applications that don't need to access more than a single user's data. Use OAuth access tokens if you want users to easily provide authorization to applications

@AbhimanyuAryan
Copy link
Contributor Author

the problem was API_KEY has to be a username from the python implementation I saw: auth = HTTPBasicAuth(write_key, '')

which is base encoded by basicauth in our HTTP.jl here:

function basicauthlayer(handler)
return function(req; basicauth::Bool=true, kw...)
if basicauth
userinfo = unescapeuri(req.url.userinfo)
if !isempty(userinfo) && !hasheader(req.headers, "Authorization")
@debugv 1 "Adding Authorization: Basic header."
setheader(req.headers, "Authorization" => "Basic $(base64encode(userinfo))")
end
end
return handler(req; kw...)
end
end

and then passed as "Authorization" => "Basic $(base64encode(userinfo))"

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

1 participant