Last updated:
0 purchases
fennec jwt
fennec_jwt is dart plugin for generate and validate jwt. it belongs to fennec framework pub.dev but it can be used
separately.
supported hashing algorithms: #
SHA-1
SHA-256
SHA-512
MD5
installation: #
install the plugin from pub.dev
usage #
import 'dart:math';
import 'package:fennec_jwt/fennec_jwt.dart';
final String sharedSecret = '123456';
void main(List<String> arguments) {
final claimSet = JwtClaim(
issuer: 'fennec_jwt',
subject: 'jwt',
audience: <String>['[email protected]'],
jwtId: generateRandomString(32),
otherClaims: <String, dynamic>{},
maxAge: const Duration(minutes: 5),
);
final token = generateJwtHS256(claimSet, sharedSecret);
print('JWT: "$token"\n');
validateJwt(token);
}
void validateJwt(String token) {
final claimSet = verifyJwtHS256Signature(token, sharedSecret);
claimSet.validate(issuer: 'fennec_jwt', audience: '[email protected]');
print(claimSet.toJson());
}
String generateRandomString(int len) {
var r = Random();
return String.fromCharCodes(
List.generate(len, (index) => r.nextInt(33) + 89));
}
copied to clipboard
LICENSE #
MIT
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.