Documentation
¶
Index ¶
- func Decode(encoded string) ([]byte, error)
- func Encode(data []byte) string
- func GenerateJWT(value any, secretKey string, ttl time.Duration, algorithm string) (string, error)
- func Hash(value string, hashCost int) (string, error)
- func ParseJWT(tokenString, secretKey string) (any, error)
- func ValidateHash(value, hashedValue string) bool
- type Config
- type InvalidJWTError
- type JWTClaimsError
- type JWTConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateJWT ¶
GenerateJWT creates a new Json Web Token, based on provided data.
value - any value to store in JWT payload;
secretKey - is a secret, on base of which will be checked, if JWT can be trusted;
ttl - time JWT is appropriate and after which will be expired;
algorithm - JWT hashing algorithm like HS256 and so on.
func Hash ¶
Hash hashes data for security purpose. For example, not to store raw unprotected data on database.
func ParseJWT ¶
ParseJWT decodes a Json Web Token payload.
tokenString - a JWT, which will be parsed;
secretKey - is a secret, on base of which will be checked, if JWT can be trusted;.
func ValidateHash ¶
ValidateHash checks if hashed data is equal to raw data.
Types ¶
type InvalidJWTError ¶
type InvalidJWTError struct {
Message string
}
InvalidJWTError is an error, which represents, that JWT expired or something else went wrong via parsing it.
func (InvalidJWTError) Error ¶
func (e InvalidJWTError) Error() string
type JWTClaimsError ¶
type JWTClaimsError struct {
Message string
}
JWTClaimsError is an error, which represents, that failed to retrieve JWT payload.
func (JWTClaimsError) Error ¶
func (e JWTClaimsError) Error() string