Documentation
¶
Overview ¶
Package hs256 implements jwt.Signer and jwt.Verifier using the HS256 HMAC-SHA256 signing algorithm.
Use Signer/Verifier with the generic core/jwt.AuthService:
signer := hs256.NewSigner([]byte("secret"))
verifier := hs256.NewVerifier([]byte("secret"))
svc := jwt.NewAuthService[MyAuthInfo](signer, verifier, "myservice", "user", time.Hour)
The package also exposes the older generic CreateToken/ParseToken helpers for callers that don't need AuthService.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidSigningMethod = errors.New("unexpected signing method") ErrInvalidClaimsType = errors.New("invalid claims type") ErrInvalidToken = errors.New("invalid token") )
Sentinel errors returned by ParseToken / Verifier.
Functions ¶
func CreateToken ¶
CreateToken is a generic helper that signs the given claims with HS256. Useful when AuthService's payload model doesn't fit your use case.
Types ¶
type Signer ¶ added in v1.3.0
type Signer struct {
// contains filtered or unexported fields
}
Signer signs JWT claims using HS256 with a shared secret. Implements core/jwt.Signer.
type Verifier ¶ added in v1.3.0
type Verifier struct {
// contains filtered or unexported fields
}
Verifier validates HS256-signed JWTs against a shared secret. Implements core/jwt.Verifier.
func NewVerifier ¶ added in v1.3.0
NewVerifier returns an HS256 jwt.Verifier that validates against the given shared secret.