feat(module,auth): use dummy getclaim func

This commit is contained in:
wpetit 2023-03-10 14:33:12 +01:00
parent 6399196fe5
commit fd12d2ba42
2 changed files with 13 additions and 1 deletions

View File

@ -55,7 +55,7 @@ func (m *Module) getClaim(call goja.FunctionCall, rt *goja.Runtime) goja.Value {
} }
func ModuleFactory(funcs ...OptionFunc) app.ServerModuleFactory { func ModuleFactory(funcs ...OptionFunc) app.ServerModuleFactory {
opt := &Option{} opt := defaultOptions()
for _, fn := range funcs { for _, fn := range funcs {
fn(opt) fn(opt)
} }

View File

@ -3,6 +3,8 @@ package auth
import ( import (
"context" "context"
"net/http" "net/http"
"github.com/pkg/errors"
) )
type GetClaimFunc func(ctx context.Context, r *http.Request, claimName string) (string, error) type GetClaimFunc func(ctx context.Context, r *http.Request, claimName string) (string, error)
@ -13,6 +15,16 @@ type Option struct {
type OptionFunc func(*Option) 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 { func WithGetClaim(fn GetClaimFunc) OptionFunc {
return func(o *Option) { return func(o *Option) {
o.GetClaim = fn o.GetClaim = fn