Skip to content

Commit 2480e0b

Browse files
committed
Added method SetCustomClaim(const AName: string; const AValue: TValue) to the IJOSEProducerBuilder interface
1 parent 44c54d9 commit 2480e0b

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

Source/Common/JOSE.Types.JSON.pas

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ EJSONConversionException = class(Exception);
4949
TJSONArray = System.JSON.TJSONArray;
5050

5151
TJSONUtils = class
52-
private
53-
class procedure SetJSONRttiValue(const AName: string; const AValue: TValue; AJSON: TJSONObject); overload;
5452
public
5553
class function ToJSON(AJSONValue: TJSONValue): string; static;
5654
class function CheckPair(const AName: string; AJSON: TJSONObject): Boolean;
@@ -62,6 +60,7 @@ TJSONUtils = class
6260
class function GetJSONValueAsEpoch(const AName: string; AJSON: TJSONObject): TDateTime;
6361

6462
class procedure SetJSONValue(const AName: string; AValue: TJSONValue; AJSON: TJSONObject); overload;
63+
class procedure SetJSONRttiValue(const AName: string; const AValue: TValue; AJSON: TJSONObject); overload;
6564
class procedure SetJSONValueFrom<T>(const AName: string; const AValue: T; AJSON: TJSONObject);
6665

6766
class procedure RemoveJSONNode(const AName: string; AJSON: TJSONObject);

Source/JOSE/JOSE.Core.JWT.pas

+6
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ TJWTClaims = class(TJOSEBase)
111111
public
112112
constructor Create; virtual;
113113

114+
procedure SetClaim(const AName: string; const AValue: TValue);
114115
procedure SetClaimOfType<T>(const AName: string; const AValue: T);
115116
function GenerateJWTId(ANumberOfBytes: Integer = 16): string;
116117

@@ -221,6 +222,11 @@ destructor TJWT.Destroy;
221222

222223
{ TJWTClaims }
223224

225+
procedure TJWTClaims.SetClaim(const AName: string; const AValue: TValue);
226+
begin
227+
TJSONUtils.SetJSONRttiValue(AName, AValue, FJSON);
228+
end;
229+
224230
procedure TJWTClaims.SetClaimOfType<T>(const AName: string; const AValue: T);
225231
begin
226232
AddPairOfType<T>(AName, AValue);

Source/JOSE/JOSE.Producer.pas

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ interface
2525

2626
uses
2727
System.SysUtils,
28+
System.Rtti,
2829
JOSE.Types.Bytes,
2930
JOSE.Core.Base,
3031
JOSE.Core.Parts,
@@ -67,6 +68,7 @@ TJOSEProducer = class(TInterfacedObject, IJOSEProducer)
6768
function SetJWTId(const AValue: string): IJOSEProducerBuilder;
6869
function SetNotBefore(AValue: TDateTime): IJOSEProducerBuilder;
6970
function SetSubject(const AValue: string): IJOSEProducerBuilder;
71+
function SetCustomClaim(const AName: string; const AValue: TValue): IJOSEProducerBuilder;
7072

7173
function SetKey(const AKey: TJOSEBytes): IJOSEProducerBuilder;
7274
function SetKeyPair(const APublicKey, APrivateKey: TJOSEBytes): IJOSEProducerBuilder;
@@ -97,6 +99,7 @@ TJOSEProducerBuilder = class(TInterfacedObject, IJOSEProducerBuilder)
9799
function SetJWTId(const AValue: string): IJOSEProducerBuilder;
98100
function SetNotBefore(AValue: TDateTime): IJOSEProducerBuilder;
99101
function SetSubject(const AValue: string): IJOSEProducerBuilder;
102+
function SetCustomClaim(const AName: string; const AValue: TValue): IJOSEProducerBuilder;
100103

101104
function SetKey(const AKey: TJOSEBytes): IJOSEProducerBuilder;
102105
function SetKeyPair(const APublicKey, APrivateKey: TJOSEBytes): IJOSEProducerBuilder;
@@ -217,6 +220,12 @@ function TJOSEProducerBuilder.SetAudience(const AValue: TArray<string>): IJOSEPr
217220
Result := Self;
218221
end;
219222

223+
function TJOSEProducerBuilder.SetCustomClaim(const AName: string; const AValue: TValue): IJOSEProducerBuilder;
224+
begin
225+
GetJWT.Claims.SetClaim(AName, AValue);
226+
Result := Self;
227+
end;
228+
220229
function TJOSEProducerBuilder.SetExpiration(AValue: TDateTime): IJOSEProducerBuilder;
221230
begin
222231
GetJWT.Claims.Expiration := AValue;

0 commit comments

Comments
 (0)