openapistack / openapi-client-axios

JavaScript client library for consuming OpenAPI-enabled APIs with axios
https://openapistack.co
MIT License
558 stars 67 forks source link

Upgrading to axios version 0.20.0 breaks generated `Bearer` Authorization token method client #37

Closed infomofo closed 4 years ago

infomofo commented 4 years ago

I upgraded from

-    "axios": "^0.19.2",
+    "axios": "^0.20.0",

And after that, my openapi calls that use the Bearer Authorization header token are consistently returning 403. Inspecting the network traffic it seems that after the axios upgrade, my generated axios client no longer is sending the required Authorization header at all. Is anyone else experiencing this? Is there a known workaround or is there a known regression with axios v0.20.0? Let me know if I can provide additional information to help demonstrate the issue I am encountering.

anttiviljami commented 4 years ago

Can you share how you initialize your OpenAPIClientAxios instance? How are you setting the header token?

infomofo commented 4 years ago

I'm initializing my OpenAPIClientAxios method using the openapi-client-axios-typegen method outlined in the README using the getClient method:

import OpenAPIClientAxios from "openapi-client-axios";
import { Client } from "client";
const api = new OpenAPIClientAxios({ definition: "/api/openapi.json" });
api.init<Client>();
const client = await api.getClient<Client>();

I'm setting the header token as an axios default, as I use the same authorization token for all my api calls.

axios.defaults.headers.common["Authorization"] = "Bearer " + token

anttiviljami commented 4 years ago

Hi @infomofo ! Could you please make sure you're setting the default headers on the axios client created by OpenAPIClientAxios ?

const client = await api.getClient<Client>();
client.defaults.headers["Authorization"] = "Bearer " + token;
infomofo commented 4 years ago

@anttiviljami This suggested method of setting the bearer token worked with the latest version of axios, thanks!

anttiviljami commented 4 years ago

Cheers! 🍺