key-sentry
v1.0.1
Published
A secure JWT token generation and management library
Maintainers
Readme
KeySentry
A secure and flexible JWT (JSON Web Token) authentication library for Node.js applications.
Features
- Simple JWT token generation and verification
- Configurable token expiration times
- Support for access and refresh tokens
- Customizable signing algorithms
- Secure default settings
Installation
npm install key-sentryMethods
generateToken(payload, withRefreshToken = true)
Generates an access token and optionally a refresh token.
Parameters:
payload(Object): Data to include in the tokenwithRefreshToken(boolean, optional): Whether to generate a refresh token (default: true)
Returns: Object containing:
accessToken(string): The JWT access tokenaccessTokenExpiresAt(number): Access token expiration timestampissuedAt(number): Token issuance timestamppayload(Object): The data included in the tokenrefreshToken(string, optional): The refresh tokenrefreshTokenExpiresAt(number, optional): Refresh token expiration timestamprefreshIssuedAt(number, optional): Refresh token issuance timestamp
verifyToken(token, tokenType = 'access')
Verifies a token's authenticity and expiration status.
Parameters:
token(string): The token to verifytokenType(string, optional): Type of token ('access' or 'refresh', default: 'access')
Returns: Object containing:
valid(boolean): Whether the token is validexpired(boolean): Whether the token is expiredpayload(Object|null): The decoded payload if available, null otherwiseerror(string, optional): Error message if verification failed
