mirror of
https://github.com/jonasroussel/dart_jsonwebtoken.git
synced 2025-08-06 13:51:08 +08:00
v2.6.1
This commit is contained in:
@ -147,6 +147,37 @@ class JWT {
|
||||
}
|
||||
}
|
||||
|
||||
/// Exactly like `verify`, just return null instead of throwing errors.
|
||||
static JWT? tryVerify(
|
||||
String token,
|
||||
JWTKey key, {
|
||||
bool checkHeaderType = true,
|
||||
bool checkExpiresIn = true,
|
||||
bool checkNotBefore = true,
|
||||
Duration? issueAt,
|
||||
Audience? audience,
|
||||
String? subject,
|
||||
String? issuer,
|
||||
String? jwtId,
|
||||
}) {
|
||||
try {
|
||||
return verify(
|
||||
token,
|
||||
key,
|
||||
checkHeaderType: checkHeaderType,
|
||||
checkExpiresIn: checkExpiresIn,
|
||||
checkNotBefore: checkNotBefore,
|
||||
issueAt: issueAt,
|
||||
audience: audience,
|
||||
subject: subject,
|
||||
issuer: issuer,
|
||||
jwtId: jwtId,
|
||||
);
|
||||
} catch (ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Decode a token without checking its signature
|
||||
static JWT decode(String token) {
|
||||
try {
|
||||
@ -178,6 +209,15 @@ class JWT {
|
||||
}
|
||||
}
|
||||
|
||||
/// Exactly like `decode`, just return `null` instead of throwing errors.
|
||||
static JWT? tryDecode(String token) {
|
||||
try {
|
||||
return decode(token);
|
||||
} catch (ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// JSON Web Token
|
||||
JWT(
|
||||
this.payload, {
|
||||
@ -282,6 +322,27 @@ class JWT {
|
||||
}
|
||||
}
|
||||
|
||||
/// Exactly like `sign`, just return `null` instead of throwing errors.
|
||||
String? trySign(
|
||||
JWTKey key, {
|
||||
JWTAlgorithm algorithm = JWTAlgorithm.HS256,
|
||||
Duration? expiresIn,
|
||||
Duration? notBefore,
|
||||
bool noIssueAt = false,
|
||||
}) {
|
||||
try {
|
||||
return sign(
|
||||
key,
|
||||
algorithm: algorithm,
|
||||
expiresIn: expiresIn,
|
||||
notBefore: notBefore,
|
||||
noIssueAt: noIssueAt,
|
||||
);
|
||||
} catch (ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static Audience? _parseAud(dynamic val) {
|
||||
if (val is String) {
|
||||
return Audience.one(val);
|
||||
|
Reference in New Issue
Block a user