mirror of
https://github.com/jonasroussel/dart_jsonwebtoken.git
synced 2025-08-24 21:23:39 +08:00
Set parameters when using JWT.decode
Set audience, issuer, subject and jwtId when using the JWT.decode function
This commit is contained in:
@ -188,6 +188,9 @@ class JWT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Decode a token without checking its signature
|
/// Decode a token without checking its signature
|
||||||
|
///
|
||||||
|
/// This also sets [JWT.audience], [JWT.subject], [JWT.issuer], and
|
||||||
|
/// [JWT.jwtId] even though they are not verified. Use with caution.
|
||||||
static JWT decode(String token) {
|
static JWT decode(String token) {
|
||||||
try {
|
try {
|
||||||
final parts = token.split('.');
|
final parts = token.split('.');
|
||||||
@ -207,6 +210,10 @@ class JWT {
|
|||||||
return JWT(
|
return JWT(
|
||||||
payload,
|
payload,
|
||||||
header: header,
|
header: header,
|
||||||
|
audience: _parseAud(payload['aud']),
|
||||||
|
issuer: payload['iss']?.toString(),
|
||||||
|
subject: payload['sub']?.toString(),
|
||||||
|
jwtId: payload['jti']?.toString(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (ex, stackTrace) {
|
} catch (ex, stackTrace) {
|
||||||
|
Reference in New Issue
Block a user