-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoption.go
More file actions
68 lines (58 loc) · 2 KB
/
Copy pathoption.go
File metadata and controls
68 lines (58 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package swt
import (
"time"
"github.com/golang-jwt/jwt/v5"
)
type Option func(swt *SecureWebhookToken)
// WithSubject overrides the default sub claim.
func WithSubject(s string) Option {
return func(swt *SecureWebhookToken) {
swt.Claims().wc().Subject = s
}
}
// WithExpiresAt overrides the default exp claim.
func WithExpiresAt(t time.Time) Option {
return func(swt *SecureWebhookToken) {
swt.Claims().wc().ExpiresAt = jwt.NewNumericDate(t)
}
}
// WithNotBefore overrides the default nbf claim.
func WithNotBefore(t time.Time) Option {
return func(swt *SecureWebhookToken) {
swt.Claims().wc().NotBefore = jwt.NewNumericDate(t)
}
}
// WithID overrides the jti claim with a given id. Should be a UUID or similar unique id.
func WithID(id string) Option {
return func(swt *SecureWebhookToken) {
swt.Claims().wc().ID = id
}
}
// WithAudience overrides the aud claim.
// The Audience claim is optional and is nil by default.
// It can consist of zero or more recipients containing a StringOrURI value.
func WithAudience(ids ...string) Option {
return func(swt *SecureWebhookToken) {
swt.Claims().wc().Audience = ids
}
}
// WithSigningMethod allows overriding the default signing method HS256.
// Draft-02 supports both symmetrical and asymmetrical signatures.
func WithSigningMethod(method jwt.SigningMethod) Option {
return func(swt *SecureWebhookToken) {
swt.token.Method = method
}
}
// WithRetryCount sets the retry count for the webhook token.
// This is metadata that indicates how many times this webhook delivery has been attempted.
// The receiver can use this to:
// - Track delivery attempts
// - Apply different handling logic for retries (e.g., idempotency checks)
// - Implement exponential backoff strategies
// Note: This library does not automatically implement retry logic - this is informational only.
// Senders should increment this count when resending failed webhooks.
func WithRetryCount(rc uint) Option {
return func(swt *SecureWebhookToken) {
swt.Claims().wc().Webhook.RetryCount = rc
}
}