From fd12d2ba42fac6fb37cc62a400a2581b79e6f6d8 Mon Sep 17 00:00:00 2001 From: William Petit Date: Fri, 10 Mar 2023 14:33:12 +0100 Subject: [PATCH] feat(module,auth): use dummy getclaim func --- pkg/module/auth/module.go | 2 +- pkg/module/auth/option.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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