forked from grijjy/GrijjyFoundation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grijjy.JWT.pas
40 lines (30 loc) · 892 Bytes
/
Grijjy.JWT.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
unit Grijjy.JWT;
{ Java Web Tokens }
interface
uses
System.SysUtils;
const
{ RSA with SHA256 }
JWT_RS256 = '{"alg":"RS256","typ":"JWT"}';
{ TODO: Added HMAC with SHA256 token support }
{ Creates a Java Web Token using the provided private key in PEM format }
function JavaWebToken(const APrivateKey: TBytes; const AHeader, APayload: String; out AJWT: String): Boolean;
implementation
uses
Grijjy.OpenSSL,
Grijjy.BinaryCoding;
function JavaWebToken(const APrivateKey: TBytes; const AHeader, APayload: String; out AJWT: String): Boolean;
var
Data: TBytes;
JWS: TBytes;
begin
Data := goBase64Encode(BytesOf(AHeader)) + [Ord('.')] + goBase64Encode(BytesOf(APayload));
if TgoSSLHelper.Sign_RSASHA256(Data, APrivateKey, JWS) then
begin
AJWT := StringOf(Data) + '.' + StringOf(goBase64Encode(JWS));
Result := True;
end
else
Result := False;
end;
end.