edge/pkg/module/auth/option.go

33 lines
611 B
Go

package auth
import (
"context"
"net/http"
"github.com/pkg/errors"
)
type GetClaimFunc func(ctx context.Context, r *http.Request, claimName string) (string, error)
type Option struct {
GetClaim GetClaimFunc
}
type OptionFunc func(*Option)
func defaultOptions() *Option {
return &Option{
GetClaim: dummyGetClaim,
}
}
func dummyGetClaim(ctx context.Context, r *http.Request, claimName string) (string, error) {
return "", errors.Errorf("dummy getclaim func cannot retrieve claim '%s'", claimName)
}
func WithGetClaim(fn GetClaimFunc) OptionFunc {
return func(o *Option) {
o.GetClaim = fn
}
}