mirror of
https://github.com/jonasroussel/dart_jsonwebtoken.git
synced 2025-08-01 08:42:08 +08:00
v1.5.0
This commit is contained in:
@ -1,3 +1,8 @@
|
|||||||
|
## 1.5.0
|
||||||
|
|
||||||
|
- Debuging `_TypeError issue on sign method` (#4)
|
||||||
|
- Implementing `toString` in the `JWTError` class
|
||||||
|
|
||||||
## 1.4.1
|
## 1.4.1
|
||||||
|
|
||||||
- Formating for 'static analysis'
|
- Formating for 'static analysis'
|
||||||
|
@ -2,9 +2,12 @@ class JWTError extends Error {
|
|||||||
JWTError(this.message);
|
JWTError(this.message);
|
||||||
|
|
||||||
final String 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 {
|
class JWTInvalidError extends JWTError {
|
||||||
JWTInvalidError(String message) : super(message);
|
JWTInvalidError(String message) : super(message);
|
||||||
}
|
}
|
||||||
|
@ -165,26 +165,37 @@ class JWT {
|
|||||||
}) {
|
}) {
|
||||||
final header = {'alg': algorithm.name, 'typ': 'JWT'};
|
final header = {'alg': algorithm.name, 'typ': 'JWT'};
|
||||||
|
|
||||||
if (payload is Map) {
|
if (payload is Map<String, dynamic>) {
|
||||||
if (!noIssueAt) payload['iat'] = secondsSinceEpoch(DateTime.now());
|
payload = Map<String, dynamic>.from(payload);
|
||||||
if (expiresIn != null) {
|
|
||||||
payload['exp'] = secondsSinceEpoch(DateTime.now().add(expiresIn));
|
try {
|
||||||
}
|
if (!noIssueAt) payload['iat'] = secondsSinceEpoch(DateTime.now());
|
||||||
if (notBefore != null) {
|
if (expiresIn != null) {
|
||||||
payload['nbf'] = secondsSinceEpoch(DateTime.now().add(notBefore));
|
payload['exp'] = secondsSinceEpoch(DateTime.now().add(expiresIn));
|
||||||
}
|
}
|
||||||
if (audience != null) payload['aud'] = audience;
|
if (notBefore != null) {
|
||||||
if (subject != null) payload['sub'] = subject;
|
payload['nbf'] = secondsSinceEpoch(DateTime.now().add(notBefore));
|
||||||
if (issuer != null) payload['iss'] = issuer;
|
}
|
||||||
if (jwtId != null) payload['jti'] = jwtId;
|
if (audience != null) payload['aud'] = audience;
|
||||||
|
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 b64Header = base64Unpadded(jsonBase64.encode(header));
|
||||||
final b64Payload = base64Unpadded(
|
|
||||||
payload is String
|
String b64Payload;
|
||||||
? base64.encode(utf8.encode(payload))
|
try {
|
||||||
: jsonBase64.encode(payload),
|
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 body = '${b64Header}.${b64Payload}';
|
||||||
final signature = base64Unpadded(
|
final signature = base64Unpadded(
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: dart_jsonwebtoken
|
name: dart_jsonwebtoken
|
||||||
description: A dart implementation of the famous javascript library 'jsonwebtoken' (JWT).
|
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
|
repository: https://github.com/jonasroussel/jsonwebtoken
|
||||||
homepage: https://github.com/jonasroussel/jsonwebtoken#readme
|
homepage: https://github.com/jonasroussel/jsonwebtoken#readme
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user