-
Notifications
You must be signed in to change notification settings - Fork 215
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
Add bodyserializer/accept header to openverse api client to correctly authenticate with the API #5330
Conversation
Latest k6 run output1
Footnotes
|
packages/js/api-client/src/auth.ts
Outdated
return new URLSearchParams(body).toString() | ||
}, | ||
headers: { | ||
Accept: "x-www-form-encoded", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accept: "x-www-form-encoded", | |
"Content-Type": "x-www-form-encoded", |
Sorry, I've mixed up the headers in the issue. The correct one will be content type, to encode the body of the request (and not the response)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skipped this myself, thanks for spotting. Updated now.
ec7db68
to
c108fab
Compare
… authenticate with the API
53c5325
to
10f8fbc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution, @madewithkode !
I realized that I also had the header value wrong in the original issue 🤦♀️ Fixed that, and also updated the tests to be sure that the body is correctly encoded.
Add bodyserializer/accept header to openverse api client to correctly authenticate with the API
Fixes
Fixes #5314 by @obulat
Description
The @openverse/api-client package sends the requests for token to the Openverse Django API with the correct parameters but does not serialize the body to the required x-www-form-urlencoded format. This causes the requests to be sent with an empty body. The new changes adds a bodySerializer1 that creates new URLSearchParams from the body object, and stringifies it, thus allowing requests to be sent with correct body objects.
Checklist
Update index.md
).main
) or a parent feature branch.ov just catalog/generate-docs
for catalogPRs) or the media properties generator (
ov just catalog/generate-docs media-props
for the catalog or
ov just api/generate-docs
for the API) where applicable.Developer Certificate of Origin
Developer Certificate of Origin