mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-30 13:47:05 +02:00
Autenticate OAuth backends
This commit is contained in:
parent
94704f9cd0
commit
fa7732c538
15 changed files with 61 additions and 20 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ import (
|
|||
|
||||
type DumpBackend struct{}
|
||||
|
||||
func (b *DumpBackend) Name() string { return "dump" }
|
||||
|
||||
func (b *DumpBackend) FromConfig(config *viper.Viper) models.Backend {
|
||||
return b
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@ type FunkwhaleApiBackend struct {
|
|||
username string
|
||||
}
|
||||
|
||||
func (b *FunkwhaleApiBackend) Name() string { return "funkwhale" }
|
||||
|
||||
func (b *FunkwhaleApiBackend) FromConfig(config *viper.Viper) models.Backend {
|
||||
b.client = NewClient(
|
||||
config.GetString("server-url"),
|
||||
|
|
|
@ -39,6 +39,8 @@ type JspfBackend struct {
|
|||
tracks []Track
|
||||
}
|
||||
|
||||
func (b *JspfBackend) Name() string { return "jspf" }
|
||||
|
||||
func (b *JspfBackend) FromConfig(config *viper.Viper) models.Backend {
|
||||
b.filePath = config.GetString("file-path")
|
||||
b.title = config.GetString("title")
|
||||
|
|
|
@ -36,6 +36,8 @@ type ListenBrainzApiBackend struct {
|
|||
existingMbids map[string]bool
|
||||
}
|
||||
|
||||
func (b *ListenBrainzApiBackend) Name() string { return "listenbrainz" }
|
||||
|
||||
func (b *ListenBrainzApiBackend) FromConfig(config *viper.Viper) models.Backend {
|
||||
b.client = NewClient(config.GetString("token"))
|
||||
b.client.MaxResults = MaxItemsPerGet
|
||||
|
|
|
@ -36,6 +36,8 @@ type MalojaApiBackend struct {
|
|||
nofix bool
|
||||
}
|
||||
|
||||
func (b *MalojaApiBackend) Name() string { return "maloja" }
|
||||
|
||||
func (b *MalojaApiBackend) FromConfig(config *viper.Viper) models.Backend {
|
||||
b.client = NewClient(
|
||||
config.GetString("server-url"),
|
||||
|
|
|
@ -37,6 +37,8 @@ type ScrobblerLogBackend struct {
|
|||
log ScrobblerLog
|
||||
}
|
||||
|
||||
func (b *ScrobblerLogBackend) Name() string { return "scrobbler-log" }
|
||||
|
||||
func (b *ScrobblerLogBackend) FromConfig(config *viper.Viper) models.Backend {
|
||||
b.filePath = config.GetString("file-path")
|
||||
b.includeSkipped = config.GetBool("include-skipped")
|
||||
|
|
|
@ -40,6 +40,8 @@ type SpotifyApiBackend struct {
|
|||
clientSecret string
|
||||
}
|
||||
|
||||
func (b *SpotifyApiBackend) Name() string { return "spotify" }
|
||||
|
||||
func (b *SpotifyApiBackend) FromConfig(config *viper.Viper) models.Backend {
|
||||
b.clientId = config.GetString("client-id")
|
||||
b.clientSecret = config.GetString("client-secret")
|
||||
|
|
|
@ -36,6 +36,8 @@ type SubsonicApiBackend struct {
|
|||
password string
|
||||
}
|
||||
|
||||
func (b *SubsonicApiBackend) Name() string { return "subsonic" }
|
||||
|
||||
func (b *SubsonicApiBackend) FromConfig(config *viper.Viper) models.Backend {
|
||||
b.client = subsonic.Client{
|
||||
Client: &http.Client{},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue