Middleware HTTP Basic Authentication para Horse. Cobre HorseBasicAuthentication (callback de validação, configuração THorseBasicAuthenticationConfig), Header, RealmMessage, SkipRoutes e proteção por rota. Fonte: app/package/docs/pacotes/horse-basic-auth.md.
Scanned 9/12/2026
Install to Claude Code
npx -y skills add aibot88/sec_skill_store --skill developer-delphi-horse-basic-auth-v1-0-0 --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Developer Delphi Horse Basic Auth V1 0 0?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/aibot88-developer-delphi-horse-basic-auth-v1-0-0)More formats (shields.io, HTML) on the badges page.
---
name: developer-delphi-horse-basic-auth
description: Middleware HTTP Basic Authentication para Horse. Cobre HorseBasicAuthentication (callback de validação, configuração THorseBasicAuthenticationConfig), Header, RealmMessage, SkipRoutes e proteção por rota. Fonte: app/package/docs/pacotes/horse-basic-auth.md.
model: sonnet
thinking: minimal
category: project
---
# developer-delphi-horse-basic-auth
## Versão interna (ficheiro)
| Campo | Valor |
| --- | --- |
| **FileVersion** | 1.0.0 |
| **Política** | `.cursor/VERSION.md` |
## Responsabilidade única
Middleware de autenticação HTTP Basic (cabeçalho `Authorization: Basic ...`) para Horse.
## When to use
- Validar username/password via cabeçalho Basic Auth
- Proteger rotas com autenticação simples
- Integração servidor-a-servidor (Basic Auth para APIs internas)
## When NOT to use
- Autenticação JWT Bearer → `developer-delphi-horse-jwt`
- Geração/validação de tokens JWT → `developer-delphi-horse-security`
## Documento canônico
`app/package/docs/pacotes/horse-basic-auth.md`
---
## HorseBasicAuthentication — sobrecargas
| Sobrecarga | Descrição |
| --- | --- |
| `HorseBasicAuthentication(callback)` | Middleware com validação custom |
| `HorseBasicAuthentication(callback, config)` | Com configuração avançada |
### IHorseBasicAuthenticationConfig — configuração
| Método | Descrição |
| --- | --- |
| `New` | Cria instância |
| `Header(value)` | Cabeçalho da credencial (padrão: `Authorization`) |
| `RealmMessage(value)` | Mensagem do realm no challenge 401 |
| `SkipRoutes([...])` | Rotas que ignoram autenticação |
---
## Exemplos
### Global — todas as rotas
```delphi
uses Horse, Horse.BasicAuthentication;
begin
THorse.Use(HorseBasicAuthentication(
function(const AUsername, APassword: string): Boolean
begin
Result := AUsername.Equals('user') and APassword.Equals('password');
end));
THorse.Get('/ping',
procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc)
begin
Res.Send('pong');
end);
THorse.Listen(9000);
end.
```
### Com configuração completa
```delphi
THorse.Use(HorseBasicAuthentication(
ValidarCredenciais,
THorseBasicAuthenticationConfig.New
.Header('Authorization')
.RealmMessage('GestorERP API')
.SkipRoutes(['/health', '/swagger/doc/html', '/auth/refresh'])
));
```
### Validação contra base de dados
```delphi
function ValidarCredenciais(const AUsername, APassword: string): Boolean;
var LQuery: TFDQuery;
begin
Result := False;
LQuery := TFDQuery.Create(nil);
try
LQuery.Connection := DM.Conexao;
LQuery.SQL.Text :=
'SELECT 1 FROM usuarios WHERE login = :u AND senha_hash = :p AND ativo = 1';
LQuery.ParamByName('u').AsString := AUsername;
LQuery.ParamByName('p').AsString := HashSenha(APassword);
LQuery.Open;
Result := not LQuery.IsEmpty;
finally
LQuery.Free;
end;
end;
```
### Proteção por rota (AddCallback)
```delphi
// Rota pública
THorse.Get('/health',
procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc)
begin
Res.Send('ok');
end);
// Rotas privadas com Basic Auth
THorse
.AddCallback(HorseBasicAuthentication(ValidarCredenciais))
.Get('/admin/report', ProcRelatorio);
```
### Lazarus / FPC
```delphi
{$MODE DELPHI}{$H+}
uses Horse, Horse.BasicAuthentication, SysUtils;
function DoLogin(const AUsername, APassword: string): Boolean;
begin
Result := AUsername.Equals('user') and APassword.Equals('password');
end;
begin
THorse.Use(HorseBasicAuthentication(DoLogin));
THorse.Get('/ping', GetPing);
THorse.Listen(9000);
end.
```
---
## Notas GestorERP
- Basic Auth apenas em canais **HTTPS** — nunca em HTTP puro
- Hashear passwords com BCrypt ou SHA-256+salt (nunca plaintext)
- Preferir JWT para sessões longas; Basic Auth para integrações servidor-a-servidor
- `unit` a usar: `Horse.BasicAuthentication`
---
## Changelog (este arquivo)
- 1.0.0 (12/04/2026): Criação — skill middleware Basic Auth.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!