Skip to content

Commit

Permalink
chore: update auth method metadata structure (#1275)
Browse files Browse the repository at this point in the history
  • Loading branch information
markphelps authored Jan 16, 2023
1 parent b75cdf1 commit d94448d
Show file tree
Hide file tree
Showing 4 changed files with 259 additions and 251 deletions.
18 changes: 13 additions & 5 deletions internal/config/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/spf13/viper"
"go.flipt.io/flipt/rpc/flipt/auth"
"google.golang.org/protobuf/types/known/structpb"
)

var (
Expand Down Expand Up @@ -162,7 +163,7 @@ type StaticAuthenticationMethodInfo struct {
type AuthenticationMethodInfo struct {
Method auth.Method
SessionCompatible bool
Metadata map[string]string
Metadata *structpb.Struct
}

// Name returns the friendly lower-case name for the authentication method.
Expand Down Expand Up @@ -221,17 +222,24 @@ func (a AuthenticationMethodOIDCConfig) Info() AuthenticationMethodInfo {
info := AuthenticationMethodInfo{
Method: auth.Method_METHOD_OIDC,
SessionCompatible: true,
Metadata: map[string]string{},
}

var (
metadata = make(map[string]any)
providers = make(map[string]any, len(a.Providers))
)

// this ensures we expose the authorize and callback URL endpoint
// to the UI via the /auth/v1/method endpoint
for provider := range a.Providers {
key := fmt.Sprintf("provider.%s", provider)
info.Metadata[key+".authorize_url"] = fmt.Sprintf("/auth/v1/method/oidc/%s/authorize", provider)
info.Metadata[key+".callback_url"] = fmt.Sprintf("/auth/v1/method/oidc/%s/callback", provider)
providers[provider] = map[string]any{
"authorize_url": fmt.Sprintf("/auth/v1/method/oidc/%s/authorize", provider),
"callback_url": fmt.Sprintf("/auth/v1/method/oidc/%s/callback", provider),
}
}

metadata["providers"] = providers
info.Metadata, _ = structpb.NewStruct(metadata)
return info
}

Expand Down
1 change: 1 addition & 0 deletions internal/server/auth/public/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func NewServer(logger *zap.Logger, conf config.AuthenticationConfig) *Server {
for _, info := range conf.Methods.AllMethods() {
server.resp.Methods = append(server.resp.Methods, &auth.MethodInfo{
Method: info.AuthenticationMethodInfo.Method,
Enabled: info.Enabled,
SessionCompatible: info.AuthenticationMethodInfo.SessionCompatible,
Metadata: info.AuthenticationMethodInfo.Metadata,
})
Expand Down
Loading

0 comments on commit d94448d

Please sign in to comment.