jwt_manager 1.0.0 copy "jwt_manager: ^1.0.0" to clipboard
jwt_manager: ^1.0.0 copied to clipboard

An easy-to-use pure dart JWT manager that creates JWT tokens, verifies a signature, expiration time and others required key fields.

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: 'some@email.com',
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');

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');

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.

2
likes
130
pub points
43%
popularity

Publisher

unverified uploader

An easy-to-use pure dart JWT manager that creates JWT tokens, verifies a signature, expiration time and others required key fields.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

pointycastle, rsa_pkcs

More

Packages that depend on jwt_manager