JWT Claims

JWT Claims

"Iss" (issuer) Issuer

"Sub" (subject) theme

"Aud" (audience) recipient user

"Exp" (expiration time) expires

"Nbf" (not before) Before unavailable

"Iat" (issued at) jwt the issue of time

"Jti" (JWT ID) jwt unique identity, is mainly used as a one-time token, in order to avoid a replay attack.

  /// <summary>
  ///   JSON Web Token (JWT) claims set.
  /// </summary>
  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<string>;
    procedure SetAudienceArray(const Value: TArray<string>);
  public
    constructor Create; virtual;
    procedure SetClaimOfType<T>(const AName: string; const AValue: T);
    function GenerateJWTId(ANumberOfBytes: Integer = 16): string;

    property Audience: string read GetAudience write SetAudience;
    property AudienceArray: TArray<string> 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;

  

 

Guess you like

Origin www.cnblogs.com/hnxxcxg/p/11367704.html
jwt