mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-30 13:47:05 +02:00
Use config from OAuth2Authenticator for auth command
This commit is contained in:
parent
cf3747bde2
commit
d0739aad0f
5 changed files with 31 additions and 18 deletions
|
@ -43,7 +43,7 @@ func Authenticate(backend models.Backend, token *oauth2.Token, config *viper.Vip
|
|||
if err != nil {
|
||||
return auth, err
|
||||
}
|
||||
authenticator.OAuth2Setup(redirectURL.String(), token)
|
||||
authenticator.OAuth2Setup(redirectURL, token)
|
||||
}
|
||||
return auth, nil
|
||||
}
|
||||
|
|
|
@ -22,6 +22,15 @@ THE SOFTWARE.
|
|||
|
||||
package spotify
|
||||
|
||||
type TracksResult struct {
|
||||
Href string `json:"href"`
|
||||
Limit int `json:"limit"`
|
||||
Next string `json:"next"`
|
||||
Previous string `json:"previous"`
|
||||
Offset int `json:"offset"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
type RecentlyPlayedResult struct {
|
||||
Href string `json:"href"`
|
||||
Limit int `json:"limit"`
|
||||
|
|
|
@ -18,6 +18,7 @@ Scotty. If not, see <https://www.gnu.org/licenses/>.
|
|||
package spotify
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
|
@ -42,17 +43,22 @@ func (b *SpotifyApiBackend) FromConfig(config *viper.Viper) models.Backend {
|
|||
return b
|
||||
}
|
||||
|
||||
func (b *SpotifyApiBackend) OAuth2Config(redirectUrl string) oauth2.Config {
|
||||
func (b *SpotifyApiBackend) OAuth2Config(redirectUrl *url.URL) oauth2.Config {
|
||||
return oauth2.Config{
|
||||
ClientID: b.clientId,
|
||||
ClientSecret: b.clientSecret,
|
||||
Scopes: []string{"user-read-recently-played"},
|
||||
RedirectURL: redirectUrl,
|
||||
Endpoint: spotify.Endpoint,
|
||||
Scopes: []string{
|
||||
"user-read-currently-playing",
|
||||
"user-read-recently-played",
|
||||
"user-library-read",
|
||||
"user-library-modify",
|
||||
},
|
||||
RedirectURL: redirectUrl.String(),
|
||||
Endpoint: spotify.Endpoint,
|
||||
}
|
||||
}
|
||||
|
||||
func (b *SpotifyApiBackend) OAuth2Setup(redirectUrl string, token *oauth2.Token) error {
|
||||
func (b *SpotifyApiBackend) OAuth2Setup(redirectUrl *url.URL, token *oauth2.Token) error {
|
||||
config := b.OAuth2Config(redirectUrl)
|
||||
b.client = NewClient(config, token)
|
||||
return nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue