Search packages, repositories and app categories

Package detailsv2.0.1

jwt_decoder

This small library helps you to decode Json Web Tokens, you can also know if a JWT is already expired.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
655K
Likes
552
Pub points
160

Install package

flutter pub add jwt_decoder

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The jwt_decoder package is a lightweight Dart library designed to decode JSON Web Tokens (JWTs) efficiently. It allows developers to extract payload data from JWTs and check whether the token has expired. Built with simplicity in mind, it supports all major platforms including Android, iOS, Web, macOS, Windows, and Linux. The package is ideal for applications requiring secure token handling, such as authentication systems or API integrations that rely on JWTs for user session management.

Use cases

  • Parsing JWT payloads in authentication flows
  • Validating token expiration before API calls
  • Extracting user claims from tokens
  • Integrating JWT-based auth in cross-platform apps
  • Debugging JWT structure during development

Key features

  • Simple decoding of JWTs
  • Built-in expiration checking
  • Cross-platform compatibility
  • Lightweight and minimal dependencies
  • Supports all Flutter platforms

Suitable for

  • Flutter apps using JWT authentication
  • Developers needing quick JWT inspection
  • Backend integration with JWT tokens
  • Apps requiring secure token validation

Considerations

  • Does not verify JWT signatures
  • Only decodes, does not validate authenticity
  • Not suitable for production security checks without additional verification
  • Requires external logic for signature validation

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

JWT Decoder

This is a small library for decoding a json web token for dart / flutter. Since the header and payload is base64 encoded you can easily know the stored data with no password, you can also know if the token is expired or not.

If you like this library there's a version for Vue here. And for React here

Getting Started

Decode a token
main () {
  String yourToken = "Your JWT";
  Map<String, dynamic> decodedToken = JwtDecoder.decode(yourToken);

  /*
  If the token has a valid format, you will get a Map<String, dynamic>
  Your decoded token can look like:
  {
     "sub": "1234567890",
     "name": "Gustavo",
     "iat": 1516239022,
     "exp": 1516239022,
     "randomKey": "something else"
  }
  */
}
Know if the token is expired
main () {
  String yourToken = "Your JWT";
  bool hasExpired = JwtDecoder.isExpired(yourToken);

  // You will get a true / false response
  // true: if the token is already expired
  // false: if the token is not expired
}
Get expiration date
main () {
  String yourToken = "Your JWT";
  DateTime expirationDate = JwtDecoder.getExpirationDate(token);

  // 2025-01-13 13:04:18.000
  print(expirationDate);
}
You can know how old your token is
// Token payload must include an 'iat' field
main () {
  String yourToken = "Your JWT";
  Duration tokenTime = JwtDecoder.getTokenTime(token);

  // 15
  print(tokenTime.inDays);
}

License

MIT

Categories

Source repository

Projects using this package

Rankings