@forgeframework/auth
v0.3.0
Published
Provides authentication strategies for the Forge Framework.
Maintainers
Readme
@forgeframework/auth
Provides authentication strategies for the Forge Framework.
Part of the Forge Framework — a TypeScript framework for backend microservices and web applications.
Installation
npm install @forgeframework/authUsage
import { JwtStrategy, authMiddleware, OAuth2Strategy } from '@forgeframework/auth';
const jwt = new JwtStrategy({
secret: config.get('auth.jwtSecret'),
algorithm: 'RS256',
accessTokenExpiry: '15m',
refreshTokenExpiry: '7d',
issuer: 'forge-app',
});
server.use(authMiddleware(jwt));
server.route('POST', '/auth/login', async (ctx) => {
const { email, password } = ctx.request.body as LoginCredentials;
const user = await userService.verifyCredentials(email, password);
const tokens = jwt.sign({ sub: user.id, email: user.email, roles: user.roles, permissions: user.permissions });
ctx.response.json(tokens);
});
server.route('POST', '/auth/refresh', async (ctx) => {
const { refreshToken } = ctx.request.body as { refreshToken: string };
const tokens = await jwt.refresh(refreshToken);
ctx.response.json(tokens);
});Documentation
Full API reference and guides: https://carbonforge.io/framework/docs/security/auth
(Documentation site launching soon.)
License
MIT © Carbon Forge
