delphimvcframework/samples/jsonwebtoken/WebModuleUnit1.pas

64 lines
1.5 KiB
ObjectPascal
Raw Normal View History

2016-05-23 17:26:00 +02:00
unit WebModuleUnit1;
interface
uses
System.SysUtils,
2016-05-23 17:26:00 +02:00
System.Classes,
Web.HTTPApp,
MVCFramework,
MVCFramework.Commons;
2016-05-23 17:26:00 +02:00
type
TWebModule1 = class(TWebModule)
procedure WebModuleCreate(Sender: TObject);
private
MVC: TMVCEngine;
public
{ Public declarations }
end;
var
WebModuleClass: TComponentClass = TWebModule1;
implementation
{$R *.dfm}
uses
AppControllerU,
System.Generics.Collections,
2016-05-23 17:26:00 +02:00
AuthenticationU,
MVCFramework.Middleware.JWT,
MVCFramework.JWT,
System.DateUtils;
2016-05-23 17:26:00 +02:00
procedure TWebModule1.WebModuleCreate(Sender: TObject);
var
lClaimsSetup: TJWTClaimsSetup;
2016-05-23 17:26:00 +02:00
begin
lClaimsSetup := procedure(const JWT: TJWT)
begin
JWT.Claims.Issuer := 'Delphi MVC Framework JWT Middleware Sample';
JWT.Claims.ExpirationTime := Now + OneHour; // valid for 1 hour
JWT.Claims.NotBefore := Now - OneMinute * 5; // valid since 5 minutes ago
JWT.Claims.IssuedAt := Now;
JWT.CustomClaims['mycustomvalue'] := 'hello there';
end;
2016-05-23 17:26:00 +02:00
MVC := TMVCEngine.Create(Self);
MVC.Config[TMVCConfigKey.DocumentRoot] := '..\..\www';
MVC.Config[TMVCConfigKey.SessionTimeout] := '30';
MVC.Config[TMVCConfigKey.DefaultContentType] := 'text/html';
MVC
.AddController(TApp1MainController)
.AddController(TAdminController)
2019-07-26 13:51:11 +02:00
.AddMiddleware(TMVCJWTAuthenticationMiddleware.Create(TAuthenticationSample.Create, 'mys3cr37', '/login', LClaimsSetup,
[TJWTCheckableClaim.ExpirationTime, TJWTCheckableClaim.NotBefore, TJWTCheckableClaim.IssuedAt], 300));
2016-05-23 17:26:00 +02:00
end;
end.