2016-05-23 17:26:00 +02:00
|
|
|
unit WebModuleUnit1;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
2017-03-30 21:22:54 +02:00
|
|
|
uses
|
|
|
|
System.SysUtils,
|
2016-05-23 17:26:00 +02:00
|
|
|
System.Classes,
|
|
|
|
Web.HTTPApp,
|
2017-03-30 21:22:54 +02:00
|
|
|
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}
|
|
|
|
|
|
|
|
|
2017-03-30 21:22:54 +02:00
|
|
|
uses
|
|
|
|
AppControllerU,
|
|
|
|
System.Generics.Collections,
|
2016-05-23 17:26:00 +02:00
|
|
|
AuthenticationU,
|
2017-03-30 21:22:54 +02:00
|
|
|
MVCFramework.Middleware.JWT,
|
2020-04-29 01:59:41 +02:00
|
|
|
MVCFramework.Middleware.StaticFiles,
|
2017-03-30 21:22:54 +02:00
|
|
|
MVCFramework.JWT,
|
|
|
|
System.DateUtils;
|
2016-05-23 17:26:00 +02:00
|
|
|
|
|
|
|
procedure TWebModule1.WebModuleCreate(Sender: TObject);
|
2016-06-23 11:42:16 +02:00
|
|
|
var
|
|
|
|
lClaimsSetup: TJWTClaimsSetup;
|
2016-05-23 17:26:00 +02:00
|
|
|
begin
|
2016-06-23 11:42:16 +02:00
|
|
|
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.SessionTimeout] := '30';
|
|
|
|
MVC.Config[TMVCConfigKey.DefaultContentType] := 'text/html';
|
2019-10-30 00:21:13 +01:00
|
|
|
MVC
|
|
|
|
.AddController(TApp1MainController)
|
|
|
|
.AddController(TAdminController)
|
2019-07-26 13:51:11 +02:00
|
|
|
.AddMiddleware(TMVCJWTAuthenticationMiddleware.Create(TAuthenticationSample.Create, 'mys3cr37', '/login', LClaimsSetup,
|
2020-04-29 01:59:41 +02:00
|
|
|
[TJWTCheckableClaim.ExpirationTime, TJWTCheckableClaim.NotBefore, TJWTCheckableClaim.IssuedAt], 300))
|
|
|
|
.AddMiddleware(TMVCStaticFilesMiddleware.Create(
|
|
|
|
'/', { StaticFilesPath }
|
|
|
|
'..\..\www' { DocumentRoot }
|
|
|
|
));
|
2016-05-23 17:26:00 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|