A JWT token generator package for flutter and dart.
Features
Generate HS256 algorithm jwt token.
Getting started
Add the depency to pubspec.yaml and start using its methods.
Usage
- Instantiate JWT class.
- Declare the payload.
- Use generateToken method.
JWT jwt = JWT();
Map<String, dynamic> payload = {
'iss': 'localhost',
'exp': DateTime.now().add(Duration(hours: 1)).millisecondsSinceEpoch / 1000,
'id': 1,
'fullname': 'User name'
};
String token = await jwt.generateToken(payload: payload, secretKey: 'SampleKey');
To validate JWT
- Instantiate JWT class.
- Use validate JWT method.
JWT jwt = JWT();
bool isValidated = await jwt.verifyTokey(token: token, secretKey: secretKey);
print(isValidated);// True or False
Additional information
Currently supported algorithm: HS256 will be adding more algorithm soon or if you want to contribute you are welcome.
Libraries
- jwt_token_generator
- Support for doing something awesome.