Skip to content

Commit

Permalink
Falha na validação do JWT #39
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciussanchez committed Aug 7, 2023
1 parent 3ed092c commit 5309a67
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ src/*.~*
*.identcache
*.projdata
*.tvsconfig
*.skincfg
*.dsk
*.dcu
*.exe
Expand Down
6 changes: 3 additions & 3 deletions boss-lock.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"hash": "445774d05b3e1b873cfcdb89032b3e1f",
"updated": "2023-03-09T23:35:20.3502827-03:00",
"updated": "2023-08-07T09:27:43.9207961-03:00",
"installedModules": {
"github.com/andre-djsystem/hashlib4pascal": {
"name": "hashlib4pascal",
Expand All @@ -12,8 +12,8 @@
},
"github.com/hashload/horse": {
"name": "horse",
"version": "3.1.0",
"hash": "fc3b8eefb46c1a3b387e86ca46a9faa1",
"version": "3.1.4",
"hash": "54665bed032fc96d1398bf5df6332754",
"artifacts": {},
"failed": false,
"changed": false
Expand Down
2 changes: 1 addition & 1 deletion boss.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"projects": [],
"dependencies": {
"github.com/andre-djsystem/hashlib4pascal": "^1.0.0",
"github.com/hashload/horse": "^3.1.0",
"github.com/hashload/horse": "^3.1.4",
"github.com/paolo-rossi/delphi-jose-jwt": "^v3.2.0"
}
}
6 changes: 3 additions & 3 deletions samples/delphi/client/boss-lock.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"hash": "6ef9161b900632671022358216c7dfe7",
"updated": "2023-03-09T23:37:34.5596218-03:00",
"updated": "2023-08-07T09:25:32.3870207-03:00",
"installedModules": {
"github.com/hashload/horse": {
"name": "horse",
"version": "3.1.0",
"hash": "fc3b8eefb46c1a3b387e86ca46a9faa1",
"version": "3.1.4",
"hash": "54665bed032fc96d1398bf5df6332754",
"artifacts": {},
"failed": false,
"changed": false
Expand Down
2 changes: 1 addition & 1 deletion samples/delphi/client/boss.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"mainsrc": "./",
"projects": [],
"dependencies": {
"github.com/hashload/horse": "^3.1.0",
"github.com/hashload/horse": "^3.1.4",
"github.com/paolo-rossi/delphi-jose-jwt": "^v3.2.0"
}
}
70 changes: 68 additions & 2 deletions samples/delphi/client/samples_client.dproj

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions src/Horse.JWT.pas
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
unit Horse.JWT;

{$IF DEFINED(FPC)}
{$MODE DELPHI}{$H+}
{$MODE DELPHI}{$H+}
{$ENDIF}

interface
Expand Down Expand Up @@ -224,8 +224,20 @@ procedure Middleware(AHorseRequest: THorseRequest; AHorseResponse: THorseRespons
LBuilder.SetRequireSubject;
end;

LJWT := TJOSEContext.Create(LToken, TJWTClaims);
try
LJWT := TJOSEContext.Create(LToken, TJWTClaims);
except
AHorseResponse.Send(UNAUTHORIZED).Status(THTTPStatus.Unauthorized);
raise EHorseCallbackInterrupted.Create(UNAUTHORIZED);
end;

try
if LJWT.GetJOSEObject = nil then
begin
AHorseResponse.Send(UNAUTHORIZED).Status(THTTPStatus.Unauthorized);
raise EHorseCallbackInterrupted.Create(UNAUTHORIZED);
end;

LValidations := LBuilder.Build;
try
LValidations.ProcessContext(LJWT);
Expand Down

0 comments on commit 5309a67

Please sign in to comment.