danieleteti / delphimvcframework

DMVCFramework (for short) is a popular and powerful framework for WEB API in Delphi. Supports RESTful and JSON-RPC WEB APIs development.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Senseless Default-Parameter in new TMVCJWTAuthenticationMiddleware Constructor

DeddyH opened this issue · comments

In the "new" constructor the fourth parameter AConfigClaims of type TJWTClaimsSetup is default nil, but if you leave it blank you will get an exception in OnBeforeRouting. To solve this problem I suggest one of the following solutions:

  1. Make it mandatory. This would require swapping params for uniqueness, e.g.
constructor Create(
  AConfigClaims: TJWTClaimsSetup; 
  AAuthenticationHandler: IMVCAuthenticationHandler; 
  ASecret: string = 'D3lph1MVCFram3w0rk';
  ALoginURLSegment: string = '/login'; 
  AClaimsToCheck: TJWTCheckableClaims = []; 
  ALeewaySeconds: Cardinal = 300); overload; virtual;
  1. Leave the signature as is, but set up a default one if nil, e.g.
constructor TMVCJWTAuthenticationMiddleware.Create(AAuthenticationHandler: IMVCAuthenticationHandler;
  ASecret, ALoginURLSegment: string; AConfigClaims: TJWTClaimsSetup; AClaimsToCheck: TJWTCheckableClaims;
  ALeewaySeconds: Cardinal);
begin
  inherited Create;
  FAuthenticationHandler := AAuthenticationHandler;
  FSetupJWTClaims := AConfigClaims;
  if not Assigned(FSetupJWTClaims) then
    FSetupJWTClaims := procedure(const JWT: TJWT)
	  begin
	    // setup some reasonable claims here
	  end;
  ...
end;