edge/pkg/module/auth/option.go
William Petit b5b4042cc7
All checks were successful
arcad/edge/pipeline/head This commit looks good
feat(sdk,client): add menu to help navigation between apps
2023-04-20 10:17:37 +02:00

48 lines
918 B
Go

package auth
import (
"context"
"net/http"
"github.com/pkg/errors"
)
type GetClaimsFunc func(ctx context.Context, r *http.Request, claims ...string) ([]string, error)
type Option struct {
GetClaims GetClaimsFunc
ProfileClaims []string
}
type OptionFunc func(*Option)
func defaultOptions() *Option {
return &Option{
GetClaims: dummyGetClaims,
ProfileClaims: []string{
ClaimSubject,
ClaimIssuer,
ClaimEdgeEntrypoint,
ClaimEdgeRole,
ClaimPreferredUsername,
ClaimEdgeTenant,
},
}
}
func dummyGetClaims(ctx context.Context, r *http.Request, claims ...string) ([]string, error) {
return nil, errors.Errorf("dummy getclaim func cannot retrieve claims '%s'", claims)
}
func WithGetClaims(fn GetClaimsFunc) OptionFunc {
return func(o *Option) {
o.GetClaims = fn
}
}
func WithProfileClaims(claims ...string) OptionFunc {
return func(o *Option) {
o.ProfileClaims = claims
}
}