Added Login Parameters to Swagger Documentation

This commit is contained in:
Mauricio Montuori 2019-11-18 22:22:39 -03:00
parent aa93aecbaf
commit 8b48250eba
3 changed files with 19 additions and 1 deletions

View File

@ -92,6 +92,9 @@ type
constructor Create(AAuthenticationHandler: IMVCAuthenticationHandler; ASecret: string = 'D3lph1MVCFram3w0rk';
ALoginURLSegment: string = '/login'; AConfigClaims: TJWTClaimsSetup = nil;
AClaimsToCheck: TJWTCheckableClaims = []; ALeewaySeconds: Cardinal = 300); overload; virtual;
property AuthorizationHeaderName: string read FAuthorizationHeaderName;
property UserNameHeaderName: string read FUserNameHeaderName;
property PasswordHeaderName: string read FPasswordHeaderName;
end;
implementation

View File

@ -248,7 +248,8 @@ begin
LJwtUrlSegment.Insert(0, '/');
// Path operation Middleware JWT
ASwagDoc.Paths.Add(TMVCSwagger.GetJWTAuthenticationPath(LJwtUrlSegment));
ASwagDoc.Paths.Add(TMVCSwagger.GetJWTAuthenticationPath(LJwtUrlSegment,
LJWTMiddleware.UserNameHeaderName, LJWTMiddleware.PasswordHeaderName));
// Methods that have the MVCRequiresAuthentication attribute use bearer authentication.
LSecurityDefsBearer := TSwagSecurityDefinitionApiKey.Create;

View File

@ -558,6 +558,7 @@ class function TMVCSwagger.GetJWTAuthenticationPath(const AJWTUrlSegment: string
var
lSwagPathOp: TSwagPathOperation;
lSwagResponse: TSwagResponse;
lSwagParam: TSwagRequestParameter;
begin
lSwagPathOp := TSwagPathOperation.Create;
lSwagPathOp.Tags.Add('JWT Authentication');
@ -565,6 +566,19 @@ begin
lSwagPathOp.Security.Add(SECURITY_BASIC_NAME);
lSwagPathOp.Description := 'Create JSON Web Token';
lSwagPathOp.Produces.Add(TMVCMediaType.APPLICATION_JSON);
lSwagParam := TSwagRequestParameter.Create;
lSwagParam.Name := AUserNameHeaderName;
lSwagParam.TypeParameter := stpString;
lSwagParam.Required := true;
lSwagParam.InLocation := rpiHeader;
lSwagPathOp.Parameters.Add(lSwagParam);
lSwagParam := TSwagRequestParameter.Create;
lSwagParam.Name := APasswordHeaderName;
lSwagParam.TypeParameter := stpString;
lSwagParam.Required := true;
lSwagParam.InLocation := rpiHeader;
lSwagPathOp.Parameters.Add(lSwagParam);
lSwagResponse := TSwagResponse.Create;
lSwagResponse.StatusCode := HTTP_STATUS.Unauthorized.ToString;