Best way to add bearer token to openapi generated client?

Hi I've created a framework for my project that contains the generated client by Swift's OpenAPI generator.

Right now every time I need to make an API call I initialize a new instance of the client passing in the token I got through Firebase Auth to the config of the client to add the http header for the auth.

This feels wrong...but I haven't been able to think of a better solution because I get the token from Firebase when the user logs into my app and I use Firebase's own method to renew the token if necessary.

Should I maybe create a singleton of the client and only pass the token once when I receive it and again when I need to renew it? I'm having trouble reconciling how to do that because the Firebase auth code is in my main project and the client is in this framework I've made.

Hey @momokhancastro. I think a ClientMiddleware is what you're looking for here.

Here's an example: swift-openapi-generator/Examples/auth-client-middleware-example at main · apple/swift-openapi-generator · GitHub.

You'll probably want to make this a stateful object so that you can refresh the token as needed.