JWT Library for Token Creation and Verification
RFC7519 Internet Engineering Task Force (Ietf) Updated May 2015 Source https://tools.ietf.org/html/rfc7519
Abstract - Json Web Token (JWT) is a compact, URL -SAFE MEANS OF REPRESENTING CLAIMS TO BE TRANSFER BETWEEN TWO SHORTS. The Claims in a jwt are enoded as a json object that is used as the payload of a json web signature (jws) struture or as the plaintext of a json web enryction (jWE) struture, enabling the claims to be digitally signed or integrity protected with message authentication code (MAC) and/or Encrypted.
Summary - JSON Web Token (JWT) is a compact and URL means of representing claims to be transferred between two parts. The claims in a JWT are encoded as a JSON object that is used as the useful load of a JSON Web Subscription Structure (JWS) or as the simple text of a JSO Web encryption structure (JWE), allowing the statements to be digitally signed or protected with a message authentication code (MAC) and/or encrypted.
BOSS INSTALL LUISNT/BENJAMIM
{
jti - Jwt ID - Jwt ID (ID)
iss - Issuer - Issuer (Issuer)
sub - Subject - Subject matter
aud - Audience - Audience (Remote IP)
iat - Issued At - Issued on (When Token was Issued / Automatic)
nbf - Not Before - Validity Started (Starts At)
exp - Expiration Time - Expired Validity (Expires On)
add - custom key - can be: integer, decimal, datetime, boolean, JsonObject, JsonArray and Variant
jti - Jwt ID - Jwt ID ( ID )
iss - Issuer - Emissor ( Emissor )
sub - Subject - Assunto
aud - Audience - Audiência ( Remote IP )
iat - Issued At - Emitido em ( Quando o Token foi Emitido / Automático )
nbf - Not Before - Validade Iniciada ( Inicia Em )
exp - Expiration Time - Validade Terminada ( Expirar Em )
add - custom key - can be: integer, decimal, datetime, boolean, JsonObject, JsonArray e Variant
}
uses
System.SysUtils
, Benjamim
;
procedure print (aToken: string; aSign: boolean);
begin
WriteLn(EmptyStr);
WriteLn( ' Token: ' );
WriteLn(aToken);
WriteLn( ' Algorithm: ' , Benjamim.JWT.Header.Algorithm);
WriteLn( ' Sign: ' , BoolToStr(aSign, true));
WriteLn(EmptyStr);
WriteLn(EmptyStr);
end ;
var
LToken: string;
LSign : boolean;
begin
ReportMemoryLeaksOnShutdown := true;
Benjamim.JWT.Password( ' secret ' ); { OPTIONAL }
Benjamim.JWT.Header.Algorithm(TJwtAlgorithm.HS512); { OPTIONAL - DEFAULT TJwtAlgorithm.HS256 }
Benjamim.JWT.Payload.jti( 1 )
.iss( ' Luis Nt ' )
.sub( ' Chave de acesso ' )
.aud( ' 192.168.0.77 ' )
.iat( ' 2021-01-31 15:55:21.123 ' )
.nbf( ' 2021-01-31 18:01:01.001 ' )
.exp( ' 2021-01-31 22:01:01.001 ' )
.add( ' price ' , 10.5 )
.add( ' name ' , ' your fullname ' )
.add( ' phone ' , 559822223333 )
;
LToken := Benjamim.JWT.Signature.Sign;
LSign :=
Benjamim.JWT
.Token(LToken)
.Signature
.Verify;
print(LToken, LSign);
ReadLn;
end .
uses
Benjamim
;
procedure print (aToken: string; aSign: boolean);
begin
WriteLn(EmptyStr);
WriteLn( ' Token: ' );
WriteLn(aToken);
WriteLn( ' Algorithm: ' , Benjamim.JWT.Header.Algorithm);
WriteLn( ' Sign: ' , BoolToStr(aSign, true));
WriteLn(EmptyStr);
WriteLn(EmptyStr);
end ;
var
LToken: string;
LSign : boolean;
begin
ReportMemoryLeaksOnShutdown := true;
LToken :=
' eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Ikpva ' +
' G4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c ' ;
LSign :=
Benjamim.JWT
.Token(LToken)
.Password( ' your-256-bit-secret ' ) { usado no site JWT.io }
.Signature
.Verify;
print(LToken, LSign);
ReadLn;
end .