搜尋套件、儲存庫與 APP 分類

套件詳情v0.3.1

jwt_decode

一個簡單的 Dart 套件,用於解碼 JSON Web 權杖,並檢查和提供其到期時間

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
69.7萬
喜歡數
123
Pub 分數
150

安裝套件

flutter pub add jwt_decode

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個簡單的 Dart 套件,用於解碼 JSON Web 權杖 (JWT),可輕鬆存取載入資料並驗證過期日期。它支援在 Android、iOS、Web、macOS、Windows 和 Linux 等多個平台解析 JWT。此套件非常適合需要安全權杖處理的應用程式,例如驗證系統或 API 整合。透過 `flutter pub add jwt_decode` 進行最少設定,開發者可快速提取宣告並驗證權杖有效性。

適用情境

  • 身分驗證工作流程
  • API令牌驗證
  • 使用者會話管理
  • 安全數據交換
  • 令牌過期檢查

主要特色

  • 輕鬆解碼 JWT
  • 有效期限驗證
  • 跨平台支援
  • 最小設定
  • 有效載荷聲明提取

適合對象

  • 行動應用開發者
  • Web 應用程式建構器
  • 後端服務整合商
  • 注重安全的項目
  • 身分驗證系統實現者

使用建議

  • 不驗證簽名
  • 需要外部驗證以確保安全
  • 僅限解碼,不支援簽名
  • 在沒有額外檢查的情況下不適合用於生產
  • 依賴於正確的令牌格式

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

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.

所屬分類

原始碼儲存庫

使用此套件的專案