Skip to content

Commit 8e62bbe

Browse files
committed
make Audience a SignOption
1 parent f42e953 commit 8e62bbe

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

claims.go

+10
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ func (aud *Audience) UnmarshalJSON(data []byte) (err error) {
127127
return
128128
}
129129

130+
// ApplyClaims implements the `SignOption` interface.
131+
// It sets the Audience field to standard Claims instance.
132+
//
133+
// Usage:
134+
//
135+
// jwt.Sign(jwt.HS256, []byte("secret"), User{Username: "kataras"}, jwt.MaxAge(15 * time.Minute), jwt.Audience{"admin", "root"})
136+
func (aud Audience) ApplyClaims(dest *Claims) {
137+
dest.Audience = aud
138+
}
139+
130140
// Age returns the total age of the claims,
131141
// the result of issued at - expired time.
132142
func (c Claims) Age() time.Duration {

0 commit comments

Comments
 (0)