Autenticate OAuth backends

This commit is contained in:
Philipp Wolfer 2023-11-21 17:51:13 +01:00
parent 94704f9cd0
commit fa7732c538
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
15 changed files with 61 additions and 20 deletions

View file

@ -28,7 +28,7 @@ import (
"github.com/spf13/viper"
"go.uploadedlobster.com/scotty/models"
"go.uploadedlobster.com/scotty/storage"
"golang.org/x/oauth2"
)
func BuildRedirectURL(config *viper.Viper, backend string) (*url.URL, error) {
@ -40,21 +40,15 @@ func BuildRedirectURL(config *viper.Viper, backend string) (*url.URL, error) {
return url.Parse("http://" + callbackHost + callbackPath)
}
func Authenticate(backend models.Backend, db storage.Database, config *viper.Viper) error {
func Authenticate(backend models.Backend, token *oauth2.Token, config *viper.Viper) (bool, error) {
authenticator, auth := backend.(models.OAuth2Authenticator)
if auth {
// FIXME
backendName := "spotify"
redirectURL, err := BuildRedirectURL(config, backendName)
redirectURL, err := BuildRedirectURL(config, backend.Name())
if err != nil {
return err
}
// FIXME
token, err := db.GetOAuth2Token("spotify")
if err != nil {
return err
return auth, err
}
authenticator.OAuth2Setup(redirectURL.String(), token)
}
return nil
return auth, nil
}