Synaptic SkillsSynapticSkills
MarketplaceSkill GraphCriar SkillMCP ServerPlataformaEnterprise
v0.1.0-beta
Voltar ao Marketplace
SecurityMédioAuto-Sync

Authenticate Service

porTHIAGONOMA·THIAGONOMA· v1.6.0 · atualizado em 2026-04-12T22:48:14.110Z
85
Score

Valida tokens JWT, verifica permissões RBAC/ABAC e gerencia sessões com blacklist para logout seguro. Integra com NextAuth, Auth0 e Keycloak via middleware reutilizável em microservices.

authenticationjwtrbacmiddlewaresessionmicroserviceskeycloak
Linguagens
TypeScriptJavaScriptPython
1.8KStars
112Forks
45.0KUsos
Fork

Documento do Skill

SKILL.mdauthenticate-service/workflow
Passo-a-passo detalhado do skill, referenciando as fases cognitivas:
1
SENSE — Identificar mecanismo de auth
```typescript
// Identificar algoritmo e provedor
import jwt from 'jsonwebtoken';
const decoded = jwt.decode(token, { complete: true });
console.log(decoded?.header.alg); // RS256 ou HS256
```
2
RECOMMEND — Middleware Next.js completo
```typescript
// middleware.ts
import { NextRequest, NextResponse } from 'next/server';
import { jwtVerify, importSPKI } from 'jose';
import { redis } from './lib/redis';
const PUBLIC_PATHS = ['/api/auth', '/api/health', '/login'];
export async function middleware(req: NextRequest) {
if (PUBLIC_PATHS.some(p => req.nextUrl.pathname.startsWith(p))) {
return NextResponse.next();
}
const token = req.headers.get('Authorization')?.replace('Bearer ', '');
if (!token) {
return NextResponse.json({ error: 'Authentication required' }, { status: 401 });
}
try {
const publicKey = await importSPKI(process.env.JWT_PUBLIC_KEY!, 'RS256');
const { payload } = await jwtVerify(token, publicKey, {
issuer: process.env.JWT_ISSUER,
audience: process.env.JWT_AUDIENCE,
});
// Verificar blacklist (logout)
if (payload.jti) {
const isRevoked = await redis.get(`blacklist:${payload.jti}`);
if (isRevoked) {
return NextResponse.json({ error: 'Token revoked' }, { status: 401 });
}
}
// Injetar user no header para rotas downstream
const headers = new Headers(req.headers);
headers.set('x-user-id', payload.sub!);
headers.set('x-user-role', String(payload.role ?? 'user'));
return NextResponse.next({ request: { headers } });
} catch (e) {
return NextResponse.json({ error: 'Invalid or expired token' }, { status: 401 });
}
}
```
3
RECOMMEND — RBAC helper
```typescript
// lib/auth/withRoles.ts
export function withRoles(roles: string[]) {
return function(handler: Function) {
return async (req: Request) => {
const role = req.headers.get('x-user-role');
if (!role || !roles.includes(role)) {
return Response.json({ error: 'Insufficient permissions' }, { status: 403 });
}
return handler(req);
};
};
}
// Uso: export const POST = withRoles(['admin'])(createSkill);
```
4
RECOMMEND — Logout com blacklist Redis
```typescript
async function revokeToken(token: string) {
const { payload } = await jwtVerify(token, publicKey);
if (payload.jti && payload.exp) {
const ttl = payload.exp - Math.floor(Date.now() / 1000);
if (ttl > 0) {
await redis.setex(`blacklist:${payload.jti}`, ttl, '1');
}
}
}
```
5
EVALUATE — Testes de segurança
```typescript
it('rejects algorithm: none attack', async () => {
const noneToken = createTokenWithAlgNone({ sub: 'user-1', role: 'admin' });
const res = await api.get('/api/protected').set('Authorization', `Bearer ${noneToken}`);
expect(res.status).toBe(401);
});
it('returns 403 (not 401) for insufficient role', async () => {
const token = createToken({ sub: 'user-1', role: 'viewer' });
const res = await api.delete('/api/admin/users/1').set('Authorization', `Bearer ${token}`);
expect(res.status).toBe(403); // authenticated but not authorized
});
```
6
REFLECT — Documentar e validar
Testar que `alg: none` é rejeitado (jwtVerify do jose já rejeita)
Confirmar que logs não expõem o token completo — apenas sub e jti
Reportar telemetria via mcp-skillschain

Telemetria de Agentes

Execuções
0
total
Taxa de Sucesso
0%
últimos 30d
Latência Média
0.0s
p50
Alucinação
0.0%
detecção
Tokens Entrada
0
avg 0/exec
Tokens Saída
0
avg 0/exec

Uso por Plataforma

Skills Relacionados

Depende de ←Send Email
24%
Hebbian Synapse
Composite0.240
w = 0.3·α + 0.5·β + 0.2·γ
87
Depende de ←Slack Notifier
24%
Hebbian Synapse
Composite0.240
w = 0.3·α + 0.5·β + 0.2·γ
82
Depende de ←REST API Builder
24%
Hebbian Synapse
Composite0.240
w = 0.3·α + 0.5·β + 0.2·γ
90
Depende de ←Webhook Manager
24%
Hebbian Synapse
Composite0.240
w = 0.3·α + 0.5·β + 0.2·γ
83
Similar a ←Auth Flow Builder
15%
Hebbian Synapse
Composite0.150
w = 0.3·α + 0.5·β + 0.2·γ
88
Similar a ←azure-role-selector
60%
Hebbian Synapse
Composite0.600
w = 0.3·α + 0.5·β + 0.2·γ
83
Similar a ←SKILL: Creating Agent Users in Microsoft Entra Agent ID
60%
Hebbian Synapse
Composite0.600
w = 0.3·α + 0.5·β + 0.2·γ
78
Co-executedSecurity Scanner
40%
Hebbian Synapse
Composite0.400
w = 0.3·α + 0.5·β + 0.2·γ
89
Co-executedToken Counter
26%
Hebbian Synapse
Composite0.262
w = 0.3·α + 0.5·β + 0.2·γ
84
Co-executedWebhook Manager
12%
Hebbian Synapse
Composite0.115
w = 0.3·α + 0.5·β + 0.2·γ
83
Co-executedPen Test Assistant
40%
Hebbian Synapse
Composite0.400
w = 0.3·α + 0.5·β + 0.2·γ
83
Co-executed ←Auth Flow Builder
40%
Hebbian Synapse
Composite0.400
w = 0.3·α + 0.5·β + 0.2·γ
88

Árvore do Skill

Authenticate Service
authenticate-service
Fases Cognitivas6
1.SENSE: Percepção
2.CONTEXTUALIZE: Contextualização
3.HYPOTHESIZE: Hipótese
4.RECOMMEND: Recomendação
5.EVALUATE: Avaliação
6.REFLECT: Reflexão
Triggers15
validate tokenverificar tokenauthenticate requestautenticar requisiçãojwt middlewarerbac validationcheck permissionsverify JWTtoken validationauth middlewaresession validationblacklist tokenrevoke tokenmicroservice authapi authentication

Avaliar este Skill

Score Breakdown

⭐Avaliação Humana0%
🤖Sucesso de Agentes0%
🕐Atualidade100%
🔗Saúde de Dependências100%
🕸️Centralidade no Grafo0%
🛡️Segurança50%
CompositeScore = α·Humano + β·Agente + γ·Recência + δ·Deps + ε·Centralidade + ζ·Segurança

Instalação

$ synaptic mcp download authenticate-service
$ synaptic skills detail authenticate-service
$ synaptic skills live authenticate-service

Links

GitHub Repository