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.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/internal/auth/interceptor.go b/internal/auth/interceptor.go
index c055a15..7d785bf 100644
--- a/internal/auth/interceptor.go
+++ b/internal/auth/interceptor.go
@@ -35,10 +35,11 @@ type InterceptorOptions struct {
35 // Default: false 35 // Default: false
36 ValidatePayload bool 36 ValidatePayload bool
37 37
38 // AllowedPubkeys is an optional whitelist of allowed pubkeys. 38 // AllowedNpubs is an optional whitelist of allowed pubkeys (hex format).
39 // Config accepts npub format only, normalized to hex at load time.
39 // If nil or empty, all valid signatures are accepted. 40 // If nil or empty, all valid signatures are accepted.
40 // Default: nil (allow all) 41 // Default: nil (allow all)
41 AllowedPubkeys []string 42 AllowedNpubs []string
42 43
43 // SkipMethods is a list of gRPC methods that bypass authentication. 44 // SkipMethods is a list of gRPC methods that bypass authentication.
44 // Useful for public endpoints like health checks or relay info. 45 // Useful for public endpoints like health checks or relay info.
@@ -53,7 +54,7 @@ func DefaultInterceptorOptions() *InterceptorOptions {
53 TimestampWindow: 60, 54 TimestampWindow: 60,
54 Required: false, 55 Required: false,
55 ValidatePayload: false, 56 ValidatePayload: false,
56 AllowedPubkeys: nil, 57 AllowedNpubs: nil,
57 SkipMethods: nil, 58 SkipMethods: nil,
58 } 59 }
59} 60}
@@ -168,9 +169,9 @@ func validateAuthFromContext(ctx context.Context, method string, opts *Intercept
168 // Extract pubkey 169 // Extract pubkey
169 pubkey := ExtractPubkey(event) 170 pubkey := ExtractPubkey(event)
170 171
171 // Check whitelist if configured 172 // Check whitelist if configured (all values are already normalized to hex)
172 if len(opts.AllowedPubkeys) > 0 { 173 if len(opts.AllowedNpubs) > 0 {
173 if !contains(opts.AllowedPubkeys, pubkey) { 174 if !contains(opts.AllowedNpubs, pubkey) {
174 return "", fmt.Errorf("pubkey not in whitelist") 175 return "", fmt.Errorf("pubkey not in whitelist")
175 } 176 }
176 } 177 }