Skip to content

Commit 9181c98

Browse files
author
CarlosHe
committed
Realm ask message for navigators
1 parent 5755a3b commit 9181c98

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

boss.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"mainsrc": "/src",
77
"projects": [],
88
"dependencies": {
9-
"github.com/hashload/horse": "^v1.6.6"
9+
"github.com/hashload/horse": "^v2.0.0"
1010
}
1111
}

src/Horse.BasicAuthentication.pas

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ interface
2020
THorseBasicAuthentication = {$IF NOT DEFINED(FPC)} reference to {$ENDIF} function(const AUsername, APassword: string): Boolean;
2121

2222
procedure Middleware(Req: THorseRequest; Res: THorseResponse; Next: {$IF DEFINED(FPC)} TNextProc {$ELSE} TProc {$ENDIF} );
23-
function HorseBasicAuthentication(const AAuthenticate: THorseBasicAuthentication; const AHeader: string = AUTHORIZATION): THorseCallback;
23+
function HorseBasicAuthentication(const AAuthenticate: THorseBasicAuthentication; const AHeader: string = AUTHORIZATION; const ARealmMessage: string = 'Enter credentials'): THorseCallback;
2424

2525
implementation
2626

2727
var
2828
Header: string;
29+
RealmMessage: string;
2930
Authenticate: THorseBasicAuthentication;
3031

31-
function HorseBasicAuthentication(const AAuthenticate: THorseBasicAuthentication; const AHeader: string = AUTHORIZATION): THorseCallback;
32+
function HorseBasicAuthentication(const AAuthenticate: THorseBasicAuthentication; const AHeader: string = AUTHORIZATION; const ARealmMessage: string = 'Enter credentials'): THorseCallback;
3233
begin
3334
Header := AHeader;
35+
RealmMessage := ARealmMessage;
3436
Authenticate := AAuthenticate;
3537
Result := Middleware;
3638
end;
@@ -47,7 +49,7 @@ procedure Middleware(Req: THorseRequest; Res: THorseResponse; Next: {$IF DEFINED
4749
LBasicAuthenticationEncode := Req.Headers[Header];
4850
if LBasicAuthenticationEncode.Trim.IsEmpty and not Req.Query.TryGetValue(Header, LBasicAuthenticationEncode) then
4951
begin
50-
Res.Send('Authorization not found').Status(THTTPStatus.Unauthorized);
52+
Res.Send('Authorization not found').Status(THTTPStatus.Unauthorized).RawWebResponse.Realm := RealmMessage;;
5153
raise EHorseCallbackInterrupted.Create;
5254
end;
5355
if not LBasicAuthenticationEncode.ToLower.StartsWith(BASIC_AUTH) then

0 commit comments

Comments
 (0)