パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v2.0.1

jwt_decoder

この小さなライブラリは、JSON Webトークンをデコードするのを助けます。また、JWTがすでに有効期限切れかどうかを確認することもできます。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
65.5万
いいね数
552
Pub ポイント
160

パッケージをインストール

flutter pub add jwt_decoder

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

jwt_decoder パッケージは、JSON Web Tokens (JWT) を効率的にデコードするための軽量な Dart ライブラリです。開発者が JWT からペイロードデータを抽出し、トークンが有効期限切れかどうかを確認できるようにします。シンプルさを重視して構築されており、Android、iOS、Web、macOS、Windows、Linux などの主要プラットフォームをすべてサポートしています。認証システムやユーザー セッション管理に JWT を使用する API 統合など、セキュアなトークン処理が必要なアプリケーションに最適です。

用途

  • 認証フローにおける JWT ペイロードの解析
  • API 呼び出し前にトークンの有効期限を検証する
  • トークンからユーザーのクレームを抽出する
  • クロスプラットフォームアプリにおけるJWTベースの認証の統合
  • 開発中のJWT構造のデバッグ

主な機能

  • JWT の簡単なデコード
  • 内蔵の有効期限チェック
  • クロスプラットフォーム互換性
  • 軽量で依存関係が最小限
  • すべてのFlutterプラットフォームをサポートしています

適している対象

  • JWT認証を使用するFlutterアプリ
  • 迅速なJWTの検査が必要な開発者
  • JWTトークンを使用したバックエンド統合
  • セキュアなトークン検証を必要とするアプリ

注意事項

  • JWT署名を検証しない
  • 復号のみ、真正性の検証は行わない
  • 追加の検証なしでは、本番環境のセキュリティチェックには適していません
  • 署名の検証には外部ロジックが必要です

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

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

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト

ランキング