diff --git a/pkg/module/auth/module.go b/pkg/module/auth/module.go index 8705f93..4d8fd4d 100644 --- a/pkg/module/auth/module.go +++ b/pkg/module/auth/module.go @@ -55,7 +55,7 @@ func (m *Module) getClaim(call goja.FunctionCall, rt *goja.Runtime) goja.Value { } func ModuleFactory(funcs ...OptionFunc) app.ServerModuleFactory { - opt := &Option{} + opt := defaultOptions() for _, fn := range funcs { fn(opt) } diff --git a/pkg/module/auth/option.go b/pkg/module/auth/option.go index fa2a375..fe63999 100644 --- a/pkg/module/auth/option.go +++ b/pkg/module/auth/option.go @@ -3,6 +3,8 @@ package auth import ( "context" "net/http" + + "github.com/pkg/errors" ) type GetClaimFunc func(ctx context.Context, r *http.Request, claimName string) (string, error) @@ -13,6 +15,16 @@ type Option struct { 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