Skip to content

Commit

Permalink
Add option to fetch server secret from file
Browse files Browse the repository at this point in the history
Ref #1138
  • Loading branch information
eleftherias committed Oct 13, 2023
1 parent a2ab312 commit d2ff443
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
20 changes: 20 additions & 0 deletions internal/config/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@

package config

import (
"fmt"
"os"
"path/filepath"
)

// IdentityConfig is the configuration for the identity provider
type IdentityConfig struct {
Cli CliIdentityConfig `mapstructure:"cli"`
Expand All @@ -41,4 +47,18 @@ type ServerIdentityConfig struct {
ClientId string `mapstructure:"client_id" default:"mediator-server"`
// ClientSecret is the client secret for the mediator server
ClientSecret string `mapstructure:"client_secret" default:"secret"`
// ClientSecretFile is the location of a file containing the client secret for the mediator server (optional)
ClientSecretFile string `mapstructure:"client_secret_file"`
}

// GetClientSecret returns the mediator-server client secret
func (sic *ServerIdentityConfig) GetClientSecret() (string, error) {
if sic.ClientSecretFile != "" {
data, err := os.ReadFile(filepath.Clean(sic.ClientSecretFile))
if err != nil {
return "", err
}
return string(data), fmt.Errorf("failed to read mediator secret from file: %w", err)
}
return sic.ClientSecret, nil
}
7 changes: 6 additions & 1 deletion internal/controlplane/handlers_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,14 @@ func (s *Server) DeleteUser(ctx context.Context,

tokenUrl := parsedURL.JoinPath("realms", s.cfg.Identity.Server.Realm, "protocol/openid-connect/token")

clientSecret, err := s.cfg.Identity.Server.GetClientSecret()
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get client secret: %v", err)
}

clientCredentials := clientcredentials.Config{
ClientID: s.cfg.Identity.Server.ClientId,
ClientSecret: s.cfg.Identity.Server.ClientSecret,
ClientSecret: clientSecret,
TokenURL: tokenUrl.String(),
}

Expand Down

0 comments on commit d2ff443

Please sign in to comment.