1
0
mirror of https://github.com/kataras/iris.git synced 2026-02-07 19:25:58 +00:00

add some godoc to jwt

This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-11-01 04:23:36 +02:00
parent 3d59d19de6
commit 836fb18c57
2 changed files with 49 additions and 5 deletions

View File

@@ -7,6 +7,11 @@ import (
"github.com/kataras/jwt"
)
// Signer holds common options to sign and generate a token.
// Its Sign method can be used to generate a token which can be sent to the client.
// Its NewTokenPair can be used to construct a token pair (access_token, refresh_token).
//
// It does not support JWE, JWK.
type Signer struct {
Alg Alg
Key interface{}
@@ -16,6 +21,14 @@ type Signer struct {
Encrypt func([]byte) ([]byte, error)
}
// NewSigner accepts the signature algorithm among with its (private or shared) key
// and the max life time duration of generated tokens and returns a JWT signer.
// See its Sign method.
//
// Usage:
//
// signer := NewSigner(HS256, secret, 15*time.Minute)
// token, err := signer.Sign(userClaims{Username: "kataras"})
func NewSigner(signatureAlg Alg, signatureKey interface{}, maxAge time.Duration) *Signer {
return &Signer{
Alg: signatureAlg,
@@ -24,7 +37,7 @@ func NewSigner(signatureAlg Alg, signatureKey interface{}, maxAge time.Duration)
}
}
// WithEncryption enables AES-GCM payload decryption.
// WithEncryption enables AES-GCM payload-only decryption.
func (s *Signer) WithEncryption(key, additionalData []byte) *Signer {
encrypt, _, err := jwt.GCM(key, additionalData)
if err != nil {