Last updated:
0 purchases
jwt manager
JWT manager #
An easy-to-use pure dart JWT manager that creates JWT tokens and verifies a signature.
Features #
Creating an encoded JWT token #
// Creating a token
final tokenDto = FcmTokenDto(
iss: '[email protected]',
iat: DateTime(2001),
);
final pemPrivateKey = '-----BEGIN PRIVATE KEY-----...';
// RsaKeyParser extracts private key from a pem string
final parser = RsaKeyParser();
final rsaPrivateKey = parser.extractPrivateKey(pemPrivateKey);
// Create RsaSignifier for signing
final rsaSignifier = RsaSignifier(privateKey: rsaPrivateKey);
// JwtBuilder encodes the token to string and signs it
final jwtBuilder = JwtBuilder(signifier: rsaSignifier);
final jwtToken = jwtBuilder.buildToken(tokenDto);
print('Encoded JWT: $jwtToken');
copied to clipboard
Verifying a signature of jwt token #
final pemPublicKey = '-----BEGIN PUBLIC KEY-----...'
// Extract public key from a pem string
final rsaPublicKey = parser.extractPublicKey(pemPublicKey);
// Verifying the signature
final rsaVerifier = RsaSignatureVerifier(publicKey: rsaPublicKey);
final isVerified = rsaVerifier.verify('signedData', 'signature');
print('Is signature verified: $isVerified');
copied to clipboard
Extra example #
You can also use the full working example from github.
Ideas #
If you have any ideas on how to enhance this package or have any concern, feel free to make an issue.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.