真心哥 發表於 2019-8-17 10:36:00

JWT Claims

<p>JWT Claims</p>
<p>“iss” (issuer) &nbsp;发行人</p>
<p>“sub” (subject) &nbsp;主题</p>
<p>“aud” (audience) 接收方&nbsp;用户</p>
<p>“exp” (expiration time) 到期时间</p>
<p>“nbf” (not before)&nbsp; 在此之前不可用</p>
<p>“iat” (issued at)&nbsp; jwt的签发时间</p>
<p>“jti” (JWT ID)&nbsp; jwt的唯一身份标识,主要用来作为一次性token,从而回避重放攻击。</p>
<div class="cnblogs_Highlighter">
<pre class="brush:csharp;gutter:true;">/// &lt;summary&gt;
///   JSON Web Token (JWT) claims set.
/// &lt;/summary&gt;
TJWTClaims = class(TJOSEBase)
private
    const AUDIENCE_SEPARATOR = ',';
private
    function GetAudience: string;
    function GetExpiration: TDateTime;
    function GetIssuedAt: TDateTime;
    function GetIssuer: string;
    function GetJWTId: string;
    function GetNotBefore: TDateTime;
    function GetSubject: string;
    procedure SetAudience(Value: string);
    procedure SetExpiration(Value: TDateTime);
    procedure SetIssuedAt(Value: TDateTime);
    procedure SetIssuer(Value: string);
    procedure SetJWTId(Value: string);
    procedure SetNotBefore(Value: TDateTime);
    procedure SetSubject(Value: string);

    function GetHasAudience: Boolean;
    function GetHasExpiration: Boolean;
    function GetHasIssuedAt: Boolean;
    function GetHasIssuer: Boolean;
    function GetHasJWTId: Boolean;
    function GetHasNotBefore: Boolean;
    function GetHasSubject: Boolean;

    function ClaimExists(const AClaimName: string): Boolean;
    function GetAudienceArray: TArray&lt;string&gt;;
    procedure SetAudienceArray(const Value: TArray&lt;string&gt;);
public
    constructor Create; virtual;
    procedure SetClaimOfType&lt;T&gt;(const AName: string; const AValue: T);
    function GenerateJWTId(ANumberOfBytes: Integer = 16): string;

    property Audience: string read GetAudience write SetAudience;
    property AudienceArray: TArray&lt;string&gt; read GetAudienceArray write SetAudienceArray;
    property HasAudience: Boolean read GetHasAudience;
    property Expiration: TDateTime read GetExpiration write SetExpiration;
    property HasExpiration: Boolean read GetHasExpiration;
    property IssuedAt: TDateTime read GetIssuedAt write SetIssuedAt;
    property HasIssuedAt: Boolean read GetHasIssuedAt;
    property Issuer: string read GetIssuer write SetIssuer;
    property HasIssuer: Boolean read GetHasIssuer;
    property JWTId: string read GetJWTId write SetJWTId;
    property HasJWTId: Boolean read GetHasJWTId;
    property NotBefore: TDateTime read GetNotBefore write SetNotBefore;
    property HasNotBefore: Boolean read GetHasNotBefore;
    property Subject: string read GetSubject write SetSubject;
    property HasSubject: Boolean read GetHasSubject;
end;
</pre>
</div>
<p>  </p>
<p>&nbsp;</p>

</div>
<div id="MySignature" role="contentinfo">
    <p>本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/11367704.html</p><br><br>
来源:https://www.cnblogs.com/hnxxcxg/p/11367704.html
頁: [1]
查看完整版本: JWT Claims