Search categories, packages and repositories

Package detailsv2.0.2

corsac_jwt

Lightweight implementation of JSON Web Tokens (JWT).

AndroidiOSWebmacOSWindowsLinux
30-day downloads
20.8K
Likes
29
Pub points
150

Install package

flutter pub add corsac_jwt

Package Overview

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

Corsac JWT is a lightweight Dart package for implementing JSON Web Tokens (JWT) in Flutter applications. It provides a simple and efficient way to generate, verify, and decode JWTs, making it ideal for secure authentication and authorization workflows. The package supports all major platforms including Android, iOS, Web, macOS, Windows, and Linux. With minimal dependencies and clear API design, it integrates seamlessly into apps requiring token-based security. Its focus on performance and correctness ensures reliable handling of JWTs in both client and server environments.

Use cases

  • User authentication
  • Token-based authorization
  • Secure session management
  • API request signing
  • Stateless authentication
  • Cross-platform token handling

Key features

  • Lightweight and fast
  • Supports all Flutter platforms
  • Simple and intuitive API
  • Robust JWT validation
  • No external dependencies
  • Comprehensive decoding and encoding

Suitable for

  • Mobile and web apps needing JWT
  • Developers prioritizing security
  • Projects with stateless auth requirements
  • Apps using REST APIs
  • Teams seeking minimal crypto libraries
  • Flutter apps targeting multiple platforms

Considerations

  • Requires manual handling of token storage
  • No built-in refresh token logic
  • Limited to JWT-specific functionality
  • Not suitable for complex cryptographic operations
  • Depends on correct implementation of token lifecycle
  • Best used with additional security practices

Original README

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

Lightweight implementation of JSON Web Tokens (JWT).

Usage

import 'package:corsac_jwt/corsac_jwt.dart';

void main() {
  var builder = new JWTBuilder();
  var token = builder
    ..issuer = 'https://api.foobar.com'
    ..expiresAt = new DateTime.now().add(new Duration(minutes: 3))
    ..setClaim('data', {'userId': 836})
    ..getToken(); // returns token without signature

  var signer = new JWTHmacSha256Signer('sharedSecret');
  var signedToken = builder.getSignedToken(signer);
  print(signedToken); // prints encoded JWT
  var stringToken = signedToken.toString();

  var decodedToken = new JWT.parse(stringToken);
  // Verify signature:
  print(decodedToken.verify(signer)); // true

  // Validate claims:
  var validator = new JWTValidator() // uses DateTime.now() by default
    ..issuer = 'https://api.foobar.com'; // set claims you wish to validate
  Set<String> errors = validator.validate(decodedToken);
  print(errors); // (empty list)
}

Supported signers:

  • HS256 (JWTHmacSha256Signer).
  • RS256 (JWTRsaSha256Signer)
  • ES256 (JWTEcdsaSha256Signer)

Refer to documentation for more details.

License

BSD-2

Categories

Dependencies

Dependency list 4 items

Source repository

Projects using this package

No data available yet.