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
25 stars 4 forks source link

Support for bearer token #11

Closed craigcooper11 closed 1 year ago

craigcooper11 commented 1 year ago

Hello @tdabasinskas ! Do you currently have a way to add a bearer token? I see that you can pass in an instance of HTTP client but this doesn't support setting a bearer token. There might be some use cases where peoples backstage instance has server to server auth turned on. https://backstage.io/docs/auth/service-to-service-auth

tdabasinskas commented 1 year ago

Hi @craigcooper11,

I think (haven't tested it) the following should work if using golang.org/x/oauth2:

httpClient := oauth2.NewClient(ctx, oauth2.StaticTokenSource(&oauth2.Token{
    AccessToken: "<your token>",
    TokenType:   "Bearer",
}))

backstageClient, err := backstage.NewClient(baseURL, "default", httpClient)