Add bodySerializer
and Accept
header to @openverse/api-client
to correctly authenticate with the API
#5314
Labels
💻 aspect: code
Concerns the software code in the repository
🛠 goal: fix
Bug fix
good first issue
New-contributor friendly
help wanted
Open to participation from the community
🟨 priority: medium
Not blocking but should be addressed soon
🧱 stack: frontend
Related to the Nuxt frontend
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 requiredx-www-form-urlencoded
format. This causes the requests to be sent with an empty body.Solution
Add
bodySerializer
1 that createsnew URLSearchParams
from thebody
object, and stringifies it:openverse/packages/js/api-client/src/auth.ts
Lines 132 to 138 in ba0d5e3
Tests update
The matching of the request in tests should also be updated to ensure we always get the correct encoding.
Update this line:
openverse/packages/js/api-client/tests/client.test.ts
Line 29 in ba0d5e3
With this code:
Additional context
I opened an issue in the
openapi-fetch
repository to encode the body automatically when the relevant header is passed: Automatically encode the body when "Accept": "application/x-www-form-encoded" header is passedThis issue was identified when I was trying to use
@openverse/api-client
in the "Proxy frontend API requests" project planning.Footnotes
Documentation on
bodySerializer
inopenapi-fetch
↩The text was updated successfully, but these errors were encountered: