summaryrefslogtreecommitdiffstats
path: root/internal/auth/interceptor.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/auth/interceptor.go')
-rw-r--r--internal/auth/interceptor.go15
1 files changed, 6 insertions, 9 deletions
diff --git a/internal/auth/interceptor.go b/internal/auth/interceptor.go
index 42c2688..67450ce 100644
--- a/internal/auth/interceptor.go
+++ b/internal/auth/interceptor.go
@@ -18,28 +18,25 @@ const (
18) 18)
19 19
20type InterceptorOptions struct { 20type InterceptorOptions struct {
21 Read OperationAuthConfig 21 Read AuthOperationConfig
22 Write OperationAuthConfig 22 Write AuthOperationConfig
23 TimestampWindow int64 23 TimestampWindow int64
24 ValidatePayload bool 24 ValidatePayload bool
25 SkipMethods []string 25 SkipMethods []string
26} 26}
27 27
28// OperationAuthConfig configures auth for read or write operations. 28type AuthOperationConfig struct {
29// Three states: disabled (allow all), enabled with empty list (require auth),
30// enabled with npubs (whitelist only). Npubs normalized to hex at load time.
31type OperationAuthConfig struct {
32 Enabled bool 29 Enabled bool
33 AllowedNpubs []string 30 AllowedNpubs []string
34} 31}
35 32
36func DefaultInterceptorOptions() *InterceptorOptions { 33func DefaultInterceptorOptions() *InterceptorOptions {
37 return &InterceptorOptions{ 34 return &InterceptorOptions{
38 Read: OperationAuthConfig{ 35 Read: AuthOperationConfig{
39 Enabled: false, 36 Enabled: false,
40 AllowedNpubs: nil, 37 AllowedNpubs: nil,
41 }, 38 },
42 Write: OperationAuthConfig{ 39 Write: AuthOperationConfig{
43 Enabled: false, 40 Enabled: false,
44 AllowedNpubs: nil, 41 AllowedNpubs: nil,
45 }, 42 },
@@ -154,7 +151,7 @@ func validateAuthFromContext(ctx context.Context, method string, opts *Intercept
154 151
155 pubkey := ExtractPubkey(event) 152 pubkey := ExtractPubkey(event)
156 153
157 var opConfig OperationAuthConfig 154 var opConfig AuthOperationConfig
158 if isWriteMethod(method) { 155 if isWriteMethod(method) {
159 opConfig = opts.Write 156 opConfig = opts.Write
160 } else { 157 } else {