Moved tokensource to auth package

This commit is contained in:
Philipp Wolfer 2023-11-24 10:30:11 +01:00
parent 46e6a667c8
commit 5aed552854
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
2 changed files with 8 additions and 7 deletions

View file

@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with
Scotty. If not, see <https://www.gnu.org/licenses/>. Scotty. If not, see <https://www.gnu.org/licenses/>.
*/ */
package backends package auth
import ( import (
"context" "context"

View file

@ -22,6 +22,7 @@ import (
"strings" "strings"
"github.com/spf13/viper" "github.com/spf13/viper"
"go.uploadedlobster.com/scotty/internal/auth"
"go.uploadedlobster.com/scotty/internal/models" "go.uploadedlobster.com/scotty/internal/models"
"go.uploadedlobster.com/scotty/internal/storage" "go.uploadedlobster.com/scotty/internal/storage"
) )
@ -36,19 +37,19 @@ func BuildRedirectURL(config *viper.Viper, backend string) (*url.URL, error) {
} }
func Authenticate(service string, backend models.Backend, db storage.Database, config *viper.Viper) (bool, error) { func Authenticate(service string, backend models.Backend, db storage.Database, config *viper.Viper) (bool, error) {
authenticator, auth := backend.(models.OAuth2Authenticator) authenticator, needAuth := backend.(models.OAuth2Authenticator)
if auth { if needAuth {
redirectURL, err := BuildRedirectURL(config, backend.Name()) redirectURL, err := BuildRedirectURL(config, backend.Name())
if err != nil { if err != nil {
return auth, err return needAuth, err
} }
token, err := db.GetOAuth2Token(service) token, err := db.GetOAuth2Token(service)
if err != nil { if err != nil {
return auth, err return needAuth, err
} }
conf := authenticator.OAuth2Strategy(redirectURL).Config() conf := authenticator.OAuth2Strategy(redirectURL).Config()
tokenSource := NewDatabaseTokenSource(db, service, &conf, token) tokenSource := auth.NewDatabaseTokenSource(db, service, &conf, token)
authenticator.OAuth2Setup(tokenSource) authenticator.OAuth2Setup(tokenSource)
} }
return auth, nil return needAuth, nil
} }