zmb3 / spotify

A Go wrapper for the Spotify Web API
Apache License 2.0
1.37k stars 287 forks source link

Allow HTTP Client and Base URL to be overrided on instantiation #106

Closed bttmly closed 3 years ago

bttmly commented 4 years ago

I have an application that consists of two components: a persistent server that takes care of authenticating with Spotify (it stores creds and refreshes them after authenticating once), and a CLI that gets existing creds from this auth server and uses that token to make Spotify API calls. This lets me control Spotify from the command line without re-authenticating frequently. Currently the CLI portion of the app is written in Ruby while the server is in Go. I'm translating the CLI to Go right now and was hoping to use this library. However, the implementation of the Client struct here won't let me bypass this library's auth mechanism. I believe I could use this library if the Client.http field was public – I would create my own client with an http.RoundTripper that simply adds the authorization field.

Any chance these fields could be exposed?

tobiola commented 4 years ago

Not sure if this helps, but there is a function Token() for the Client struct that returns the oauth2.Token defined here: https://github.com/zmb3/spotify/blob/f2845aa5788672b1d62fab139d6ae7b4bfc2d61b/auth.go#L172

This provides access to the access and refresh token which can be sent to your CLI side to make request to the API

bttmly commented 4 years ago

I want to go in the reverse direction – my application will provide the tokens, and I want this library to accept them.

strideynet commented 3 years ago

This will be resolved using functional options for the client instantiation in v2.0