tdabasinskas / go-backstage

Go client library for accessing the Backstage REST API
https://pkg.go.dev/github.com/tdabasinskas/go-backstage/backstage
Apache License 2.0
27 stars 4 forks source link

Add authentication options for client #36

Closed j18e closed 5 months ago

j18e commented 5 months ago

Some recent versions of Backstage introduce authentication via bearer tokens. The NewClient function allows for providing one's own HTTP client and notes "To use API methods which require authentication, provide a http.Client that will perform the authentication.", however I don't see that it's possible to add an Authorization header to every request made by the client. That would have to be done inside the package.

My suggestion is to add a token field to NewClient where one could optionally provide the bearer token and have it added to all the requests made to Backstage. I'll be trying this out in my fork https://github.com/j18e/go-backstage but there could be other ways to achieve it. What do you think @tdabasinskas ?

tdabasinskas commented 5 months ago

Hi @j18e ,

Have you checked #11? The original author of that issue hasn't confirmed it, but I'm quite sure it should work.

j18e commented 5 months ago

You're absolutely right, that does the trick. But maybe I'll submit a PR that adds a comment telling how one can authenticate.

Thanks for the quick response!