Skip to content

Commit

Permalink
Added a new
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciussanchez committed May 3, 2022
1 parent d3f4479 commit 2a45065
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
6 changes: 3 additions & 3 deletions boss-lock.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"hash": "8a53e9cf872feaac975a8fad2c6a5af0",
"updated": "2022-02-16T08:58:42.6439434-03:00",
"updated": "2021-10-04T08:54:27.0678585-03:00",
"installedModules": {
"github.com/hashload/horse": {
"name": "horse",
"version": "3.0.0",
"hash": "195e14c9c225f81a8c69d18b5118c149",
"version": "3.0.1",
"hash": "4533d4457de32678b73d0f990ded34c8",
"artifacts": {},
"failed": false,
"changed": false
Expand Down
15 changes: 11 additions & 4 deletions src/Horse.BasicAuthentication.pas
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
unit Horse.BasicAuthentication;

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

interface
Expand All @@ -26,6 +26,7 @@ interface
function RealmMessage(const AValue: string): IHorseBasicAuthenticationConfig; overload;
function RealmMessage: string; overload;
function SkipRoutes(const AValues: TArray<string>): IHorseBasicAuthenticationConfig; overload;
function SkipRoutes(const AValue: string): IHorseBasicAuthenticationConfig; overload;
function SkipRoutes: TArray<string>; overload;
end;

Expand All @@ -39,6 +40,7 @@ THorseBasicAuthenticationConfig = class(TInterfacedObject, IHorseBasicAuthenti
function RealmMessage(const AValue: string): IHorseBasicAuthenticationConfig; overload;
function RealmMessage: string; overload;
function SkipRoutes(const AValues: TArray<string>): IHorseBasicAuthenticationConfig; overload;
function SkipRoutes(const AValue: string): IHorseBasicAuthenticationConfig; overload;
function SkipRoutes: TArray<string>; overload;
public
constructor Create;
Expand Down Expand Up @@ -94,11 +96,11 @@ procedure Middleware(Req: THorseRequest; Res: THorseResponse; Next: {$IF DEFINED
if LBasicAuthenticationEncode.Trim.IsEmpty and not Req.Query.TryGetValue(Config.Header, LBasicAuthenticationEncode) then
begin
Res.Send('Authorization not found').Status(THTTPStatus.Unauthorized).RawWebResponse
{$IF DEFINED(FPC)}
{$IF DEFINED(FPC)}
.WWWAuthenticate := Format('Basic realm=%s', [Config.RealmMessage]);
{$ELSE}
{$ELSE}
.Realm := Config.RealmMessage;
{$ENDIF}
{$ENDIF}

raise EHorseCallbackInterrupted.Create;
end;
Expand Down Expand Up @@ -174,6 +176,11 @@ function THorseBasicAuthenticationConfig.RealmMessage: string;
Result := FRealmMessage;
end;

function THorseBasicAuthenticationConfig.SkipRoutes(const AValue: string): IHorseBasicAuthenticationConfig;
begin
Result := SkipRoutes([AValue]);
end;

function THorseBasicAuthenticationConfig.SkipRoutes(const AValues: TArray<string>): IHorseBasicAuthenticationConfig;
var
I: Integer;
Expand Down

0 comments on commit 2a45065

Please sign in to comment.