Skip to content

Commit

Permalink
make Audience a SignOption
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Nov 26, 2023
1 parent f42e953 commit 8e62bbe
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ func (aud *Audience) UnmarshalJSON(data []byte) (err error) {
return
}

// ApplyClaims implements the `SignOption` interface.
// It sets the Audience field to standard Claims instance.
//
// Usage:
//
// jwt.Sign(jwt.HS256, []byte("secret"), User{Username: "kataras"}, jwt.MaxAge(15 * time.Minute), jwt.Audience{"admin", "root"})
func (aud Audience) ApplyClaims(dest *Claims) {
dest.Audience = aud
}

// Age returns the total age of the claims,
// the result of issued at - expired time.
func (c Claims) Age() time.Duration {
Expand Down

0 comments on commit 8e62bbe

Please sign in to comment.