mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-10 23:49:28 +02:00
Moved tokensource to auth package
This commit is contained in:
parent
46e6a667c8
commit
5aed552854
2 changed files with 8 additions and 7 deletions
|
@ -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/>.
|
||||
*/
|
||||
|
||||
package backends
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -22,6 +22,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"go.uploadedlobster.com/scotty/internal/auth"
|
||||
"go.uploadedlobster.com/scotty/internal/models"
|
||||
"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) {
|
||||
authenticator, auth := backend.(models.OAuth2Authenticator)
|
||||
if auth {
|
||||
authenticator, needAuth := backend.(models.OAuth2Authenticator)
|
||||
if needAuth {
|
||||
redirectURL, err := BuildRedirectURL(config, backend.Name())
|
||||
if err != nil {
|
||||
return auth, err
|
||||
return needAuth, err
|
||||
}
|
||||
token, err := db.GetOAuth2Token(service)
|
||||
if err != nil {
|
||||
return auth, err
|
||||
return needAuth, err
|
||||
}
|
||||
conf := authenticator.OAuth2Strategy(redirectURL).Config()
|
||||
tokenSource := NewDatabaseTokenSource(db, service, &conf, token)
|
||||
tokenSource := auth.NewDatabaseTokenSource(db, service, &conf, token)
|
||||
authenticator.OAuth2Setup(tokenSource)
|
||||
}
|
||||
return auth, nil
|
||||
return needAuth, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue