Skip to content

Commit 600d6a5

Browse files
Update README.md
1 parent 6b56dc2 commit 600d6a5

1 file changed

Lines changed: 38 additions & 4 deletions

File tree

README.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,44 @@
11
# horse-basic-auth
2+
<b>horse-basic-auth</b> is a official middleware for working with basic authentication in APIs developed with the <a href="https://github.com/HashLoad/horse">Horse</a> framework.
3+
<br>We created a channel on Telegram for questions and support:<br><br>
4+
<a href="https://t.me/hashload">
5+
<img src="https://img.shields.io/badge/telegram-join%20channel-7289DA?style=flat-square">
6+
</a>
27

3-
Middleware for Basic Authentication in HORSE
8+
## ⚙️ Installation
9+
Installation is done using the [`boss install`](https://github.com/HashLoad/boss) command:
10+
``` sh
11+
$ boss install horse-basic-auth
12+
```
13+
If you choose to install manually, simply add the following folders to your project, in *Project > Options > Resource Compiler > Directories and Conditionals > Include file search path*
14+
```
15+
../horse-basic-auth/src
16+
```
417

5-
Sample Horse server validate basic authentication:
18+
## ✔️ Compatibility
19+
This middleware is compatible with projects developed in:
20+
- [X] Delphi
21+
- [X] Lazarus
622

23+
## ⚡️ Quickstart
724
```delphi
8-
uses Horse, Horse.BasicAuthentication, System.SysUtils;
25+
uses
26+
Horse,
27+
Horse.BasicAuthentication, // It's necessary to use the unit
28+
System.SysUtils;
929
1030
begin
31+
// It's necessary to add the middleware in the Horse:
1132
THorse.Use(HorseBasicAuthentication(
1233
function(const AUsername, APassword: string): Boolean
1334
begin
35+
// Here inside you can access your database and validate if username and password are valid
1436
Result := AUsername.Equals('user') and APassword.Equals('password');
1537
end));
38+
39+
// The default header for receiving credentials is "Authorization".
40+
// You can change, if necessary:
41+
// THorse.Use(HorseBasicAuthentication(MyCallbackValidation, 'X-My-Header-Authorization'));
1642
1743
THorse.Get('/ping',
1844
procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc)
@@ -21,5 +47,13 @@ begin
2147
end);
2248
2349
THorse.Listen(9000);
24-
end.
50+
end;
2551
```
52+
53+
## 📌 Status Code
54+
This middleware can return the following status code:
55+
* [401](https://httpstatuses.com/401) - Unauthorized
56+
* [500](https://httpstatuses.com/500) - InternalServerError
57+
58+
## ⚠️ License
59+
`horse-basic-auth` is free and open-source middleware licensed under the [MIT License](https://github.com/HashLoad/horse-basic-auth/blob/master/LICENSE).

0 commit comments

Comments
 (0)