Auth & Tokens
Create the async core instance, then issue or verify access and refresh tokens.
API: createAuthenik8, issueTokens, verifyToken
auth.ts
import { createAuthenik8 } from "authenik8-core";
const auth = await createAuthenik8({
jwtSecret: process.env.JWT_SECRET!,
refreshSecret: process.env.REFRESH_SECRET!,
});
const tokens = await auth.issueTokens({
userId: "user_1",
email: "dev@example.com",
});
Direct usage example
The same factory used by generated applications can be used directly:
server.ts
import express from "express";
import { createAuthenik8 } from "authenik8-core";
const app = express();
const auth = await createAuthenik8({
jwtSecret: process.env.JWT_SECRET!,
refreshSecret: process.env.REFRESH_SECRET!,
});
app.use(express.json({ limit: "16kb", strict: true }));
app.use(auth.helmet);
app.use(auth.rateLimit);
app.post("/tokens", async (req, res) => {
const tokens = await auth.issueTokens({
userId: req.body.userId,
email: req.body.email,
});
res.json(tokens);
});
app.post("/refresh", async (req, res) => {
res.json(await auth.refreshToken(req.body.refreshToken));
});
app.listen(3000);