From ae37ed0fc336603a9f9f76c55c6fd7a511ed0dc1 Mon Sep 17 00:00:00 2001 From: Rodrigo Bernardi Date: Thu, 18 Apr 2019 12:28:12 -0300 Subject: [PATCH] Added free on jwt --- src/Horse.JWT.pas | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/Horse.JWT.pas b/src/Horse.JWT.pas index 441ffb1..d9464d3 100644 --- a/src/Horse.JWT.pas +++ b/src/Horse.JWT.pas @@ -53,34 +53,38 @@ procedure Middleware(Req: THorseRequest; Res: THorseResponse; Next: TProc); LValidations := TJOSEConsumerBuilder.NewConsumer.SetVerificationKey(SecretJWT) .SetSkipVerificationKeyValidation.SetRequireExpirationTime.Build; - - LJWT := TJOSEContext.Create(LToken, TJWTClaims); try + + LJWT := TJOSEContext.Create(LToken, TJWTClaims); try try - LValidations.ProcessContext(LJWT); - LJSON := LJWT.GetClaims.JSON; + try + LValidations.ProcessContext(LJWT); + LJSON := LJWT.GetClaims.JSON; - if Assigned(SessionClass) then - begin - LSession := SessionClass.Create; - TJson.JsonToObject(LSession, LJSON); - end - else - LSession := LJSON; + if Assigned(SessionClass) then + begin + LSession := SessionClass.Create; + TJson.JsonToObject(LSession, LJSON); + end + else + LSession := LJSON; - THorseHackRequest(Req).SetSession(LSession); - Next(); - finally - LSession.Free; - end; + THorseHackRequest(Req).SetSession(LSession); + Next(); + finally + LSession.Free; + end; - except - Res.Send('Unauthorized').Status(401); - raise EHorseCallbackInterrupted.Create; + except + Res.Send('Unauthorized').Status(401); + raise EHorseCallbackInterrupted.Create; + end; + finally + LJWT.Free; end; finally - LJWT.Free; + LValidations.Free; end; end;