红鱼儿

统计

基于jwt制作Token
function TfrmSimple.BuildTokenFR(path, key: string; validtime:Int64): string;
var
   LToken: TJWT;
begin
     LToken := TJWT.Create;
     try
        LToken.Claims.Subject := path;
        LToken.Claims.IssuedAt := Now;
        LToken.Claims.Expiration := Now + validtime;
        LToken.Claims.Issuer := '';
        LToken.Claims.JWTId:='';
        result:=TJOSE.SHA256CompactToken(key,LToken);
     finally
        LToken.Free;
     end;
end;

直接上代码,下面是调用代码:

 memoCompact.Lines.Add(  BuildTokenFR('order.cpt','123456',30*60*1000));

返回结果:

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJvcmRlci5jcHQiLCJpYXQiOjE1OTQwMzAzNTIsImV4cCI6MTU3MTE0MDMwMzUyfQ.DsceM8yrgp8S4-2Xor7de11YXq9eULYkD2-blY6B2BE

开源地址:

https://github.com/paolo-rossi/delphi-jose-jwt

 

posted on 2020-07-06 18:13  红鱼儿  阅读(60)  评论(0编辑  收藏