2020-05-15 15:53:13 +02:00
|
|
|
unit WebModuleUnit1;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.SysUtils,
|
|
|
|
System.Classes,
|
|
|
|
Web.HTTPApp,
|
|
|
|
MVCFramework,
|
|
|
|
MVCFramework.Commons;
|
|
|
|
|
|
|
|
type
|
|
|
|
TWebModule1 = class(TWebModule)
|
|
|
|
procedure WebModuleCreate(Sender: TObject);
|
|
|
|
procedure WebModuleDestroy(Sender: TObject);
|
|
|
|
|
|
|
|
private
|
|
|
|
FEngine: TMVCEngine;
|
|
|
|
|
|
|
|
public
|
|
|
|
{ Public declarations }
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
WebModuleClass: TComponentClass = TWebModule1;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
AppControllerU,
|
|
|
|
System.Generics.Collections,
|
|
|
|
AuthenticationU,
|
|
|
|
MVCFramework.Middleware.JWT,
|
|
|
|
MVCFramework.Middleware.StaticFiles,
|
|
|
|
MVCFramework.JWT,
|
|
|
|
System.DateUtils;
|
|
|
|
|
|
|
|
procedure TWebModule1.WebModuleCreate(Sender: TObject);
|
|
|
|
var
|
|
|
|
lClaimsSetup: TJWTClaimsSetup;
|
|
|
|
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;
|
|
|
|
|
|
|
|
FEngine := TMVCEngine.Create(Self);
|
|
|
|
|
|
|
|
FEngine
|
|
|
|
.AddController(TApp1MainController)
|
|
|
|
.AddController(TAdminController)
|
2022-09-10 11:59:45 +02:00
|
|
|
.AddMiddleware(TMVCJWTAuthenticationMiddleware.Create(TAuthenticationSample.Create, lClaimsSetup, 'mys3cr37', '/login',
|
2020-09-24 21:30:45 +02:00
|
|
|
[TJWTCheckableClaim.ExpirationTime, TJWTCheckableClaim.NotBefore, TJWTCheckableClaim.IssuedAt], 300));
|
2020-05-15 15:53:13 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TWebModule1.WebModuleDestroy(Sender: TObject);
|
|
|
|
begin
|
|
|
|
FEngine.Free;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|