OAuth2Strategy interface to abstract the details of the login flow

This allows implementing clients the deviate from the standard OAuth2 flow
This commit is contained in:
Philipp Wolfer 2023-11-23 14:41:31 +01:00
parent 780af98e1e
commit f447a259d4
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
6 changed files with 130 additions and 27 deletions

View file

@ -46,7 +46,7 @@ func Authenticate(service string, backend models.Backend, db storage.Database, c
if err != nil {
return auth, err
}
conf := authenticator.OAuth2Config(redirectURL)
conf := authenticator.OAuth2Strategy(redirectURL).Config()
tokenSource := NewDatabaseTokenSource(db, service, &conf, token)
authenticator.OAuth2Setup(tokenSource)
}

View file

@ -25,6 +25,7 @@ import (
"time"
"github.com/spf13/viper"
"go.uploadedlobster.com/scotty/internal/auth"
"go.uploadedlobster.com/scotty/models"
"golang.org/x/oauth2"
"golang.org/x/oauth2/spotify"
@ -44,6 +45,23 @@ func (b *SpotifyApiBackend) FromConfig(config *viper.Viper) models.Backend {
return b
}
func (b *SpotifyApiBackend) OAuth2Strategy(redirectUrl *url.URL) auth.OAuth2Strategy {
conf := oauth2.Config{
ClientID: b.clientId,
ClientSecret: b.clientSecret,
Scopes: []string{
"user-read-currently-playing",
"user-read-recently-played",
"user-library-read",
"user-library-modify",
},
RedirectURL: redirectUrl.String(),
Endpoint: spotify.Endpoint,
}
return auth.NewStandardStrategy(conf)
}
func (b *SpotifyApiBackend) OAuth2Config(redirectUrl *url.URL) oauth2.Config {
return oauth2.Config{
ClientID: b.clientId,