flutter jwt code example
Example 1: flutter jwt
import 'package:corsac_jwt/corsac_jwt.dart';
void main() {
var builder = new JWTBuilder();
var token = builder
..issuer = 'https://api.foobar.com'
..expiresAt = new DateTime.now().add(new Duration(minutes: 3))
..setClaim('data', {'userId': 836})
..getToken();
var signer = new JWTHmacSha256Signer('sharedSecret');
var signedToken = builder.getSignedToken(signer);
print(signedToken);
var stringToken = signedToken.toString();
var decodedToken = new JWT.parse(stringToken);
print(decodedToken.verify(signer));
var validator = new JWTValidator()
..issuer = 'https://api.foobar.com';
Set<String> errors = validator.validate(decodedToken);
print(errors);
}
Example 2: post jwt token flutter
String token = await Candidate().getToken();
final response = await http.get(url, headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $token',
});
print('Token : ${token}');
print(response);