Taylor Goodall

moon indicating dark mode
sun indicating light mode

Configuring Bearer Auth with Open-API typescript-fetch

June 11, 2021

This blog post is a quick walk through of configuring Bearer Auth for your open-api generated typescript-fetch client. I ran into this problem and could not find a solution with trusty google, after digging through the source code it was discovered it is very simple.

Here’s how it can be done,

const AddNewPet = async (Pet: PetInterface) => {
// This is the key part
const cfgParams : ConfigurationParameters = {
apiKey: 'bearer YOUR_BEARER_API_KEY_HERE',
// Pass the config Params to the Configuration
const cfg = new Configuration(cfgParams)
// cfg into the API
const petStoreApi = new PetStoreApi(cfg);
const pet = petStoreApi.AddNewPet(Pet)

To Test this out, you can go ahead and make an API request via your App in chrome under the network tab you should see the request being made with our Bearer token on it.

Hopefully this saves you some time if you to run into this problem.

software Engineer, living in Adelaide, Australia Interested in building engaging products and solving problems