我从API接收到jwt令牌,但我不知道如何从Dart中的令牌提取过期时间。
接收到的令牌
依吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉吉
5条答案
按热度按时间wqnecbli1#
一个优雅的解决方案是使用
jwt_decoder
包。https://pub.dev/packages/jwt_decoderflutter pub add jwt_decoder
1.汇入:
import 'package:jwt_decoder/jwt_decoder.dart';
1.获取所有JWT属性:
或者在这种情况下只检查过期日期:
dwbf0jvd2#
您可以轻松地使用
jwt_decode
包。1.安装jwt_解码
1.支票已过期
以下是软件包URL https://pub.dev/packages/jwt_decode
pod7payv3#
你可以通过解码它来完成,一般来说,JWT令牌由两部分(对象)组成,在上面的JWT中,解码它的结果是:
因此,失效日期是时间戳(1586763136),代表2020年4月13日(星期一)7:32:16 AM。
怎么做?
Dart代码信用分配给:boformer
brc7rcf04#
应使用dart:convert。使用utf8将解码base64,使用json获取Map对象以调用
["exp"]
属性3mpgtkmj5#
如果您想使用软件包,另一种解决方案是:
安装corsac_jwt:https://pub.dev/packages/corsac_jwt#-installing-tab-