summaryrefslogtreecommitdiff
path: root/internal/oidc/idp.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/oidc/idp.go')
-rw-r--r--internal/oidc/idp.go47
1 files changed, 32 insertions, 15 deletions
diff --git a/internal/oidc/idp.go b/internal/oidc/idp.go
index 3032d15d5..166fc4b85 100644
--- a/internal/oidc/idp.go
+++ b/internal/oidc/idp.go
@@ -23,6 +23,7 @@ import (
"fmt"
"github.com/coreos/go-oidc/v3/oidc"
+ "github.com/spf13/viper"
"github.com/superseriousbusiness/gotosocial/internal/config"
"golang.org/x/oauth2"
)
@@ -54,42 +55,56 @@ type idp struct {
// If the passed config contains a nil value for the OIDCConfig, or OIDCConfig.Enabled
// is set to false, then nil, nil will be returned. If OIDCConfig.Enabled is true,
// then the other OIDC config fields must also be set.
-func NewIDP(ctx context.Context, config *config.Config) (IDP, error) {
+func NewIDP(ctx context.Context) (IDP, error) {
+ keys := config.Keys
- // oidc isn't enabled so we don't need to do anything
- if config.OIDCConfig == nil || !config.OIDCConfig.Enabled {
+ oidcEnabled := viper.GetBool(keys.OIDCEnabled)
+ if !oidcEnabled {
+ // oidc isn't enabled so we don't need to do anything
return nil, nil
}
// validate config fields
- if config.OIDCConfig.IDPName == "" {
+ idpName := viper.GetString(keys.OIDCIdpName)
+ if idpName == "" {
return nil, fmt.Errorf("not set: IDPName")
}
- if config.OIDCConfig.Issuer == "" {
+
+ issuer := viper.GetString(keys.OIDCIssuer)
+ if issuer == "" {
return nil, fmt.Errorf("not set: Issuer")
}
- if config.OIDCConfig.ClientID == "" {
+
+ clientID := viper.GetString(keys.OIDCClientID)
+ if clientID == "" {
return nil, fmt.Errorf("not set: ClientID")
}
- if config.OIDCConfig.ClientSecret == "" {
+
+ clientSecret := viper.GetString(keys.OIDCClientSecret)
+ if clientSecret == "" {
return nil, fmt.Errorf("not set: ClientSecret")
}
- if len(config.OIDCConfig.Scopes) == 0 {
+
+ scopes := viper.GetStringSlice(keys.OIDCScopes)
+ if len(scopes) == 0 {
return nil, fmt.Errorf("not set: Scopes")
}
- provider, err := oidc.NewProvider(ctx, config.OIDCConfig.Issuer)
+ provider, err := oidc.NewProvider(ctx, issuer)
if err != nil {
return nil, err
}
+ protocol := viper.GetString(keys.Protocol)
+ host := viper.GetString(keys.Host)
+
oauth2Config := oauth2.Config{
// client_id and client_secret of the client.
- ClientID: config.OIDCConfig.ClientID,
- ClientSecret: config.OIDCConfig.ClientSecret,
+ ClientID: clientID,
+ ClientSecret: clientSecret,
// The redirectURL.
- RedirectURL: fmt.Sprintf("%s://%s%s", config.Protocol, config.Host, CallbackPath),
+ RedirectURL: fmt.Sprintf("%s://%s%s", protocol, host, CallbackPath),
// Discovery returns the OAuth2 endpoints.
Endpoint: provider.Endpoint(),
@@ -97,14 +112,16 @@ func NewIDP(ctx context.Context, config *config.Config) (IDP, error) {
// "openid" is a required scope for OpenID Connect flows.
//
// Other scopes, such as "groups" can be requested.
- Scopes: config.OIDCConfig.Scopes,
+ Scopes: scopes,
}
// create a config for verifier creation
oidcConf := &oidc.Config{
- ClientID: config.OIDCConfig.ClientID,
+ ClientID: clientID,
}
- if config.OIDCConfig.SkipVerification {
+
+ skipVerification := viper.GetBool(keys.OIDCSkipVerification)
+ if skipVerification {
oidcConf.SkipClientIDCheck = true
oidcConf.SkipExpiryCheck = true
oidcConf.SkipIssuerCheck = true