swagger-typescript-api icon indicating copy to clipboard operation
swagger-typescript-api copied to clipboard

Authenticate with Bearer token in header

Open WarrickFitz opened this issue 3 years ago • 1 comments

I generated a client library for a swagger file that suggests the API required a JWT Bearer token.

I can't see to figure out how to supply this bearer token \ header to the client library such that it sends it to the server.

Can someone please point me at an example?

WarrickFitz avatar Oct 01 '21 00:10 WarrickFitz

one of options:

const api = new Api<string>({
  secure: true,
  baseURL: process.env.NEXT_PUBLIC_API_BASE_URL,
  securityWorker: accessToken =>
    accessToken ? { headers: { Authorization: `Bearer ${accessToken}` } } : {},
});

// call this where you have token.
api.setSecurityData(YOUR_TOKEN);

then each api.someResource(...) will be called with token in the header

ApacheEx avatar Oct 01 '21 21:10 ApacheEx