Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update auth method metadata structure #1275

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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