dart_jwt_token 0.0.3 copy "dart_jwt_token: ^0.0.3" to clipboard
dart_jwt_token: ^0.0.3 copied to clipboard

This package is used to create jwt token, verify token with key, and decode without key.

Dart JWT package lets you create jwt token.

Installation #

  1. Add this to your package's pubspec.yaml file:
dependencies:
  dart_jwt_token: ^0.0.2
  1. You can install packages from the command line with Flutter:
$ dart pub get
  1. Import the package and use it in your Flutter App.
import 'package:dart_jwt_token/dart_jwt_token.dart';

Usage #

Create JWT Token #

String createToken(
    {required Map payload,
      required Map<String, dynamic> headers,
      required SecretKey key}) {
  String token = "";
  final jwt = JWT(payload, header: headers);
  token = jwt.sign(key);
  return token;
}

Verify JWT Token #

Map<String, dynamic> verifyToken(String token, SecretKey key) {
  try {
    final jwt = JWT.verify(token, key);
    return jwt.payload;
  } on JWTExpiredError {
    return {"expired": true};
  } on JWTError catch (ex) {
    return {"Error": ex.message};
  }
}
0
likes
160
pub points
73%
popularity

Publisher

unverified uploader

This package is used to create jwt token, verify token with key, and decode without key.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

crypto

More

Packages that depend on dart_jwt_token