mirror of
https://github.com/jonasroussel/dart_jsonwebtoken.git
synced 2025-05-18 00:25:52 +08:00
v2.6.1
This commit is contained in:
@ -1,3 +1,7 @@
|
||||
## 2.6.1
|
||||
|
||||
- Adding a `try` version of `decode`, `verify` and `sign`, that simply returns `null` instead of throwing errors
|
||||
|
||||
## 2.6.0
|
||||
|
||||
- Adding a `JWT.decode` method to simply decode a token without checking its signature
|
||||
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 Jonas Roussel
|
||||
Copyright (c) 2023 Jonas Roussel
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -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);
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: dart_jsonwebtoken
|
||||
description: A dart implementation of the famous javascript library 'jsonwebtoken' (JWT).
|
||||
version: 2.6.0
|
||||
version: 2.6.1
|
||||
repository: https://github.com/jonasroussel/dart_jsonwebtoken
|
||||
homepage: https://github.com/jonasroussel/dart_jsonwebtoken#readme
|
||||
|
||||
|
Reference in New Issue
Block a user