From f16251533d5f421a332df0c557ea2b31cbcb06ad Mon Sep 17 00:00:00 2001 From: Vinicius Sanchez Date: Fri, 4 Feb 2022 11:14:27 -0300 Subject: [PATCH] Starting lazarus samples --- samples/{ => delphi}/auth/boss-lock.json | 12 +-- samples/{ => delphi}/auth/boss.json | 0 samples/{ => delphi}/auth/samples.dpr | 0 samples/{ => delphi}/auth/samples.dproj | 2 +- samples/{ => delphi}/client/boss-lock.json | 8 +- samples/{ => delphi}/client/boss.json | 0 samples/{ => delphi}/client/samples.dpr | 0 samples/{ => delphi}/client/samples.dproj | 120 +++++++++++++++++++-- samples/lazarus/client/Console.lpi | 64 +++++++++++ samples/lazarus/client/Console.lpr | 22 ++++ samples/lazarus/client/boss-lock.json | 22 ++++ samples/lazarus/client/boss.json | 12 +++ src/Horse.JWT.pas | 39 +++---- 13 files changed, 261 insertions(+), 40 deletions(-) rename samples/{ => delphi}/auth/boss-lock.json (70%) rename samples/{ => delphi}/auth/boss.json (100%) rename samples/{ => delphi}/auth/samples.dpr (100%) rename samples/{ => delphi}/auth/samples.dproj (99%) rename samples/{ => delphi}/client/boss-lock.json (72%) rename samples/{ => delphi}/client/boss.json (100%) rename samples/{ => delphi}/client/samples.dpr (100%) rename samples/{ => delphi}/client/samples.dproj (88%) create mode 100644 samples/lazarus/client/Console.lpi create mode 100644 samples/lazarus/client/Console.lpr create mode 100644 samples/lazarus/client/boss-lock.json create mode 100644 samples/lazarus/client/boss.json diff --git a/samples/auth/boss-lock.json b/samples/delphi/auth/boss-lock.json similarity index 70% rename from samples/auth/boss-lock.json rename to samples/delphi/auth/boss-lock.json index d0d30d0..881e32a 100644 --- a/samples/auth/boss-lock.json +++ b/samples/delphi/auth/boss-lock.json @@ -4,24 +4,24 @@ "installedModules": { "github.com/hashload/horse": { "name": "horse", - "version": "2.0.13", - "hash": "32daa5a81f115ecc285cbbbbdbcddcea", + "version": "v2.0.14", + "hash": "38c6bebdc7b9712d6e5856d299289a26", "artifacts": {}, "failed": false, "changed": false }, "github.com/hashload/jhonson": { "name": "jhonson", - "version": "1.1.1", - "hash": "5740da7df1068b882117a68df8098c9a", + "version": "1.1.3", + "hash": "711f200029b2fc3aef76ab410ac5833a", "artifacts": {}, "failed": false, "changed": false }, "github.com/paolo-rossi/delphi-jose-jwt": { "name": "delphi-jose-jwt", - "version": "v3.0.0", - "hash": "e07d23afdc06adef34b7fbbabd97ce83", + "version": "v3.0.3", + "hash": "d8b6ff80aff10e83d87219f45fa43ffb", "artifacts": {}, "failed": false, "changed": false diff --git a/samples/auth/boss.json b/samples/delphi/auth/boss.json similarity index 100% rename from samples/auth/boss.json rename to samples/delphi/auth/boss.json diff --git a/samples/auth/samples.dpr b/samples/delphi/auth/samples.dpr similarity index 100% rename from samples/auth/samples.dpr rename to samples/delphi/auth/samples.dpr diff --git a/samples/auth/samples.dproj b/samples/delphi/auth/samples.dproj similarity index 99% rename from samples/auth/samples.dproj rename to samples/delphi/auth/samples.dproj index 141b638..e7e6795 100644 --- a/samples/auth/samples.dproj +++ b/samples/delphi/auth/samples.dproj @@ -76,7 +76,7 @@ true $(BDS)\bin\delphi_PROJECTICON.ico $(BDS)\bin\delphi_PROJECTICNS.icns - $(Horse);$(DCC_UnitSearchPath);modules\.dcp;modules\.dcu;modules;modules\delphi-jose-jwt\Samples\Basic;modules\delphi-jose-jwt\Samples\Console;modules\delphi-jose-jwt\Samples\CryptoTest;modules\delphi-jose-jwt\Samples\CustomClaims;modules\delphi-jose-jwt\Source\Common;modules\delphi-jose-jwt\Source\JOSE;modules\delphi-jose-jwt\Tests\Source;modules\horse\src;modules\jhonson\src + $(Horse);$(DCC_UnitSearchPath);modules\.dcp;modules\.dcu;modules;modules\delphi-jose-jwt\Source\Common;modules\delphi-jose-jwt\Source\JOSE;modules\horse\src;modules\jhonson\src VCL;$(DCC_Framework) samples diff --git a/samples/client/boss-lock.json b/samples/delphi/client/boss-lock.json similarity index 72% rename from samples/client/boss-lock.json rename to samples/delphi/client/boss-lock.json index 36caa8b..7468831 100644 --- a/samples/client/boss-lock.json +++ b/samples/delphi/client/boss-lock.json @@ -4,16 +4,16 @@ "installedModules": { "github.com/hashload/horse": { "name": "horse", - "version": "2.0.13", - "hash": "32daa5a81f115ecc285cbbbbdbcddcea", + "version": "v2.0.14", + "hash": "38c6bebdc7b9712d6e5856d299289a26", "artifacts": {}, "failed": false, "changed": false }, "github.com/paolo-rossi/delphi-jose-jwt": { "name": "delphi-jose-jwt", - "version": "v3.0.0", - "hash": "e07d23afdc06adef34b7fbbabd97ce83", + "version": "v3.0.3", + "hash": "d8b6ff80aff10e83d87219f45fa43ffb", "artifacts": {}, "failed": false, "changed": false diff --git a/samples/client/boss.json b/samples/delphi/client/boss.json similarity index 100% rename from samples/client/boss.json rename to samples/delphi/client/boss.json diff --git a/samples/client/samples.dpr b/samples/delphi/client/samples.dpr similarity index 100% rename from samples/client/samples.dpr rename to samples/delphi/client/samples.dpr diff --git a/samples/client/samples.dproj b/samples/delphi/client/samples.dproj similarity index 88% rename from samples/client/samples.dproj rename to samples/delphi/client/samples.dproj index 2ba9706..add789d 100644 --- a/samples/client/samples.dproj +++ b/samples/delphi/client/samples.dproj @@ -71,7 +71,7 @@ true $(BDS)\bin\delphi_PROJECTICON.ico $(BDS)\bin\delphi_PROJECTICNS.icns - $(Horse);$(DCC_UnitSearchPath);modules\.dcp;modules\.dcu;modules;modules\delphi-jose-jwt\Samples\Basic;modules\delphi-jose-jwt\Samples\Console;modules\delphi-jose-jwt\Samples\CryptoTest;modules\delphi-jose-jwt\Samples\CustomClaims;modules\delphi-jose-jwt\Source\Common;modules\delphi-jose-jwt\Source\JOSE;modules\delphi-jose-jwt\Tests\Source;modules\horse\src + $(Horse);modules\.dcp;modules\.dcu;modules;modules\delphi-jose-jwt\Source\Common;modules\delphi-jose-jwt\Source\JOSE;modules\horse\src;$(DCC_UnitSearchPath) VCL;$(DCC_Framework) samples @@ -108,7 +108,7 @@ false - ..\..\src;$(DCC_UnitSearchPath) + ..\..\..\src;$(DCC_UnitSearchPath) 1033 (None) @@ -142,11 +142,7 @@ samples.dpr - - Embarcadero DBExpress DataSnap Native Server Components - Microsoft Office 2000 Sample Automation Server Wrapper Components - Microsoft Office XP Sample Automation Server Wrapper Components - + @@ -183,12 +179,20 @@ classes 1 + + classes + 1 + res\xml 1 + + res\xml + 1 + @@ -201,6 +205,10 @@ library\lib\armeabi 1 + + library\lib\armeabi + 1 + @@ -213,12 +221,20 @@ library\lib\mips 1 + + library\lib\mips + 1 + library\lib\armeabi-v7a 1 + + library\lib\arm64-v8a + 1 + @@ -231,120 +247,200 @@ res\drawable 1 + + res\drawable + 1 + res\values 1 + + res\values + 1 + res\values-v21 1 + + res\values-v21 + 1 + res\values 1 + + res\values + 1 + res\drawable 1 + + res\drawable + 1 + res\drawable-xxhdpi 1 + + res\drawable-xxhdpi + 1 + res\drawable-ldpi 1 + + res\drawable-ldpi + 1 + res\drawable-mdpi 1 + + res\drawable-mdpi + 1 + res\drawable-hdpi 1 + + res\drawable-hdpi + 1 + res\drawable-xhdpi 1 + + res\drawable-xhdpi + 1 + res\drawable-mdpi 1 + + res\drawable-mdpi + 1 + res\drawable-hdpi 1 + + res\drawable-hdpi + 1 + res\drawable-xhdpi 1 + + res\drawable-xhdpi + 1 + res\drawable-xxhdpi 1 + + res\drawable-xxhdpi + 1 + res\drawable-xxxhdpi 1 + + res\drawable-xxxhdpi + 1 + res\drawable-small 1 + + res\drawable-small + 1 + res\drawable-normal 1 + + res\drawable-normal + 1 + res\drawable-large 1 + + res\drawable-large + 1 + res\drawable-xlarge 1 + + res\drawable-xlarge + 1 + res\values 1 + + res\values + 1 + @@ -414,6 +510,9 @@ 0 + + 0 + 0 @@ -701,6 +800,9 @@ 1 + + 1 + @@ -744,6 +846,10 @@ library\lib\armeabi-v7a 1 + + library\lib\arm64-v8a + 1 + 1 diff --git a/samples/lazarus/client/Console.lpi b/samples/lazarus/client/Console.lpi new file mode 100644 index 0000000..03d57a3 --- /dev/null +++ b/samples/lazarus/client/Console.lpi @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + <UseAppBundle Value="False"/> + <ResourceType Value="res"/> + </General> + <BuildModes Count="1"> + <Item1 Name="Default" Default="True"/> + </BuildModes> + <PublishOptions> + <Version Value="2"/> + <UseFileFilters Value="True"/> + </PublishOptions> + <RunParams> + <FormatVersion Value="2"/> + <Modes Count="0"/> + </RunParams> + <Units Count="1"> + <Unit0> + <Filename Value="Console.lpr"/> + <IsPartOfProject Value="True"/> + </Unit0> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="11"/> + <PathDelim Value="\"/> + <Target> + <Filename Value="Console"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <OtherUnitFiles Value="..\..\..\src;modules\.dcp;modules\.dcu;modules;modules\horse\src;modules\hashlib4pascal\HashLib\src\Base;modules\hashlib4pascal\HashLib\src\Crypto\Blake2BParams;modules\hashlib4pascal\HashLib\src\Crypto\Blake2SParams;modules\hashlib4pascal\HashLib\src\Interfaces\IBlake2BParams;modules\hashlib4pascal\HashLib\src\Interfaces\IBlake2SParams;modules\hashlib4pascal\HashLib\src\Checksum;modules\hashlib4pascal\HashLib\src\Crypto;modules\hashlib4pascal\HashLib\src\Hash32;modules\hashlib4pascal\HashLib\src\Hash64;modules\hashlib4pascal\HashLib\src\Hash128;modules\hashlib4pascal\HashLib\src\Include;modules\hashlib4pascal\HashLib\src\Interfaces;modules\hashlib4pascal\HashLib\src\KDF;modules\hashlib4pascal\HashLib\src\Nullable;modules\hashlib4pascal\HashLib\src\NullDigest;modules\hashlib4pascal\HashLib\src\Utils"/> + <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <Other> + <CustomOptions Value="-dUseCThreads"/> + </Other> + </CompilerOptions> + <Debugging> + <Exceptions Count="3"> + <Item1> + <Name Value="EAbort"/> + </Item1> + <Item2> + <Name Value="ECodetoolError"/> + </Item2> + <Item3> + <Name Value="EFOpenError"/> + </Item3> + </Exceptions> + </Debugging> +</CONFIG> diff --git a/samples/lazarus/client/Console.lpr b/samples/lazarus/client/Console.lpr new file mode 100644 index 0000000..c40be34 --- /dev/null +++ b/samples/lazarus/client/Console.lpr @@ -0,0 +1,22 @@ +program Console; + +{$MODE DELPHI}{$H+} + +uses + {$IFDEF UNIX}{$IFDEF UseCThreads} + cthreads, + {$ENDIF}{$ENDIF} + Horse, Horse.JWT, SysUtils; + +procedure GetPing(Req: THorseRequest; Res: THorseResponse; Next: TNextProc); +begin + Res.Send('Pong'); +end; + +begin + THorse.Use(HorseJWT('my-private-key')); + + THorse.Get('/ping', GetPing); + + THorse.Listen(9000); +end. diff --git a/samples/lazarus/client/boss-lock.json b/samples/lazarus/client/boss-lock.json new file mode 100644 index 0000000..408f1ac --- /dev/null +++ b/samples/lazarus/client/boss-lock.json @@ -0,0 +1,22 @@ +{ + "hash": "d41d8cd98f00b204e9800998ecf8427e", + "updated": "2022-02-04T10:51:11.8350763-03:00", + "installedModules": { + "github.com/andre-djsystem/hashlib4pascal": { + "name": "hashlib4pascal", + "version": "1.0.0", + "hash": "8528036224699ab509c7d8f31d691ffb", + "artifacts": {}, + "failed": false, + "changed": false + }, + "github.com/hashload/horse": { + "name": "horse", + "version": "v2.0.14", + "hash": "38c6bebdc7b9712d6e5856d299289a26", + "artifacts": {}, + "failed": false, + "changed": false + } + } +} \ No newline at end of file diff --git a/samples/lazarus/client/boss.json b/samples/lazarus/client/boss.json new file mode 100644 index 0000000..277e544 --- /dev/null +++ b/samples/lazarus/client/boss.json @@ -0,0 +1,12 @@ +{ + "name": "client", + "description": "", + "version": "1.0.0", + "homepage": "", + "mainsrc": "./src", + "projects": [], + "dependencies": { + "github.com/andre-djsystem/hashlib4pascal": "^1.0.0", + "github.com/hashload/horse": "^v2.0.14" + } +} \ No newline at end of file diff --git a/src/Horse.JWT.pas b/src/Horse.JWT.pas index 23f455f..c01e4d2 100644 --- a/src/Horse.JWT.pas +++ b/src/Horse.JWT.pas @@ -9,9 +9,7 @@ interface uses {$IF DEFINED(FPC)} Generics.Collections, Classes, fpjson, SysUtils, HTTPDefs, fpjwt, Base64, DateUtils, - HlpIHashInfo, - HlpConverters, - HlpHashFactory, + HlpIHashInfo, HlpConverters, HlpHashFactory, {$ELSE} System.Generics.Collections, System.Classes, System.JSON, System.SysUtils, Web.HTTPApp, REST.JSON, JOSE.Core.JWT, JOSE.Core.JWK, JOSE.Core.Builder, JOSE.Consumer.Validators, JOSE.Consumer, JOSE.Context, @@ -68,8 +66,7 @@ implementation SessionClass: TClass; Header: string; -function HorseJWT(ASecretJWT: string; ASessionClass: TClass; - AConfig: THorseJWTConfig; AHeader: string): THorseCallback; +function HorseJWT(ASecretJWT: string; ASessionClass: TClass; AConfig: THorseJWTConfig; AHeader: string): THorseCallback; begin SecretJWT := ASecretJWT; SessionClass := ASessionClass; @@ -78,8 +75,7 @@ function HorseJWT(ASecretJWT: string; ASessionClass: TClass; Result := {$IF DEFINED(FPC)}@Middleware{$ELSE}Middleware{$ENDIF}; end; -function HorseJWT(ASecretJWT: string; ASessionClass: TClass; AHeader: string - ): THorseCallback; +function HorseJWT(ASecretJWT: string; ASessionClass: TClass; AHeader: string): THorseCallback; begin SecretJWT := ASecretJWT; SessionClass := ASessionClass; @@ -87,8 +83,7 @@ function HorseJWT(ASecretJWT: string; ASessionClass: TClass; AHeader: string Result := {$IF DEFINED(FPC)}@Middleware{$ELSE}Middleware{$ENDIF}; end; -function HorseJWT(ASecretJWT: string; AConfig: THorseJWTConfig; AHeader: string - ): THorseCallback; +function HorseJWT(ASecretJWT: string; AConfig: THorseJWTConfig; AHeader: string): THorseCallback; begin SecretJWT := ASecretJWT; Config := AConfig; @@ -117,24 +112,24 @@ procedure Middleware(AHorseRequest: THorseRequest; LSession: TObject; LJSON: TJSONObject; {$IF DEFINED(FPC)} - function HexToAscii(const HexStr : String) : AnsiString ; //ACBrUtil + function HexToAscii(const HexStr: string): AnsiString; Var - B : Byte ; - Cmd : String ; - I, L: Integer ; + B: Byte; + Cmd: string; + I, L: Integer; begin - Result := '' ; - Cmd := Trim(HexStr); - I := 1 ; - L := Length(Cmd) ; + Result := ''; + Cmd := Trim(HexStr); + I := 1; + L := Length(Cmd); while I < L do begin - B := StrToInt('$' + copy(Cmd, I, 2)) ; - Result := Result + AnsiChar(chr(B)) ; - Inc( I, 2) ; - end ; - end ; + B := StrToInt('$' + copy(Cmd, I, 2)); + Result := Result + AnsiChar(chr(B)); + Inc( I, 2); + end; + end; function ValidateSignature: Boolean; var