|
1 | 1 | # 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> |
2 | 7 |
|
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 | +``` |
4 | 17 |
|
5 | | -Sample Horse server validate basic authentication: |
| 18 | +## ✔️ Compatibility |
| 19 | +This middleware is compatible with projects developed in: |
| 20 | +- [X] Delphi |
| 21 | +- [X] Lazarus |
6 | 22 |
|
| 23 | +## ⚡️ Quickstart |
7 | 24 | ```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; |
9 | 29 |
|
10 | 30 | begin |
| 31 | + // It's necessary to add the middleware in the Horse: |
11 | 32 | THorse.Use(HorseBasicAuthentication( |
12 | 33 | function(const AUsername, APassword: string): Boolean |
13 | 34 | begin |
| 35 | + // Here inside you can access your database and validate if username and password are valid |
14 | 36 | Result := AUsername.Equals('user') and APassword.Equals('password'); |
15 | 37 | 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')); |
16 | 42 |
|
17 | 43 | THorse.Get('/ping', |
18 | 44 | procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc) |
|
21 | 47 | end); |
22 | 48 |
|
23 | 49 | THorse.Listen(9000); |
24 | | -end. |
| 50 | +end; |
25 | 51 | ``` |
| 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