2023-02-24 14:40:28 +01:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
2023-03-10 14:33:12 +01:00
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2023-02-24 14:40:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type GetClaimFunc func(ctx context.Context, r *http.Request, claimName string) (string, error)
|
|
|
|
|
|
|
|
type Option struct {
|
|
|
|
GetClaim GetClaimFunc
|
|
|
|
}
|
|
|
|
|
|
|
|
type OptionFunc func(*Option)
|
|
|
|
|
2023-03-10 14:33:12 +01:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2023-02-24 14:40:28 +01:00
|
|
|
func WithGetClaim(fn GetClaimFunc) OptionFunc {
|
|
|
|
return func(o *Option) {
|
|
|
|
o.GetClaim = fn
|
|
|
|
}
|
|
|
|
}
|