Search packages, repositories and app categories

Package detailsv0.3.1

jwt_decode

A easy dart package to decode JSON Web Tokens, and to check and give its expiry dates

AndroidiOSWebmacOSWindowsLinux
30-day downloads
697K
Likes
123
Pub points
150

Install package

flutter pub add jwt_decode

Package Overview

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

A simple Dart package for decoding JSON Web Tokens (JWTs), enabling easy access to payload data and verification of expiration dates. It supports parsing JWTs across multiple 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. With minimal setup via `flutter pub add jwt_decode`, developers can quickly extract claims and validate token validity.

Use cases

  • Authentication workflows
  • API token validation
  • User session management
  • Secure data exchange
  • Token expiry checks

Key features

  • Easy JWT decoding
  • Expiration date validation
  • Cross-platform support
  • Minimal setup
  • Payload claim extraction

Suitable for

  • Mobile app developers
  • Web application builders
  • Backend service integrators
  • Security-focused projects
  • Authentication system implementers

Considerations

  • Does not verify signatures
  • Requires external validation for security
  • Limited to decoding, not signing
  • Not suitable for production without additional checks
  • Depends on correct token format

Original README

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

jwt_decode

jwt_decode is a lightweight library for decoding JSON Web Tokens (JWTs) in Dart.

IMPORTANT: This library does not validate the tokens. It can decode any well-formed ones.

Installation

Add jwt_decode to your project's pubspec.yaml file:

dependencies:
  jwt_decode: ^0.3.1

Then run flutter pub get to install the package.

Using

Here's an example of how to use jwt_decode to decode a JWT:

import 'package:jwt_decode/jwt_decode.dart';

void main() {
  final String token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjE1MTYyMzkwMjJ9.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';
  final Map<String, dynamic> decodedToken = Jwt.parseJwt(token);
  print(decodedToken);
}

This will output the following:

{
  "sub": "1234567890",
  "name": "John Doe",
  "iat": 1516239022,
  "exp": 1516239022
}

API Reference

Jwt.parseJwt(String token)

Parses the given JWT and returns a map containing the token's claims.

Jwt.getExpiryDate(String token)

Parses the given JWT and returns the DateTime object containing the token's expiry date if the token is valid and null if not.

Jwt.isExpired(String token)

Parses the given JWT and returns true if the token is still valid, and false otherwise.

Contributing

Contributions are welcome! Please see our Contributing Guidelines for more information.

License

jwt_decode is licensed under the BSD 3-clause license.

Categories

Source repository

Projects using this package