🐛 Fix on reading jwt claims

This commit is contained in:
2024-10-30 23:59:04 +08:00
parent f9b6cd2e20
commit 3f6ea11d22
4 changed files with 12 additions and 4 deletions

View File

@ -9,7 +9,7 @@ type JwtClaims struct {
jwt.RegisteredClaims
// Nexus Standard
Session int `json:"sed"`
Session string `json:"sed"`
CacheTTL time.Duration `json:"ttl,omitempty"`
// OIDC Standard

View File

@ -39,6 +39,9 @@ func NewJwtReader(fp string) (*JwtReader, error) {
}, nil
}
// ReadJwt is the helper method to help me validate and parse jwt.
// To use it, pass the initialized jwt reader which contains public key.
// And pass the token string, and a pointer struct (you must initialize it, which it cannot be nil) of your claims
func ReadJwt[T jwt.Claims](v *JwtReader, in string, out T) (T, error) {
token, err := jwt.ParseWithClaims(in, out, func(token *jwt.Token) (interface{}, error) {
if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok {