This commit is contained in:
Jonas Roussel
2020-12-27 16:45:59 +01:00
parent 2b39a3be15
commit eb4da9be66
4 changed files with 38 additions and 19 deletions

View File

@ -1,3 +1,8 @@
## 1.5.0
- Debuging `_TypeError issue on sign method` (#4)
- Implementing `toString` in the `JWTError` class
## 1.4.1
- Formating for 'static analysis'

View File

@ -2,9 +2,12 @@ class JWTError extends Error {
JWTError(this.message);
final String message;
@override
String toString() => 'JWTError: $message';
}
/// An error thrown when toke is invalid
/// An error thrown when token is invalid
class JWTInvalidError extends JWTError {
JWTInvalidError(String message) : super(message);
}

View File

@ -165,7 +165,10 @@ class JWT {
}) {
final header = {'alg': algorithm.name, 'typ': 'JWT'};
if (payload is Map) {
if (payload is Map<String, dynamic>) {
payload = Map<String, dynamic>.from(payload);
try {
if (!noIssueAt) payload['iat'] = secondsSinceEpoch(DateTime.now());
if (expiresIn != null) {
payload['exp'] = secondsSinceEpoch(DateTime.now().add(expiresIn));
@ -177,14 +180,22 @@ class JWT {
if (subject != null) payload['sub'] = subject;
if (issuer != null) payload['iss'] = issuer;
if (jwtId != null) payload['jti'] = jwtId;
} catch (ex) {}
}
final b64Header = base64Unpadded(jsonBase64.encode(header));
final b64Payload = base64Unpadded(
String b64Payload;
try {
b64Payload = base64Unpadded(
payload is String
? base64.encode(utf8.encode(payload))
: jsonBase64.encode(payload),
);
} catch (ex) {
throw JWTError(
'invalid payload json format (Map keys must be String type)');
}
final body = '${b64Header}.${b64Payload}';
final signature = base64Unpadded(

View File

@ -1,6 +1,6 @@
name: dart_jsonwebtoken
description: A dart implementation of the famous javascript library 'jsonwebtoken' (JWT).
version: 1.4.1
version: 1.5.0
repository: https://github.com/jonasroussel/jsonwebtoken
homepage: https://github.com/jonasroussel/jsonwebtoken#readme