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 partconst cfgParams : ConfigurationParameters = {apiKey: 'bearer YOUR_BEARER_API_KEY_HERE',}// Pass the config Params to the Configurationconst cfg = new Configuration(cfgParams)// cfg into the APIconst 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.