Agent identity
Agent and service identity is optional and disabled in generated projects by default. It uses a distinct token class, exact scopes, actor chains, Redis-backed sessions, and fail-closed registry checks.
const auth = await createAuthenik8({
jwt,
refreshSecret,
redis,
agent: {
resolveAgent: async (agentId) => agentRepository.findActive(agentId),
authorizeDelegation: async ({user, agent, requestedScopes}) =>
user.role === 'admin' &&
agent.agentId === 'build-worker' &&
requestedScopes.every((scope) => scope === 'tasks:read'),
},
});
Machine tokens
Authenticate the workload first through mTLS, cloud workload identity, a signed client assertion, or another trusted exchange. Only then call the privileged SDK primitive:
const machine = await auth.agent!.issueToken({
agentId: 'build-worker',
scopes: ['tasks:read'],
label: 'production queue worker',
});
Never expose issueToken() as an unauthenticated public endpoint.
Protect machine routes with the agent middleware:
app.post(
'/internal/tasks',
auth.agent!.requireScopes('tasks:write'),
handler,
);
Delegation
Delegated tokens require an active human access session and a positive authorizeDelegation decision:
const delegated = await auth.agent!.issueDelegatedToken({
agentId: 'build-worker',
userAccessToken,
scopes: ['tasks:read'],
});
The token identifies both the human subject and agent actor. Revoking the human session invalidates the delegation. Removing an agent or scope from the registry invalidates existing agent tokens during session-aware verification.
await auth.agent!.revokeSession(agentId, sessionId);
await auth.agent!.revokeAgent(agentId);