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,
|
|
|
|
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.DocumentRoot] := '..\..\www';
|
|
|
|
MVC.Config[TMVCConfigKey.SessionTimeout] := '30';
|
|
|
|
MVC.Config[TMVCConfigKey.DefaultContentType] := 'text/html';
|
|
|
|
MVC.AddController(TApp1MainController).AddController(TAdminController)
|
|
|
|
.AddMiddleware(TMVCJWTAuthenticationMiddleware.Create(
|
|
|
|
TAuthenticationSample.Create,
|
2016-06-23 11:42:16 +02:00
|
|
|
lClaimsSetup,
|
2017-07-14 17:38:51 +02:00
|
|
|
'mys3cr37',
|
2019-06-11 19:42:03 +02:00
|
|
|
'/login',
|
|
|
|
[TJWTCheckableClaim.ExpirationTime, TJWTCheckableClaim.NotBefore, TJWTCheckableClaim.IssuedAt],
|
|
|
|
300,
|
2019-07-24 20:48:22 +02:00
|
|
|
TMVCJWTDefaults.AUTHORIZATION_HEADER,
|
|
|
|
TMVCJWTDefaults.USERNAME_HEADER,
|
|
|
|
TMVCJWTDefaults.PASSWORD_HEADER
|
2017-07-14 17:38:51 +02:00
|
|
|
));
|
2016-05-23 17:26:00 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|