Skip to content

Commit

Permalink
* JWT Issuer is now configurable through [AppName].JWT.Issuer param
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-magni committed Feb 18, 2017
1 parent e9ceb8c commit 34c4a28
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Source/MARS.Core.Token.pas
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ interface
type
TMARSToken = class
public
const JWT_ISSUER = 'MARS-Curiosity';
const JWT_USERNAME = 'UserName';
const JWT_ROLES = 'Roles';

const JWT_ISSUER_PARAM = 'JWT.Issuer';
const JWT_ISSUER_PARAM_DEFAULT = 'MARS-Curiosity';
const JWT_SECRET_PARAM = 'JWT.Secret';
const JWT_SECRET_PARAM_DEFAULT = '{788A2FD0-8E93-4C11-B5AF-51867CF26EE7}';
const JWT_COOKIEENABLED_PARAM = 'JWT.CookieEnabled';
Expand All @@ -51,6 +52,7 @@ TMARSToken = class
FCookieSecure: Boolean;
FRequest: TWebRequest;
FResponse: TWebResponse;
FIssuer: string;
function GetUserName: string;
procedure SetUserName(const AValue: string);
function GetExpiration: TDateTime;
Expand Down Expand Up @@ -88,6 +90,7 @@ TMARSToken = class
property IsVerified: Boolean read FIsVerified;
property Claims: TMARSParameters read FClaims;
property Expiration: TDateTime read GetExpiration;
property Issuer: string read FIssuer;
property IssuedAt: TDateTime read GetIssuedAt;
property Duration: TDateTime read FDuration;
property CookieEnabled: Boolean read FCookieEnabled;
Expand Down Expand Up @@ -161,6 +164,7 @@ constructor TMARSToken.Create(const ARequest: TWebRequest; const AResponse: TWeb
FRequest := ARequest;
FResponse := AResponse;

FIssuer := AParameters.ByName(JWT_ISSUER_PARAM, JWT_ISSUER_PARAM_DEFAULT).AsString;
FCookieEnabled := AParameters.ByName(JWT_COOKIEENABLED_PARAM, JWT_COOKIEENABLED_PARAM_DEFAULT).AsBoolean;
FCookieName := AParameters.ByName(JWT_COOKIENAME_PARAM, JWT_COOKIENAME_PARAM_DEFAULT).AsString;
FCookieDomain := AParameters.ByName(JWT_COOKIEDOMAIN_PARAM, AURL.Hostname).AsString;
Expand Down Expand Up @@ -305,7 +309,7 @@ procedure TMARSToken.Build(const ASecret: string);
LJWT := TJWT.Create(TJWTClaims);
try
LIssuedAt := Now;
FClaims[TReservedClaimNames.ISSUER] := JWT_ISSUER;
FClaims[TReservedClaimNames.ISSUER] := FIssuer;
FClaims[TReservedClaimNames.ISSUED_AT] := DateTimeToUnix(LIssuedAt, False);
FClaims[TReservedClaimNames.EXPIRATION] := DateTimeToUnix(LIssuedAt + Duration, False);
FClaims.SaveToJSON(LJWT.Claims.JSON);
Expand Down

0 comments on commit 34c4a28

Please sign in to comment.