Use config from OAuth2Authenticator for auth command

This commit is contained in:
Philipp Wolfer 2023-11-22 08:41:18 +01:00
parent cf3747bde2
commit d0739aad0f
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
5 changed files with 31 additions and 18 deletions

View file

@ -25,9 +25,9 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.uploadedlobster.com/scotty/backends"
"go.uploadedlobster.com/scotty/models"
"go.uploadedlobster.com/scotty/storage"
"golang.org/x/oauth2"
"golang.org/x/oauth2/spotify"
)
// authCmd represents the auth command
@ -37,19 +37,14 @@ var authCmd = &cobra.Command{
Long: `For backends requiring authentication this command can be used to authenticate.`,
Run: func(cmd *cobra.Command, args []string) {
serviceName, serviceConfig := getConfigFromFlag(cmd, "service")
backend := serviceConfig.GetString("backend")
backend, err := backends.ResolveBackend[models.OAuth2Authenticator](serviceConfig)
cobra.CheckErr(err)
redirectURL, err := backends.BuildRedirectURL(viper.GetViper(), backend)
redirectURL, err := backends.BuildRedirectURL(viper.GetViper(), backend.Name())
cobra.CheckErr(err)
ctx := context.Background()
conf := &oauth2.Config{
ClientID: serviceConfig.GetString("client-id"),
ClientSecret: serviceConfig.GetString("client-secret"),
Scopes: []string{"user-read-recently-played"},
RedirectURL: redirectURL.String(),
Endpoint: spotify.Endpoint,
}
conf := backend.OAuth2Config(redirectURL)
responseChan := make(chan string)