Set parameters when using JWT.decode

Set audience, issuer, subject and jwtId when using the JWT.decode function
This commit is contained in:
JHubi1
2025-02-02 09:31:23 +01:00
committed by Jonas Roussel
parent a2a494cf4a
commit a3d2358ee3

View File

@ -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) {