@azlib/identity 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +387 -0
- package/dist/errors-BGMwaW5s.d.mts +481 -0
- package/dist/errors-BGMwaW5s.d.mts.map +1 -0
- package/dist/errors-Bcjx9o6g.cjs +111 -0
- package/dist/errors-C2xZAatu.d.cts +481 -0
- package/dist/errors-C2xZAatu.d.cts.map +1 -0
- package/dist/errors-CEmnZxIn.mjs +66 -0
- package/dist/errors-CEmnZxIn.mjs.map +1 -0
- package/dist/express.cjs +405 -0
- package/dist/express.d.cts +87 -0
- package/dist/express.d.cts.map +1 -0
- package/dist/express.d.mts +87 -0
- package/dist/express.d.mts.map +1 -0
- package/dist/express.mjs +401 -0
- package/dist/express.mjs.map +1 -0
- package/dist/identity-4eP45YIP.cjs +461 -0
- package/dist/identity-Bz9RDOvT.mjs +410 -0
- package/dist/identity-Bz9RDOvT.mjs.map +1 -0
- package/dist/identity-router-DBL20UWT.d.mts +115 -0
- package/dist/identity-router-DBL20UWT.d.mts.map +1 -0
- package/dist/identity-router-Dib30Waj.d.cts +115 -0
- package/dist/identity-router-Dib30Waj.d.cts.map +1 -0
- package/dist/identity-service-B9zrvE9z.d.mts +128 -0
- package/dist/identity-service-B9zrvE9z.d.mts.map +1 -0
- package/dist/identity-service-CLzKx8Z7.d.cts +128 -0
- package/dist/identity-service-CLzKx8Z7.d.cts.map +1 -0
- package/dist/identity-store-BRRahxcS.d.cts +272 -0
- package/dist/identity-store-BRRahxcS.d.cts.map +1 -0
- package/dist/identity-store-BRRahxcS.d.mts +272 -0
- package/dist/identity-store-BRRahxcS.d.mts.map +1 -0
- package/dist/index-CpufYgyn.d.cts +30 -0
- package/dist/index-CpufYgyn.d.cts.map +1 -0
- package/dist/index-CpufYgyn.d.mts +30 -0
- package/dist/index-CpufYgyn.d.mts.map +1 -0
- package/dist/index.cjs +18 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +3 -0
- package/dist/logger-Be1wDzBC.cjs +48 -0
- package/dist/logger-CcCHJVVe.mjs +33 -0
- package/dist/logger-CcCHJVVe.mjs.map +1 -0
- package/dist/nestjs.cjs +516 -0
- package/dist/nestjs.d.cts +102 -0
- package/dist/nestjs.d.cts.map +1 -0
- package/dist/nestjs.d.mts +102 -0
- package/dist/nestjs.d.mts.map +1 -0
- package/dist/nestjs.mjs +500 -0
- package/dist/nestjs.mjs.map +1 -0
- package/dist/node.cjs +946 -0
- package/dist/node.d.cts +260 -0
- package/dist/node.d.cts.map +1 -0
- package/dist/node.d.mts +260 -0
- package/dist/node.d.mts.map +1 -0
- package/dist/node.mjs +890 -0
- package/dist/node.mjs.map +1 -0
- package/dist/test-utils.cjs +169 -0
- package/dist/test-utils.d.cts +12 -0
- package/dist/test-utils.d.cts.map +1 -0
- package/dist/test-utils.d.mts +12 -0
- package/dist/test-utils.d.mts.map +1 -0
- package/dist/test-utils.mjs +170 -0
- package/dist/test-utils.mjs.map +1 -0
- package/package.json +92 -0
- package/schema/model.ts +100 -0
- package/schema/mysql.sql +102 -0
- package/schema/postgres.sql +92 -0
- package/schema/prisma.schema +122 -0
- package/schema/sqlite.sql +92 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { V as AuthorizationRequirement } from "./errors-BGMwaW5s.mjs";
|
|
2
|
+
import { t as IdentityService } from "./identity-service-B9zrvE9z.mjs";
|
|
3
|
+
import { t as CookieRefreshOptions } from "./identity-router-DBL20UWT.mjs";
|
|
4
|
+
import { Request, Response } from "express";
|
|
5
|
+
import { CanActivate, DynamicModule, ExecutionContext } from "@nestjs/common";
|
|
6
|
+
import { Reflector } from "@nestjs/core";
|
|
7
|
+
|
|
8
|
+
//#region core/nestjs/identity-controller.d.ts
|
|
9
|
+
/** Options accepted by {@link createIdentityController}. */
|
|
10
|
+
interface IdentityControllerOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Cookie-based refresh-token transport. When set, the refresh token is stored in an
|
|
13
|
+
* `HttpOnly` cookie instead of the response body. Omit for body mode.
|
|
14
|
+
*/
|
|
15
|
+
cookie?: CookieRefreshOptions;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region core/nestjs/identity.module.d.ts
|
|
19
|
+
/** Token used to inject the configured {@link IdentityService} in Nest providers. */
|
|
20
|
+
declare const IDENTITY_SERVICE: unique symbol;
|
|
21
|
+
/** Metadata key holding the authorization requirement for a route. */
|
|
22
|
+
declare const IDENTITY_REQUIREMENT: unique symbol;
|
|
23
|
+
/**
|
|
24
|
+
* Options for enabling the pre-built REST routes in {@link IdentityModule}.
|
|
25
|
+
*/
|
|
26
|
+
interface IdentityRoutesOptions extends IdentityControllerOptions {
|
|
27
|
+
/**
|
|
28
|
+
* URL prefix for the built-in controller. Default: `"auth"`.
|
|
29
|
+
*
|
|
30
|
+
* The controller is mounted at this prefix relative to the application's global
|
|
31
|
+
* prefix (if any).
|
|
32
|
+
*/
|
|
33
|
+
prefix?: string;
|
|
34
|
+
}
|
|
35
|
+
interface IdentityModuleOptions {
|
|
36
|
+
/** A fully wired identity service (see `createIdentityService`). */
|
|
37
|
+
service: IdentityService;
|
|
38
|
+
/**
|
|
39
|
+
* When set, the module automatically registers a built-in REST controller with all
|
|
40
|
+
* standard auth endpoints (`POST /register`, `POST /login`, `POST /refresh`,
|
|
41
|
+
* `POST /logout`, `GET /me`).
|
|
42
|
+
*
|
|
43
|
+
* Pass `true` to use the defaults (`prefix: "auth"`, body-mode refresh tokens), or
|
|
44
|
+
* supply an `IdentityRoutesOptions` object to customise the prefix and cookie behaviour.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* // Minimal — everything works out of the box
|
|
49
|
+
* IdentityModule.forRoot({ service, routes: true })
|
|
50
|
+
*
|
|
51
|
+
* // With a custom prefix and HttpOnly refresh-token cookie
|
|
52
|
+
* IdentityModule.forRoot({
|
|
53
|
+
* service,
|
|
54
|
+
* routes: { prefix: "v1/auth", cookie: { name: "rt", secure: true } },
|
|
55
|
+
* })
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
routes?: true | IdentityRoutesOptions;
|
|
59
|
+
}
|
|
60
|
+
interface IdentityModuleAsyncOptions {
|
|
61
|
+
imports?: DynamicModule["imports"];
|
|
62
|
+
/** Factory returning the configured identity service. */
|
|
63
|
+
useFactory: (...args: never[]) => IdentityService | Promise<IdentityService>;
|
|
64
|
+
inject?: unknown[];
|
|
65
|
+
/**
|
|
66
|
+
* Same as {@link IdentityModuleOptions.routes} — enable built-in REST routes
|
|
67
|
+
* alongside the async service factory.
|
|
68
|
+
*/
|
|
69
|
+
routes?: true | IdentityRoutesOptions;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Authentication guard: verifies the Bearer access token and attaches the hydrated
|
|
73
|
+
* principal to `request.identity`. Apply with `@UseGuards(IdentityAuthGuard)`.
|
|
74
|
+
*/
|
|
75
|
+
declare class IdentityAuthGuard implements CanActivate {
|
|
76
|
+
private readonly service;
|
|
77
|
+
constructor(service: IdentityService);
|
|
78
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Authorization guard: enforces the requirement declared by `@RequireAuthorization()`
|
|
82
|
+
* (or `@RequirePermission()`). Must run after {@link IdentityAuthGuard}. Deny-by-default.
|
|
83
|
+
*/
|
|
84
|
+
declare class IdentityAuthorizationGuard implements CanActivate {
|
|
85
|
+
private readonly service;
|
|
86
|
+
private readonly reflector;
|
|
87
|
+
constructor(service: IdentityService, reflector: Reflector);
|
|
88
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
89
|
+
}
|
|
90
|
+
/** Declares the authorization requirement for a route or controller. */
|
|
91
|
+
declare const RequireAuthorization: (requirement: AuthorizationRequirement) => import("@nestjs/common").CustomDecorator<typeof IDENTITY_REQUIREMENT>;
|
|
92
|
+
/** Convenience: declare a single required permission for a route or controller. */
|
|
93
|
+
declare const RequirePermission: (permission: string) => import("@nestjs/common").CustomDecorator<typeof IDENTITY_REQUIREMENT>;
|
|
94
|
+
/** Param decorator that resolves the authenticated principal from the request. */
|
|
95
|
+
declare const CurrentUser: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
96
|
+
declare class IdentityModule {
|
|
97
|
+
static forRoot(options: IdentityModuleOptions): DynamicModule;
|
|
98
|
+
static forRootAsync(options: IdentityModuleAsyncOptions): DynamicModule;
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
export { CurrentUser, IDENTITY_REQUIREMENT, IDENTITY_SERVICE, IdentityAuthGuard, IdentityAuthorizationGuard, type IdentityControllerOptions, IdentityModule, IdentityModuleAsyncOptions, IdentityModuleOptions, IdentityRoutesOptions, RequireAuthorization, RequirePermission };
|
|
102
|
+
//# sourceMappingURL=nestjs.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nestjs.d.mts","names":[],"sources":["../core/nestjs/identity-controller.ts","../core/nestjs/identity.module.ts"],"mappings":";;;;;;;;;UAkGiB,yBAAA;;;AAAjB;;EAKE,MAAA,GAAS,oBAAoB;AAAA;;;AAAA;AAAA,cC1ElB,gBAAA;;cAGA,oBAAA;AAHb;;;AAAA,UAQiB,qBAAA,SAA8B,yBAAyB;EARJ;AAGpE;;;;AAA4E;EAY1E,MAAM;AAAA;AAAA,UAGS,qBAAA;EAV8B;EAY7C,OAAA,EAAS,eAAA;EAFM;;;;;;;;;AAuBsB;AAGvC;;;;;;;;;;EAHE,MAAA,UAAgB,qBAAqB;AAAA;AAAA,UAGtB,0BAAA;EACf,OAAA,GAAU,aAAA;EAEwB;EAAlC,UAAA,MAAgB,IAAA,cAAkB,eAAA,GAAkB,OAAA,CAAQ,eAAA;EAC5D,MAAA;EAAA;;;;EAKA,MAAA,UAAgB,qBAAA;AAAA;;;;;cAqBL,iBAAA,YAA6B,WAAA;EAAA,iBACe,OAAA;cAAA,OAAA,EAAS,eAAA;EAE1D,WAAA,CAAY,OAAA,EAAS,gBAAA,GAAmB,OAAA;AAAA;;;;;cAoBnC,0BAAA,YAAsC,WAAA;EAAA,iBAEJ,OAAA;EAAA,iBAC1B,SAAA;cAD0B,OAAA,EAAS,eAAA,EACnC,SAAA,EAAW,SAAA;EAGxB,WAAA,CAAY,OAAA,EAAS,gBAAA,GAAmB,OAAA;AAAA;AAPhD;AAAA,cAgCa,oBAAA,GAAoB,WAAA,EAAiB,wBAAA,8BAAwB,eAAA,QAAA,oBAAA;;cAI7D,iBAAA,GAAiB,UAAA,sCAAsB,eAAA,QAAA,oBAAA;;cAIvC,WAAA,MAAW,WAAA,gBAAA,kBAKvB;AAAA,cAiBY,cAAA;EAAA,OACJ,OAAA,CAAQ,OAAA,EAAS,qBAAA,GAAwB,aAAA;EAAA,OAczC,YAAA,CAAa,OAAA,EAAS,0BAAA,GAA6B,aAAA;AAAA"}
|
package/dist/nestjs.mjs
ADDED
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
import { a as IdentityError, c as UnauthenticatedError } from "./errors-CEmnZxIn.mjs";
|
|
2
|
+
import { Body, Controller, ForbiddenException, Get, HttpCode, HttpException, Inject, Injectable, Param, Post, Req, Res, SetMetadata, UnauthorizedException, UseGuards, createParamDecorator } from "@nestjs/common";
|
|
3
|
+
import { Reflector } from "@nestjs/core";
|
|
4
|
+
//#region \0@oxc-project+runtime@0.132.0/helpers/decorateMetadata.js
|
|
5
|
+
function __decorateMetadata(k, v) {
|
|
6
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region \0@oxc-project+runtime@0.132.0/helpers/decorateParam.js
|
|
10
|
+
function __decorateParam(paramIndex, decorator) {
|
|
11
|
+
return function(target, key) {
|
|
12
|
+
decorator(target, key, paramIndex);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region \0@oxc-project+runtime@0.132.0/helpers/decorate.js
|
|
17
|
+
function __decorate(decorators, target, key, desc) {
|
|
18
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
21
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region core/nestjs/identity-controller.ts
|
|
25
|
+
/**
|
|
26
|
+
* Pre-built NestJS controller for `@azlib/identity`.
|
|
27
|
+
*
|
|
28
|
+
* Register it automatically via `IdentityModule.forRoot({ routes: true })`.
|
|
29
|
+
* `@nestjs/common` is an optional peer dependency — only required when this file is used.
|
|
30
|
+
*/
|
|
31
|
+
function resolveCookieName(opts) {
|
|
32
|
+
return opts.name ?? "azlib_rt";
|
|
33
|
+
}
|
|
34
|
+
function rethrowAsHttp(err) {
|
|
35
|
+
if (err instanceof IdentityError) throw new HttpException({
|
|
36
|
+
code: err.code,
|
|
37
|
+
message: err.message
|
|
38
|
+
}, err.statusCode);
|
|
39
|
+
throw err;
|
|
40
|
+
}
|
|
41
|
+
function setCookieAndStripRefreshToken(res, tokens, opts) {
|
|
42
|
+
const maxAge = tokens.refreshTokenExpiresAt.getTime() - Date.now();
|
|
43
|
+
res.cookie(resolveCookieName(opts), tokens.refreshToken, {
|
|
44
|
+
httpOnly: opts.httpOnly ?? true,
|
|
45
|
+
secure: opts.secure ?? process.env.NODE_ENV === "production",
|
|
46
|
+
sameSite: opts.sameSite ?? "lax",
|
|
47
|
+
path: opts.path ?? "/",
|
|
48
|
+
domain: opts.domain,
|
|
49
|
+
maxAge
|
|
50
|
+
});
|
|
51
|
+
const { refreshToken: _rt, refreshTokenExpiresAt: _exp, ...bodyTokens } = tokens;
|
|
52
|
+
return bodyTokens;
|
|
53
|
+
}
|
|
54
|
+
function buildAuthResponse(result, cookieOpts, res) {
|
|
55
|
+
if (cookieOpts) {
|
|
56
|
+
const tokens = setCookieAndStripRefreshToken(res, result.tokens, cookieOpts);
|
|
57
|
+
return {
|
|
58
|
+
user: result.user,
|
|
59
|
+
tokens
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
function buildLoginResponse(result, cookieOpts, res) {
|
|
65
|
+
if ("mfaToken" in result) return result;
|
|
66
|
+
return buildAuthResponse(result, cookieOpts, res);
|
|
67
|
+
}
|
|
68
|
+
function readRefreshTokenFromRequest(req, cookieOpts) {
|
|
69
|
+
if (cookieOpts) return req.cookies?.[resolveCookieName(cookieOpts)];
|
|
70
|
+
const token = req.body?.["refreshToken"];
|
|
71
|
+
return typeof token === "string" ? token : void 0;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Returns a dynamically created NestJS controller class with all standard identity
|
|
75
|
+
* routes pre-wired. The class is registered directly in `IdentityModule.forRoot()`
|
|
76
|
+
* when `routes` is configured — consumers do not need to define this controller.
|
|
77
|
+
*
|
|
78
|
+
* Pre-wired routes (relative to the module prefix, default `"auth"`):
|
|
79
|
+
*
|
|
80
|
+
* | Method | Path | Description |
|
|
81
|
+
* |--------|------|-------------|
|
|
82
|
+
* | POST | `/register` | Create a new account |
|
|
83
|
+
* | POST | `/login` | Email + password login; may return MFA challenge |
|
|
84
|
+
* | POST | `/refresh` | Rotate the refresh token |
|
|
85
|
+
* | POST | `/logout` | Revoke the current session |
|
|
86
|
+
* | GET | `/me` | Return the authenticated principal (requires auth) |
|
|
87
|
+
* | POST | `/request-email-verification` | Re-send verification link (requires auth) |
|
|
88
|
+
* | POST | `/verify-email` | Consume an email verification token |
|
|
89
|
+
* | POST | `/request-password-reset` | Send a password reset link |
|
|
90
|
+
* | POST | `/reset-password` | Set a new password using a reset token |
|
|
91
|
+
* | POST | `/mfa/verify` | Complete an MFA challenge after login |
|
|
92
|
+
* | POST | `/2fa/setup` | Begin TOTP 2FA setup (requires auth) |
|
|
93
|
+
* | POST | `/2fa/enable` | Confirm and enable 2FA (requires auth) |
|
|
94
|
+
* | POST | `/2fa/disable` | Disable 2FA (requires auth) |
|
|
95
|
+
* | POST | `/admin/lock/:userId` | Lock an account |
|
|
96
|
+
* | POST | `/admin/unlock/:userId` | Unlock an account |
|
|
97
|
+
* | POST | `/admin/disable/:userId` | Disable an account |
|
|
98
|
+
*/
|
|
99
|
+
function createIdentityController(prefix, controllerOptions = {}) {
|
|
100
|
+
const cookieOpts = controllerOptions.cookie;
|
|
101
|
+
let IdentityController = class IdentityController {
|
|
102
|
+
service;
|
|
103
|
+
constructor(service) {
|
|
104
|
+
this.service = service;
|
|
105
|
+
}
|
|
106
|
+
async register(body, res) {
|
|
107
|
+
try {
|
|
108
|
+
return buildAuthResponse(await this.service.register(body), cookieOpts, res);
|
|
109
|
+
} catch (err) {
|
|
110
|
+
rethrowAsHttp(err);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async login(body, res) {
|
|
114
|
+
try {
|
|
115
|
+
return buildLoginResponse(await this.service.login(body), cookieOpts, res);
|
|
116
|
+
} catch (err) {
|
|
117
|
+
rethrowAsHttp(err);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async refresh(req, res) {
|
|
121
|
+
try {
|
|
122
|
+
const token = readRefreshTokenFromRequest(req, cookieOpts);
|
|
123
|
+
if (!token) throw new UnauthenticatedError("Refresh token is missing.");
|
|
124
|
+
return buildAuthResponse(await this.service.refresh(token), cookieOpts, res);
|
|
125
|
+
} catch (err) {
|
|
126
|
+
rethrowAsHttp(err);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
async logout(req, res) {
|
|
130
|
+
try {
|
|
131
|
+
const token = readRefreshTokenFromRequest(req, cookieOpts);
|
|
132
|
+
if (token) await this.service.logout(token);
|
|
133
|
+
if (cookieOpts) res.clearCookie(resolveCookieName(cookieOpts), { path: cookieOpts.path ?? "/" });
|
|
134
|
+
} catch (err) {
|
|
135
|
+
rethrowAsHttp(err);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
getMe(req) {
|
|
139
|
+
return req.identity;
|
|
140
|
+
}
|
|
141
|
+
async requestEmailVerification(req) {
|
|
142
|
+
try {
|
|
143
|
+
await this.service.requestEmailVerification(req.identity.userId);
|
|
144
|
+
} catch (err) {
|
|
145
|
+
rethrowAsHttp(err);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async verifyEmail(body) {
|
|
149
|
+
try {
|
|
150
|
+
if (!body.token) throw new UnauthenticatedError("token is required.");
|
|
151
|
+
await this.service.verifyEmail(body.token);
|
|
152
|
+
} catch (err) {
|
|
153
|
+
rethrowAsHttp(err);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
async requestPasswordReset(body) {
|
|
157
|
+
try {
|
|
158
|
+
if (!body.email) throw new UnauthenticatedError("email is required.");
|
|
159
|
+
await this.service.requestPasswordReset(body.email);
|
|
160
|
+
} catch (err) {
|
|
161
|
+
rethrowAsHttp(err);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async resetPassword(body) {
|
|
165
|
+
try {
|
|
166
|
+
if (!body.token || !body.newPassword) throw new UnauthenticatedError("token and newPassword are required.");
|
|
167
|
+
await this.service.resetPassword(body.token, body.newPassword);
|
|
168
|
+
} catch (err) {
|
|
169
|
+
rethrowAsHttp(err);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
async verifyMfaChallenge(body, res) {
|
|
173
|
+
try {
|
|
174
|
+
if (!body.mfaToken || !body.code) throw new UnauthenticatedError("mfaToken and code are required.");
|
|
175
|
+
return buildAuthResponse(await this.service.verifyMfaChallenge(body.mfaToken, body.code), cookieOpts, res);
|
|
176
|
+
} catch (err) {
|
|
177
|
+
rethrowAsHttp(err);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async setup2FA(req) {
|
|
181
|
+
try {
|
|
182
|
+
return await this.service.setup2FA(req.identity.userId);
|
|
183
|
+
} catch (err) {
|
|
184
|
+
rethrowAsHttp(err);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
async enable2FA(req, body) {
|
|
188
|
+
try {
|
|
189
|
+
if (!body.code) throw new UnauthenticatedError("code is required.");
|
|
190
|
+
await this.service.enable2FA(req.identity.userId, body.code);
|
|
191
|
+
} catch (err) {
|
|
192
|
+
rethrowAsHttp(err);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async disable2FA(req, body) {
|
|
196
|
+
try {
|
|
197
|
+
if (!body.code) throw new UnauthenticatedError("code is required.");
|
|
198
|
+
await this.service.disable2FA(req.identity.userId, body.code);
|
|
199
|
+
} catch (err) {
|
|
200
|
+
rethrowAsHttp(err);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
async lockAccount(userId) {
|
|
204
|
+
try {
|
|
205
|
+
await this.service.lockAccount(userId);
|
|
206
|
+
} catch (err) {
|
|
207
|
+
rethrowAsHttp(err);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
async unlockAccount(userId) {
|
|
211
|
+
try {
|
|
212
|
+
await this.service.unlockAccount(userId);
|
|
213
|
+
} catch (err) {
|
|
214
|
+
rethrowAsHttp(err);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
async disableAccount(userId) {
|
|
218
|
+
try {
|
|
219
|
+
await this.service.disableAccount(userId);
|
|
220
|
+
} catch (err) {
|
|
221
|
+
rethrowAsHttp(err);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
__decorate([
|
|
226
|
+
Post("register"),
|
|
227
|
+
__decorateParam(0, Body()),
|
|
228
|
+
__decorateParam(1, Res({ passthrough: true })),
|
|
229
|
+
__decorateMetadata("design:type", Function),
|
|
230
|
+
__decorateMetadata("design:paramtypes", [Object, Object]),
|
|
231
|
+
__decorateMetadata("design:returntype", Promise)
|
|
232
|
+
], IdentityController.prototype, "register", null);
|
|
233
|
+
__decorate([
|
|
234
|
+
Post("login"),
|
|
235
|
+
__decorateParam(0, Body()),
|
|
236
|
+
__decorateParam(1, Res({ passthrough: true })),
|
|
237
|
+
__decorateMetadata("design:type", Function),
|
|
238
|
+
__decorateMetadata("design:paramtypes", [Object, Object]),
|
|
239
|
+
__decorateMetadata("design:returntype", Promise)
|
|
240
|
+
], IdentityController.prototype, "login", null);
|
|
241
|
+
__decorate([
|
|
242
|
+
Post("refresh"),
|
|
243
|
+
__decorateParam(0, Req()),
|
|
244
|
+
__decorateParam(1, Res({ passthrough: true })),
|
|
245
|
+
__decorateMetadata("design:type", Function),
|
|
246
|
+
__decorateMetadata("design:paramtypes", [Object, Object]),
|
|
247
|
+
__decorateMetadata("design:returntype", Promise)
|
|
248
|
+
], IdentityController.prototype, "refresh", null);
|
|
249
|
+
__decorate([
|
|
250
|
+
Post("logout"),
|
|
251
|
+
HttpCode(204),
|
|
252
|
+
__decorateParam(0, Req()),
|
|
253
|
+
__decorateParam(1, Res({ passthrough: true })),
|
|
254
|
+
__decorateMetadata("design:type", Function),
|
|
255
|
+
__decorateMetadata("design:paramtypes", [Object, Object]),
|
|
256
|
+
__decorateMetadata("design:returntype", Promise)
|
|
257
|
+
], IdentityController.prototype, "logout", null);
|
|
258
|
+
__decorate([
|
|
259
|
+
Get("me"),
|
|
260
|
+
UseGuards(IdentityAuthGuard),
|
|
261
|
+
__decorateParam(0, Req()),
|
|
262
|
+
__decorateMetadata("design:type", Function),
|
|
263
|
+
__decorateMetadata("design:paramtypes", [Object]),
|
|
264
|
+
__decorateMetadata("design:returntype", void 0)
|
|
265
|
+
], IdentityController.prototype, "getMe", null);
|
|
266
|
+
__decorate([
|
|
267
|
+
Post("request-email-verification"),
|
|
268
|
+
HttpCode(204),
|
|
269
|
+
UseGuards(IdentityAuthGuard),
|
|
270
|
+
__decorateParam(0, Req()),
|
|
271
|
+
__decorateMetadata("design:type", Function),
|
|
272
|
+
__decorateMetadata("design:paramtypes", [Object]),
|
|
273
|
+
__decorateMetadata("design:returntype", Promise)
|
|
274
|
+
], IdentityController.prototype, "requestEmailVerification", null);
|
|
275
|
+
__decorate([
|
|
276
|
+
Post("verify-email"),
|
|
277
|
+
HttpCode(204),
|
|
278
|
+
__decorateParam(0, Body()),
|
|
279
|
+
__decorateMetadata("design:type", Function),
|
|
280
|
+
__decorateMetadata("design:paramtypes", [Object]),
|
|
281
|
+
__decorateMetadata("design:returntype", Promise)
|
|
282
|
+
], IdentityController.prototype, "verifyEmail", null);
|
|
283
|
+
__decorate([
|
|
284
|
+
Post("request-password-reset"),
|
|
285
|
+
HttpCode(204),
|
|
286
|
+
__decorateParam(0, Body()),
|
|
287
|
+
__decorateMetadata("design:type", Function),
|
|
288
|
+
__decorateMetadata("design:paramtypes", [Object]),
|
|
289
|
+
__decorateMetadata("design:returntype", Promise)
|
|
290
|
+
], IdentityController.prototype, "requestPasswordReset", null);
|
|
291
|
+
__decorate([
|
|
292
|
+
Post("reset-password"),
|
|
293
|
+
HttpCode(204),
|
|
294
|
+
__decorateParam(0, Body()),
|
|
295
|
+
__decorateMetadata("design:type", Function),
|
|
296
|
+
__decorateMetadata("design:paramtypes", [Object]),
|
|
297
|
+
__decorateMetadata("design:returntype", Promise)
|
|
298
|
+
], IdentityController.prototype, "resetPassword", null);
|
|
299
|
+
__decorate([
|
|
300
|
+
Post("mfa/verify"),
|
|
301
|
+
__decorateParam(0, Body()),
|
|
302
|
+
__decorateParam(1, Res({ passthrough: true })),
|
|
303
|
+
__decorateMetadata("design:type", Function),
|
|
304
|
+
__decorateMetadata("design:paramtypes", [Object, Object]),
|
|
305
|
+
__decorateMetadata("design:returntype", Promise)
|
|
306
|
+
], IdentityController.prototype, "verifyMfaChallenge", null);
|
|
307
|
+
__decorate([
|
|
308
|
+
Post("2fa/setup"),
|
|
309
|
+
UseGuards(IdentityAuthGuard),
|
|
310
|
+
__decorateParam(0, Req()),
|
|
311
|
+
__decorateMetadata("design:type", Function),
|
|
312
|
+
__decorateMetadata("design:paramtypes", [Object]),
|
|
313
|
+
__decorateMetadata("design:returntype", Promise)
|
|
314
|
+
], IdentityController.prototype, "setup2FA", null);
|
|
315
|
+
__decorate([
|
|
316
|
+
Post("2fa/enable"),
|
|
317
|
+
HttpCode(204),
|
|
318
|
+
UseGuards(IdentityAuthGuard),
|
|
319
|
+
__decorateParam(0, Req()),
|
|
320
|
+
__decorateParam(1, Body()),
|
|
321
|
+
__decorateMetadata("design:type", Function),
|
|
322
|
+
__decorateMetadata("design:paramtypes", [Object, Object]),
|
|
323
|
+
__decorateMetadata("design:returntype", Promise)
|
|
324
|
+
], IdentityController.prototype, "enable2FA", null);
|
|
325
|
+
__decorate([
|
|
326
|
+
Post("2fa/disable"),
|
|
327
|
+
HttpCode(204),
|
|
328
|
+
UseGuards(IdentityAuthGuard),
|
|
329
|
+
__decorateParam(0, Req()),
|
|
330
|
+
__decorateParam(1, Body()),
|
|
331
|
+
__decorateMetadata("design:type", Function),
|
|
332
|
+
__decorateMetadata("design:paramtypes", [Object, Object]),
|
|
333
|
+
__decorateMetadata("design:returntype", Promise)
|
|
334
|
+
], IdentityController.prototype, "disable2FA", null);
|
|
335
|
+
__decorate([
|
|
336
|
+
Post("admin/lock/:userId"),
|
|
337
|
+
HttpCode(204),
|
|
338
|
+
__decorateParam(0, Param("userId")),
|
|
339
|
+
__decorateMetadata("design:type", Function),
|
|
340
|
+
__decorateMetadata("design:paramtypes", [String]),
|
|
341
|
+
__decorateMetadata("design:returntype", Promise)
|
|
342
|
+
], IdentityController.prototype, "lockAccount", null);
|
|
343
|
+
__decorate([
|
|
344
|
+
Post("admin/unlock/:userId"),
|
|
345
|
+
HttpCode(204),
|
|
346
|
+
__decorateParam(0, Param("userId")),
|
|
347
|
+
__decorateMetadata("design:type", Function),
|
|
348
|
+
__decorateMetadata("design:paramtypes", [String]),
|
|
349
|
+
__decorateMetadata("design:returntype", Promise)
|
|
350
|
+
], IdentityController.prototype, "unlockAccount", null);
|
|
351
|
+
__decorate([
|
|
352
|
+
Post("admin/disable/:userId"),
|
|
353
|
+
HttpCode(204),
|
|
354
|
+
__decorateParam(0, Param("userId")),
|
|
355
|
+
__decorateMetadata("design:type", Function),
|
|
356
|
+
__decorateMetadata("design:paramtypes", [String]),
|
|
357
|
+
__decorateMetadata("design:returntype", Promise)
|
|
358
|
+
], IdentityController.prototype, "disableAccount", null);
|
|
359
|
+
IdentityController = __decorate([
|
|
360
|
+
Controller(prefix),
|
|
361
|
+
__decorateParam(0, Inject(IDENTITY_SERVICE)),
|
|
362
|
+
__decorateMetadata("design:paramtypes", [Object])
|
|
363
|
+
], IdentityController);
|
|
364
|
+
return IdentityController;
|
|
365
|
+
}
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region core/nestjs/identity.module.ts
|
|
368
|
+
/**
|
|
369
|
+
* NestJS integration for `@azlib/identity`.
|
|
370
|
+
*
|
|
371
|
+
* Provides a configurable module, an authentication guard, an authorization guard driven
|
|
372
|
+
* by metadata decorators, and a `@CurrentUser()` param decorator. `@nestjs/common` and
|
|
373
|
+
* `reflect-metadata` are optional peer dependencies — only required when this entry is used.
|
|
374
|
+
*/
|
|
375
|
+
var _ref;
|
|
376
|
+
/** Token used to inject the configured {@link IdentityService} in Nest providers. */
|
|
377
|
+
const IDENTITY_SERVICE = Symbol.for("azlib.identity.service");
|
|
378
|
+
/** Metadata key holding the authorization requirement for a route. */
|
|
379
|
+
const IDENTITY_REQUIREMENT = Symbol.for("azlib.identity.requirement");
|
|
380
|
+
const extractBearerToken = (req) => {
|
|
381
|
+
const header = req.headers.authorization;
|
|
382
|
+
const value = Array.isArray(header) ? header[0] : header;
|
|
383
|
+
if (!value || !value.startsWith("Bearer ")) return null;
|
|
384
|
+
const token = value.slice(7).trim();
|
|
385
|
+
return token.length > 0 ? token : null;
|
|
386
|
+
};
|
|
387
|
+
let IdentityAuthGuard = class IdentityAuthGuard {
|
|
388
|
+
service;
|
|
389
|
+
constructor(service) {
|
|
390
|
+
this.service = service;
|
|
391
|
+
}
|
|
392
|
+
async canActivate(context) {
|
|
393
|
+
const req = context.switchToHttp().getRequest();
|
|
394
|
+
const token = extractBearerToken(req);
|
|
395
|
+
if (!token) throw new UnauthorizedException("Missing bearer token.");
|
|
396
|
+
try {
|
|
397
|
+
req.identity = await this.service.authenticate(token);
|
|
398
|
+
} catch {
|
|
399
|
+
throw new UnauthorizedException("Invalid or expired token.");
|
|
400
|
+
}
|
|
401
|
+
return true;
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
IdentityAuthGuard = __decorate([
|
|
405
|
+
Injectable(),
|
|
406
|
+
__decorateParam(0, Inject(IDENTITY_SERVICE)),
|
|
407
|
+
__decorateMetadata("design:paramtypes", [Object])
|
|
408
|
+
], IdentityAuthGuard);
|
|
409
|
+
let IdentityAuthorizationGuard = class IdentityAuthorizationGuard {
|
|
410
|
+
service;
|
|
411
|
+
reflector;
|
|
412
|
+
constructor(service, reflector) {
|
|
413
|
+
this.service = service;
|
|
414
|
+
this.reflector = reflector;
|
|
415
|
+
}
|
|
416
|
+
async canActivate(context) {
|
|
417
|
+
const requirement = this.reflector.getAllAndOverride(IDENTITY_REQUIREMENT, [context.getHandler(), context.getClass()]);
|
|
418
|
+
if (!requirement) return true;
|
|
419
|
+
const principal = context.switchToHttp().getRequest().identity;
|
|
420
|
+
if (!principal) throw new UnauthorizedException("Not authenticated.");
|
|
421
|
+
if (!(await this.service.authorize(requirement, {
|
|
422
|
+
principal,
|
|
423
|
+
action: requirement.permission ?? "custom"
|
|
424
|
+
})).allowed) throw new ForbiddenException();
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
IdentityAuthorizationGuard = __decorate([
|
|
429
|
+
Injectable(),
|
|
430
|
+
__decorateParam(0, Inject(IDENTITY_SERVICE)),
|
|
431
|
+
__decorateMetadata("design:paramtypes", [Object, typeof (_ref = typeof Reflector !== "undefined" && Reflector) === "function" ? _ref : Object])
|
|
432
|
+
], IdentityAuthorizationGuard);
|
|
433
|
+
/** Declares the authorization requirement for a route or controller. */
|
|
434
|
+
const RequireAuthorization = (requirement) => SetMetadata(IDENTITY_REQUIREMENT, requirement);
|
|
435
|
+
/** Convenience: declare a single required permission for a route or controller. */
|
|
436
|
+
const RequirePermission = (permission) => SetMetadata(IDENTITY_REQUIREMENT, { permission });
|
|
437
|
+
/** Param decorator that resolves the authenticated principal from the request. */
|
|
438
|
+
const CurrentUser = createParamDecorator((_data, context) => {
|
|
439
|
+
return context.switchToHttp().getRequest().identity;
|
|
440
|
+
});
|
|
441
|
+
/**
|
|
442
|
+
* NestJS module exposing the identity service plus guards. Register once at the root:
|
|
443
|
+
*
|
|
444
|
+
* ```ts
|
|
445
|
+
* IdentityModule.forRoot({ service: createIdentityService(config, store) })
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
function buildControllers(routes) {
|
|
449
|
+
if (!routes) return [];
|
|
450
|
+
const routesOpts = routes === true ? {} : routes;
|
|
451
|
+
return [createIdentityController(routesOpts.prefix ?? "auth", { cookie: routesOpts.cookie })];
|
|
452
|
+
}
|
|
453
|
+
var IdentityModule = class IdentityModule {
|
|
454
|
+
static forRoot(options) {
|
|
455
|
+
return {
|
|
456
|
+
module: IdentityModule,
|
|
457
|
+
global: true,
|
|
458
|
+
controllers: buildControllers(options.routes),
|
|
459
|
+
providers: [
|
|
460
|
+
{
|
|
461
|
+
provide: IDENTITY_SERVICE,
|
|
462
|
+
useValue: options.service
|
|
463
|
+
},
|
|
464
|
+
IdentityAuthGuard,
|
|
465
|
+
IdentityAuthorizationGuard
|
|
466
|
+
],
|
|
467
|
+
exports: [
|
|
468
|
+
IDENTITY_SERVICE,
|
|
469
|
+
IdentityAuthGuard,
|
|
470
|
+
IdentityAuthorizationGuard
|
|
471
|
+
]
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
static forRootAsync(options) {
|
|
475
|
+
return {
|
|
476
|
+
module: IdentityModule,
|
|
477
|
+
global: true,
|
|
478
|
+
imports: options.imports ?? [],
|
|
479
|
+
controllers: buildControllers(options.routes),
|
|
480
|
+
providers: [
|
|
481
|
+
{
|
|
482
|
+
provide: IDENTITY_SERVICE,
|
|
483
|
+
useFactory: options.useFactory,
|
|
484
|
+
inject: options.inject
|
|
485
|
+
},
|
|
486
|
+
IdentityAuthGuard,
|
|
487
|
+
IdentityAuthorizationGuard
|
|
488
|
+
],
|
|
489
|
+
exports: [
|
|
490
|
+
IDENTITY_SERVICE,
|
|
491
|
+
IdentityAuthGuard,
|
|
492
|
+
IdentityAuthorizationGuard
|
|
493
|
+
]
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
//#endregion
|
|
498
|
+
export { CurrentUser, IDENTITY_REQUIREMENT, IDENTITY_SERVICE, IdentityAuthGuard, IdentityAuthorizationGuard, IdentityModule, RequireAuthorization, RequirePermission };
|
|
499
|
+
|
|
500
|
+
//# sourceMappingURL=nestjs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nestjs.mjs","names":[],"sources":["../core/nestjs/identity-controller.ts","../core/nestjs/identity.module.ts"],"sourcesContent":["/**\n * Pre-built NestJS controller for `@azlib/identity`.\n *\n * Register it automatically via `IdentityModule.forRoot({ routes: true })`.\n * `@nestjs/common` is an optional peer dependency — only required when this file is used.\n */\nimport {\n Body,\n Controller,\n Get,\n HttpCode,\n HttpException,\n type HttpStatus,\n Inject,\n Param,\n Post,\n Req,\n Res,\n UseGuards,\n} from \"@nestjs/common\";\nimport type { Request, Response } from \"express\";\n\nimport { IdentityError, UnauthenticatedError } from \"../errors\";\nimport type { IdentityService } from \"../identity-service\";\nimport type { AuthResult, AuthTokens, LoginResult } from \"../types\";\nimport type { CookieRefreshOptions } from \"../express/identity-router\";\nimport { IdentityAuthGuard, IDENTITY_SERVICE } from \"./identity.module\";\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\nfunction resolveCookieName(opts: CookieRefreshOptions): string {\n return opts.name ?? \"azlib_rt\";\n}\n\nfunction rethrowAsHttp(err: unknown): never {\n if (err instanceof IdentityError) {\n throw new HttpException({ code: err.code, message: err.message }, err.statusCode as HttpStatus);\n }\n throw err;\n}\n\nfunction setCookieAndStripRefreshToken(\n res: Response,\n tokens: AuthTokens,\n opts: CookieRefreshOptions,\n): Omit<AuthTokens, \"refreshToken\" | \"refreshTokenExpiresAt\"> {\n const maxAge = tokens.refreshTokenExpiresAt.getTime() - Date.now();\n res.cookie(resolveCookieName(opts), tokens.refreshToken, {\n httpOnly: opts.httpOnly ?? true,\n secure: opts.secure ?? process.env.NODE_ENV === \"production\",\n sameSite: opts.sameSite ?? \"lax\",\n path: opts.path ?? \"/\",\n domain: opts.domain,\n maxAge,\n });\n const { refreshToken: _rt, refreshTokenExpiresAt: _exp, ...bodyTokens } = tokens;\n return bodyTokens;\n}\n\nfunction buildAuthResponse(result: AuthResult, cookieOpts: CookieRefreshOptions | undefined, res: Response) {\n if (cookieOpts) {\n const tokens = setCookieAndStripRefreshToken(res, result.tokens, cookieOpts);\n return { user: result.user, tokens };\n }\n return result;\n}\n\nfunction buildLoginResponse(\n result: LoginResult,\n cookieOpts: CookieRefreshOptions | undefined,\n res: Response,\n) {\n if (\"mfaToken\" in result) {\n return result; // { kind: \"mfa_required\", mfaToken: \"...\" }\n }\n return buildAuthResponse(result, cookieOpts, res);\n}\n\nfunction readRefreshTokenFromRequest(\n req: Request,\n cookieOpts: CookieRefreshOptions | undefined,\n): string | undefined {\n if (cookieOpts) {\n const cookies = req.cookies as Record<string, string> | undefined;\n return cookies?.[resolveCookieName(cookieOpts)];\n }\n const body = req.body as Record<string, unknown> | undefined;\n const token = body?.[\"refreshToken\"];\n return typeof token === \"string\" ? token : undefined;\n}\n\n// ---------------------------------------------------------------------------\n// Controller options\n// ---------------------------------------------------------------------------\n\n/** Options accepted by {@link createIdentityController}. */\nexport interface IdentityControllerOptions {\n /**\n * Cookie-based refresh-token transport. When set, the refresh token is stored in an\n * `HttpOnly` cookie instead of the response body. Omit for body mode.\n */\n cookie?: CookieRefreshOptions;\n}\n\n// ---------------------------------------------------------------------------\n// Controller factory\n// ---------------------------------------------------------------------------\n\n/**\n * Returns a dynamically created NestJS controller class with all standard identity\n * routes pre-wired. The class is registered directly in `IdentityModule.forRoot()`\n * when `routes` is configured — consumers do not need to define this controller.\n *\n * Pre-wired routes (relative to the module prefix, default `\"auth\"`):\n *\n * | Method | Path | Description |\n * |--------|------|-------------|\n * | POST | `/register` | Create a new account |\n * | POST | `/login` | Email + password login; may return MFA challenge |\n * | POST | `/refresh` | Rotate the refresh token |\n * | POST | `/logout` | Revoke the current session |\n * | GET | `/me` | Return the authenticated principal (requires auth) |\n * | POST | `/request-email-verification` | Re-send verification link (requires auth) |\n * | POST | `/verify-email` | Consume an email verification token |\n * | POST | `/request-password-reset` | Send a password reset link |\n * | POST | `/reset-password` | Set a new password using a reset token |\n * | POST | `/mfa/verify` | Complete an MFA challenge after login |\n * | POST | `/2fa/setup` | Begin TOTP 2FA setup (requires auth) |\n * | POST | `/2fa/enable` | Confirm and enable 2FA (requires auth) |\n * | POST | `/2fa/disable` | Disable 2FA (requires auth) |\n * | POST | `/admin/lock/:userId` | Lock an account |\n * | POST | `/admin/unlock/:userId` | Unlock an account |\n * | POST | `/admin/disable/:userId` | Disable an account |\n */\nexport function createIdentityController(\n prefix: string,\n controllerOptions: IdentityControllerOptions = {},\n) {\n const cookieOpts = controllerOptions.cookie;\n\n @Controller(prefix)\n class IdentityController {\n constructor(@Inject(IDENTITY_SERVICE) readonly service: IdentityService) {}\n\n @Post(\"register\")\n async register(\n @Body() body: { email: string; password: string; displayName?: string },\n @Res({ passthrough: true }) res: Response,\n ) {\n try {\n const result = await this.service.register(body);\n return buildAuthResponse(result, cookieOpts, res);\n } catch (err) {\n rethrowAsHttp(err);\n }\n }\n\n @Post(\"login\")\n async login(\n @Body() body: { email: string; password: string },\n @Res({ passthrough: true }) res: Response,\n ) {\n try {\n const result = await this.service.login(body);\n return buildLoginResponse(result, cookieOpts, res);\n } catch (err) {\n rethrowAsHttp(err);\n }\n }\n\n @Post(\"refresh\")\n async refresh(@Req() req: Request, @Res({ passthrough: true }) res: Response) {\n try {\n const token = readRefreshTokenFromRequest(req, cookieOpts);\n if (!token) {\n throw new UnauthenticatedError(\"Refresh token is missing.\");\n }\n const result = await this.service.refresh(token);\n return buildAuthResponse(result, cookieOpts, res);\n } catch (err) {\n rethrowAsHttp(err);\n }\n }\n\n @Post(\"logout\")\n @HttpCode(204)\n async logout(@Req() req: Request, @Res({ passthrough: true }) res: Response) {\n try {\n const token = readRefreshTokenFromRequest(req, cookieOpts);\n if (token) {\n await this.service.logout(token);\n }\n if (cookieOpts) {\n res.clearCookie(resolveCookieName(cookieOpts), { path: cookieOpts.path ?? \"/\" });\n }\n } catch (err) {\n rethrowAsHttp(err);\n }\n }\n\n @Get(\"me\")\n @UseGuards(IdentityAuthGuard)\n getMe(@Req() req: Request & { identity?: unknown }) {\n return req.identity;\n }\n\n // -------------------------------------------------------------------------\n // Email verification\n // -------------------------------------------------------------------------\n\n @Post(\"request-email-verification\")\n @HttpCode(204)\n @UseGuards(IdentityAuthGuard)\n async requestEmailVerification(@Req() req: Request & { identity?: { userId: string } }) {\n try {\n await this.service.requestEmailVerification(req.identity!.userId);\n } catch (err) {\n rethrowAsHttp(err);\n }\n }\n\n @Post(\"verify-email\")\n @HttpCode(204)\n async verifyEmail(@Body() body: { token?: string }) {\n try {\n if (!body.token) throw new UnauthenticatedError(\"token is required.\");\n await this.service.verifyEmail(body.token);\n } catch (err) {\n rethrowAsHttp(err);\n }\n }\n\n // -------------------------------------------------------------------------\n // Password reset\n // -------------------------------------------------------------------------\n\n @Post(\"request-password-reset\")\n @HttpCode(204)\n async requestPasswordReset(@Body() body: { email?: string }) {\n try {\n if (!body.email) throw new UnauthenticatedError(\"email is required.\");\n await this.service.requestPasswordReset(body.email);\n } catch (err) {\n rethrowAsHttp(err);\n }\n }\n\n @Post(\"reset-password\")\n @HttpCode(204)\n async resetPassword(@Body() body: { token?: string; newPassword?: string }) {\n try {\n if (!body.token || !body.newPassword)\n throw new UnauthenticatedError(\"token and newPassword are required.\");\n await this.service.resetPassword(body.token, body.newPassword);\n } catch (err) {\n rethrowAsHttp(err);\n }\n }\n\n // -------------------------------------------------------------------------\n // Two-factor authentication\n // -------------------------------------------------------------------------\n\n @Post(\"mfa/verify\")\n async verifyMfaChallenge(\n @Body() body: { mfaToken?: string; code?: string },\n @Res({ passthrough: true }) res: Response,\n ) {\n try {\n if (!body.mfaToken || !body.code)\n throw new UnauthenticatedError(\"mfaToken and code are required.\");\n const result = await this.service.verifyMfaChallenge(body.mfaToken, body.code);\n return buildAuthResponse(result, cookieOpts, res);\n } catch (err) {\n rethrowAsHttp(err);\n }\n }\n\n @Post(\"2fa/setup\")\n @UseGuards(IdentityAuthGuard)\n async setup2FA(@Req() req: Request & { identity?: { userId: string } }) {\n try {\n return await this.service.setup2FA(req.identity!.userId);\n } catch (err) {\n rethrowAsHttp(err);\n }\n }\n\n @Post(\"2fa/enable\")\n @HttpCode(204)\n @UseGuards(IdentityAuthGuard)\n async enable2FA(\n @Req() req: Request & { identity?: { userId: string } },\n @Body() body: { code?: string },\n ) {\n try {\n if (!body.code) throw new UnauthenticatedError(\"code is required.\");\n await this.service.enable2FA(req.identity!.userId, body.code);\n } catch (err) {\n rethrowAsHttp(err);\n }\n }\n\n @Post(\"2fa/disable\")\n @HttpCode(204)\n @UseGuards(IdentityAuthGuard)\n async disable2FA(\n @Req() req: Request & { identity?: { userId: string } },\n @Body() body: { code?: string },\n ) {\n try {\n if (!body.code) throw new UnauthenticatedError(\"code is required.\");\n await this.service.disable2FA(req.identity!.userId, body.code);\n } catch (err) {\n rethrowAsHttp(err);\n }\n }\n\n // -------------------------------------------------------------------------\n // Account management (admin)\n // -------------------------------------------------------------------------\n\n @Post(\"admin/lock/:userId\")\n @HttpCode(204)\n async lockAccount(@Param(\"userId\") userId: string) {\n try {\n await this.service.lockAccount(userId);\n } catch (err) {\n rethrowAsHttp(err);\n }\n }\n\n @Post(\"admin/unlock/:userId\")\n @HttpCode(204)\n async unlockAccount(@Param(\"userId\") userId: string) {\n try {\n await this.service.unlockAccount(userId);\n } catch (err) {\n rethrowAsHttp(err);\n }\n }\n\n @Post(\"admin/disable/:userId\")\n @HttpCode(204)\n async disableAccount(@Param(\"userId\") userId: string) {\n try {\n await this.service.disableAccount(userId);\n } catch (err) {\n rethrowAsHttp(err);\n }\n }\n }\n\n return IdentityController;\n}\n","/**\n * NestJS integration for `@azlib/identity`.\n *\n * Provides a configurable module, an authentication guard, an authorization guard driven\n * by metadata decorators, and a `@CurrentUser()` param decorator. `@nestjs/common` and\n * `reflect-metadata` are optional peer dependencies — only required when this entry is used.\n */\nimport {\n type CanActivate,\n type DynamicModule,\n type ExecutionContext,\n ForbiddenException,\n Inject,\n Injectable,\n SetMetadata,\n UnauthorizedException,\n createParamDecorator,\n} from \"@nestjs/common\";\nimport { Reflector } from \"@nestjs/core\";\n\nimport type { AuthorizationRequirement } from \"../authorization\";\nimport type { IdentityService } from \"../identity-service\";\nimport type { AuthenticatedIdentity } from \"../types\";\nimport {\n createIdentityController,\n type IdentityControllerOptions,\n} from \"./identity-controller\";\n\n/** Token used to inject the configured {@link IdentityService} in Nest providers. */\nexport const IDENTITY_SERVICE = Symbol.for(\"azlib.identity.service\");\n\n/** Metadata key holding the authorization requirement for a route. */\nexport const IDENTITY_REQUIREMENT = Symbol.for(\"azlib.identity.requirement\");\n\n/**\n * Options for enabling the pre-built REST routes in {@link IdentityModule}.\n */\nexport interface IdentityRoutesOptions extends IdentityControllerOptions {\n /**\n * URL prefix for the built-in controller. Default: `\"auth\"`.\n *\n * The controller is mounted at this prefix relative to the application's global\n * prefix (if any).\n */\n prefix?: string;\n}\n\nexport interface IdentityModuleOptions {\n /** A fully wired identity service (see `createIdentityService`). */\n service: IdentityService;\n /**\n * When set, the module automatically registers a built-in REST controller with all\n * standard auth endpoints (`POST /register`, `POST /login`, `POST /refresh`,\n * `POST /logout`, `GET /me`).\n *\n * Pass `true` to use the defaults (`prefix: \"auth\"`, body-mode refresh tokens), or\n * supply an `IdentityRoutesOptions` object to customise the prefix and cookie behaviour.\n *\n * @example\n * ```ts\n * // Minimal — everything works out of the box\n * IdentityModule.forRoot({ service, routes: true })\n *\n * // With a custom prefix and HttpOnly refresh-token cookie\n * IdentityModule.forRoot({\n * service,\n * routes: { prefix: \"v1/auth\", cookie: { name: \"rt\", secure: true } },\n * })\n * ```\n */\n routes?: true | IdentityRoutesOptions;\n}\n\nexport interface IdentityModuleAsyncOptions {\n imports?: DynamicModule[\"imports\"];\n /** Factory returning the configured identity service. */\n useFactory: (...args: never[]) => IdentityService | Promise<IdentityService>;\n inject?: unknown[];\n /**\n * Same as {@link IdentityModuleOptions.routes} — enable built-in REST routes\n * alongside the async service factory.\n */\n routes?: true | IdentityRoutesOptions;\n}\n\ninterface RequestWithIdentity {\n headers: Record<string, string | string[] | undefined>;\n identity?: AuthenticatedIdentity;\n}\n\nconst extractBearerToken = (req: RequestWithIdentity): string | null => {\n const header = req.headers.authorization;\n const value = Array.isArray(header) ? header[0] : header;\n if (!value || !value.startsWith(\"Bearer \")) return null;\n const token = value.slice(\"Bearer \".length).trim();\n return token.length > 0 ? token : null;\n};\n\n/**\n * Authentication guard: verifies the Bearer access token and attaches the hydrated\n * principal to `request.identity`. Apply with `@UseGuards(IdentityAuthGuard)`.\n */\n@Injectable()\nexport class IdentityAuthGuard implements CanActivate {\n constructor(@Inject(IDENTITY_SERVICE) private readonly service: IdentityService) {}\n\n async canActivate(context: ExecutionContext): Promise<boolean> {\n const req = context.switchToHttp().getRequest<RequestWithIdentity>();\n const token = extractBearerToken(req);\n if (!token) {\n throw new UnauthorizedException(\"Missing bearer token.\");\n }\n try {\n req.identity = await this.service.authenticate(token);\n } catch {\n throw new UnauthorizedException(\"Invalid or expired token.\");\n }\n return true;\n }\n}\n\n/**\n * Authorization guard: enforces the requirement declared by `@RequireAuthorization()`\n * (or `@RequirePermission()`). Must run after {@link IdentityAuthGuard}. Deny-by-default.\n */\n@Injectable()\nexport class IdentityAuthorizationGuard implements CanActivate {\n constructor(\n @Inject(IDENTITY_SERVICE) private readonly service: IdentityService,\n private readonly reflector: Reflector,\n ) {}\n\n async canActivate(context: ExecutionContext): Promise<boolean> {\n const requirement = this.reflector.getAllAndOverride<AuthorizationRequirement | undefined>(\n IDENTITY_REQUIREMENT,\n [context.getHandler(), context.getClass()],\n );\n // No requirement declared: nothing extra to enforce beyond authentication.\n if (!requirement) return true;\n\n const req = context.switchToHttp().getRequest<RequestWithIdentity>();\n const principal = req.identity;\n if (!principal) {\n throw new UnauthorizedException(\"Not authenticated.\");\n }\n const decision = await this.service.authorize(requirement, {\n principal,\n action: requirement.permission ?? \"custom\",\n });\n if (!decision.allowed) {\n throw new ForbiddenException();\n }\n return true;\n }\n}\n\n/** Declares the authorization requirement for a route or controller. */\nexport const RequireAuthorization = (requirement: AuthorizationRequirement) =>\n SetMetadata(IDENTITY_REQUIREMENT, requirement);\n\n/** Convenience: declare a single required permission for a route or controller. */\nexport const RequirePermission = (permission: string) =>\n SetMetadata(IDENTITY_REQUIREMENT, { permission } satisfies AuthorizationRequirement);\n\n/** Param decorator that resolves the authenticated principal from the request. */\nexport const CurrentUser = createParamDecorator(\n (_data: unknown, context: ExecutionContext): AuthenticatedIdentity | undefined => {\n const req = context.switchToHttp().getRequest<RequestWithIdentity>();\n return req.identity;\n },\n);\n\n/**\n * NestJS module exposing the identity service plus guards. Register once at the root:\n *\n * ```ts\n * IdentityModule.forRoot({ service: createIdentityService(config, store) })\n * ```\n */\nfunction buildControllers(routes: true | IdentityRoutesOptions | undefined) {\n if (!routes) return [];\n const routesOpts = routes === true ? {} : routes;\n const prefix = routesOpts.prefix ?? \"auth\";\n const controllerOpts: IdentityControllerOptions = { cookie: routesOpts.cookie };\n return [createIdentityController(prefix, controllerOpts)];\n}\n\nexport class IdentityModule {\n static forRoot(options: IdentityModuleOptions): DynamicModule {\n return {\n module: IdentityModule,\n global: true,\n controllers: buildControllers(options.routes),\n providers: [\n { provide: IDENTITY_SERVICE, useValue: options.service },\n IdentityAuthGuard,\n IdentityAuthorizationGuard,\n ],\n exports: [IDENTITY_SERVICE, IdentityAuthGuard, IdentityAuthorizationGuard],\n };\n }\n\n static forRootAsync(options: IdentityModuleAsyncOptions): DynamicModule {\n return {\n module: IdentityModule,\n global: true,\n imports: options.imports ?? [],\n controllers: buildControllers(options.routes),\n providers: [\n {\n provide: IDENTITY_SERVICE,\n useFactory: options.useFactory,\n inject: options.inject as never[],\n },\n IdentityAuthGuard,\n IdentityAuthorizationGuard,\n ],\n exports: [IDENTITY_SERVICE, IdentityAuthGuard, IdentityAuthorizationGuard],\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAS,kBAAkB,MAAoC;CAC7D,OAAO,KAAK,QAAQ;AACtB;AAEA,SAAS,cAAc,KAAqB;CAC1C,IAAI,eAAe,eACjB,MAAM,IAAI,cAAc;EAAE,MAAM,IAAI;EAAM,SAAS,IAAI;CAAQ,GAAG,IAAI,UAAwB;CAEhG,MAAM;AACR;AAEA,SAAS,8BACP,KACA,QACA,MAC4D;CAC5D,MAAM,SAAS,OAAO,sBAAsB,QAAQ,IAAI,KAAK,IAAI;CACjE,IAAI,OAAO,kBAAkB,IAAI,GAAG,OAAO,cAAc;EACvD,UAAU,KAAK,YAAY;EAC3B,QAAQ,KAAK,UAAU,QAAQ,IAAI,aAAa;EAChD,UAAU,KAAK,YAAY;EAC3B,MAAM,KAAK,QAAQ;EACnB,QAAQ,KAAK;EACb;CACF,CAAC;CACD,MAAM,EAAE,cAAc,KAAK,uBAAuB,MAAM,GAAG,eAAe;CAC1E,OAAO;A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