@ttoss/http-server-auth 0.9.0 → 0.10.1

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/dist/index.cjs CHANGED
@@ -23,7 +23,7 @@ var __copyProps = (to, from, except, desc) => {
23
23
  }
24
24
  return to;
25
25
  };
26
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
27
27
  value: mod,
28
28
  enumerable: true
29
29
  }) : target, mod));
@@ -356,13 +356,13 @@ var requireAuth = options => {
356
356
 
357
357
  //#endregion
358
358
  exports.authMiddleware = authMiddleware;
359
- Object.defineProperty(exports, 'createEmailAuthHandlers', {
359
+ Object.defineProperty(exports, "createEmailAuthHandlers", {
360
360
  enumerable: true,
361
361
  get: function () {
362
362
  return _ttoss_auth_core.createEmailAuthHandlers;
363
363
  }
364
364
  });
365
- Object.defineProperty(exports, 'createOAuthHandlers', {
365
+ Object.defineProperty(exports, "createOAuthHandlers", {
366
366
  enumerable: true,
367
367
  get: function () {
368
368
  return _ttoss_auth_core.createOAuthHandlers;
@@ -370,39 +370,39 @@ Object.defineProperty(exports, 'createOAuthHandlers', {
370
370
  });
371
371
  exports.createProtectedResourceMetadataMiddleware = createProtectedResourceMetadataMiddleware;
372
372
  exports.emailAuth = emailAuth;
373
- Object.defineProperty(exports, 'emailAuthErrorCodes', {
373
+ Object.defineProperty(exports, "emailAuthErrorCodes", {
374
374
  enumerable: true,
375
375
  get: function () {
376
376
  return _ttoss_auth_core.emailAuthErrorCodes;
377
377
  }
378
378
  });
379
- Object.defineProperty(exports, 'getWwwAuthenticateHeader', {
379
+ Object.defineProperty(exports, "getWwwAuthenticateHeader", {
380
380
  enumerable: true,
381
381
  get: function () {
382
382
  return _ttoss_auth_core.getWwwAuthenticateHeader;
383
383
  }
384
384
  });
385
385
  exports.isOriginAllowed = isOriginAllowed;
386
- Object.defineProperty(exports, 'normalizeEmail', {
386
+ Object.defineProperty(exports, "normalizeEmail", {
387
387
  enumerable: true,
388
388
  get: function () {
389
389
  return _ttoss_auth_core.normalizeEmail;
390
390
  }
391
391
  });
392
392
  exports.oauthServer = oauthServer;
393
- Object.defineProperty(exports, 'protectedResourceMetadataDocument', {
393
+ Object.defineProperty(exports, "protectedResourceMetadataDocument", {
394
394
  enumerable: true,
395
395
  get: function () {
396
396
  return _ttoss_auth_core.protectedResourceMetadataDocument;
397
397
  }
398
398
  });
399
- Object.defineProperty(exports, 'protectedResourceMetadataPaths', {
399
+ Object.defineProperty(exports, "protectedResourceMetadataPaths", {
400
400
  enumerable: true,
401
401
  get: function () {
402
402
  return _ttoss_auth_core.protectedResourceMetadataPaths;
403
403
  }
404
404
  });
405
- Object.defineProperty(exports, 'protectedResourceMetadataUrl', {
405
+ Object.defineProperty(exports, "protectedResourceMetadataUrl", {
406
406
  enumerable: true,
407
407
  get: function () {
408
408
  return _ttoss_auth_core.protectedResourceMetadataUrl;
package/dist/index.d.cts CHANGED
@@ -1,7 +1,6 @@
1
1
 
2
2
  import { Context, Middleware, Next, Router } from "@ttoss/http-server";
3
3
  import { AuthCodeStore, AuthorizeRequest, ClientStore, EmailAuthDelivery, EmailAuthErrorCode, EmailAuthHandler, EmailAuthHandlers, EmailAuthHooks, EmailAuthMode, EmailAuthOptions, EmailAuthOptions as EmailAuthOptions$1, EmailAuthPaths, EmailAuthSession, EmailAuthTtl, EmailAuthUser, EmailAuthUserStore, EmailCodeOptions, IssueTokensArgs, IssuedTokens, OAuthClient, OAuthClientMetadata, OAuthHandlers, OAuthServerOptions, OAuthServerOptions as OAuthServerOptions$1, OnAuthorizeArgs, OnAuthorizeResult, OnRefreshTokenArgs, OnRefreshTokenResult, OneTimeTokenPurpose, OneTimeTokenStore, PasswordOptions, ProtectedResourceMetadata, RequestRateLimit, RequestRateLimitStore, StoredAuthorizationCode, StoredOneTimeToken, createEmailAuthHandlers, createOAuthHandlers, emailAuthErrorCodes, getWwwAuthenticateHeader, normalizeEmail, protectedResourceMetadataDocument, protectedResourceMetadataPaths, protectedResourceMetadataUrl } from "@ttoss/auth-core";
4
-
5
4
  //#region src/types.d.ts
6
5
  type AuthenticatedUser = {
7
6
  id: string;
@@ -31,7 +30,8 @@ type ApiTokenOptions = {
31
30
  lookup: (tokenHash: string, ctx: Context) => Promise<AuthenticatedUser | null>;
32
31
  };
33
32
  type SystemOptions = {
34
- secret: string; /** User attached to ctx.state.user for system calls. */
33
+ secret: string;
34
+ /** User attached to ctx.state.user for system calls. */
35
35
  user: AuthenticatedUser;
36
36
  };
37
37
  type OAuthOptions = {
@@ -59,7 +59,8 @@ type OAuthOptions = {
59
59
  requiredScopes?: string[];
60
60
  };
61
61
  type AuthMiddlewareOptions = {
62
- /** Ordered list of strategies to attempt. First match wins. */strategies: AuthStrategy[];
62
+ /** Ordered list of strategies to attempt. First match wins. */
63
+ strategies: AuthStrategy[];
63
64
  jwt?: JwtOptions;
64
65
  apiToken?: ApiTokenOptions;
65
66
  system?: SystemOptions;
@@ -91,7 +92,7 @@ type AuthMiddlewareOptions = {
91
92
  * header, RFC 9728 when `resourceMetadataUrl` is set) for missing/invalid
92
93
  * tokens, and `403` when a verified token is missing a required scope.
93
94
  */
94
- declare const authMiddleware: (options: AuthMiddlewareOptions) => (ctx: Context, next: Next) => Promise<void>;
95
+ export declare const authMiddleware: (options: AuthMiddlewareOptions) => (ctx: Context, next: Next) => Promise<void>;
95
96
  //#endregion
96
97
  //#region src/emailAuth.d.ts
97
98
  /**
@@ -128,7 +129,7 @@ declare const authMiddleware: (options: AuthMiddlewareOptions) => (ctx: Context,
128
129
  * );
129
130
  * ```
130
131
  */
131
- declare const emailAuth: (options: EmailAuthOptions$1 & {
132
+ export declare const emailAuth: (options: EmailAuthOptions$1 & {
132
133
  /**
133
134
  * Prefix applied to every mounted path, e.g. `/v1`. Useful when the app
134
135
  * versions its API and the engine's default paths are otherwise fine.
@@ -156,7 +157,7 @@ declare const emailAuth: (options: EmailAuthOptions$1 & {
156
157
  * app.use(oauthServer({ issuer, clientStore, authCodeStore, issueTokens, onAuthorize }).routes());
157
158
  * ```
158
159
  */
159
- declare const oauthServer: (options: OAuthServerOptions$1) => Router;
160
+ export declare const oauthServer: (options: OAuthServerOptions$1) => Router;
160
161
  /**
161
162
  * Koa middleware that serves the RFC 9728 Protected Resource Metadata
162
163
  * document. Mount it **before** `authMiddleware` so the discovery endpoint
@@ -166,9 +167,12 @@ declare const oauthServer: (options: OAuthServerOptions$1) => Router;
166
167
  * the resource: the root, plus the path-derived location of RFC 9728 §3.1 when
167
168
  * the resource identifier carries a path.
168
169
  */
169
- declare const createProtectedResourceMetadataMiddleware: (args: {
170
- /** The protected resource's identifier URI. */resource: string; /** Authorization server issuer URIs that issue tokens for this resource. */
171
- authorizationServers: string[]; /** Scopes this resource accepts, advertised as `scopes_supported`. */
170
+ export declare const createProtectedResourceMetadataMiddleware: (args: {
171
+ /** The protected resource's identifier URI. */
172
+ resource: string;
173
+ /** Authorization server issuer URIs that issue tokens for this resource. */
174
+ authorizationServers: string[];
175
+ /** Scopes this resource accepts, advertised as `scopes_supported`. */
172
176
  scopesSupported?: string[];
173
177
  }) => Middleware;
174
178
  //#endregion
@@ -177,7 +181,7 @@ declare const createProtectedResourceMetadataMiddleware: (args: {
177
181
  * Returns true if origin matches any entry in the allowlist.
178
182
  * Strings are compared exactly; RegExps are tested.
179
183
  */
180
- declare const isOriginAllowed: (origin: string, allowedOrigins: Array<string | RegExp | undefined>) => boolean;
184
+ export declare const isOriginAllowed: (origin: string, allowedOrigins: Array<string | RegExp | undefined>) => boolean;
181
185
  //#endregion
182
186
  //#region src/requireAuth.d.ts
183
187
  /**
@@ -187,6 +191,6 @@ declare const isOriginAllowed: (origin: string, allowedOrigins: Array<string | R
187
191
  * @example
188
192
  * router.get('/me', requireAuth({ strategies: ['jwt', 'apiToken'] }), handler);
189
193
  */
190
- declare const requireAuth: (options: AuthMiddlewareOptions) => ((ctx: Context, next: Next) => Promise<void>);
194
+ export declare const requireAuth: (options: AuthMiddlewareOptions) => ((ctx: Context, next: Next) => Promise<void>);
191
195
  //#endregion
192
- export { type ApiTokenOptions, type AuthCodeStore, type AuthMiddlewareOptions, type AuthStrategy, type AuthenticatedUser, type AuthorizeRequest, type ClientStore, type EmailAuthDelivery, type EmailAuthErrorCode, type EmailAuthHandler, type EmailAuthHandlers, type EmailAuthHooks, type EmailAuthMode, type EmailAuthOptions, type EmailAuthPaths, type EmailAuthSession, type EmailAuthTtl, type EmailAuthUser, type EmailAuthUserStore, type EmailCodeOptions, type IssueTokensArgs, type IssuedTokens, type JwtOptions, type OAuthClient, type OAuthClientMetadata, type OAuthHandlers, type OAuthOptions, type OAuthServerOptions, type OnAuthorizeArgs, type OnAuthorizeResult, type OnRefreshTokenArgs, type OnRefreshTokenResult, type OneTimeTokenPurpose, type OneTimeTokenStore, type PasswordOptions, type ProtectedResourceMetadata, type RequestRateLimit, type RequestRateLimitStore, type StoredAuthorizationCode, type StoredOneTimeToken, type SystemOptions, authMiddleware, createEmailAuthHandlers, createOAuthHandlers, createProtectedResourceMetadataMiddleware, emailAuth, emailAuthErrorCodes, getWwwAuthenticateHeader, isOriginAllowed, normalizeEmail, oauthServer, protectedResourceMetadataDocument, protectedResourceMetadataPaths, protectedResourceMetadataUrl, requireAuth };
196
+ export { type ApiTokenOptions, type AuthCodeStore, type AuthMiddlewareOptions, type AuthStrategy, type AuthenticatedUser, type AuthorizeRequest, type ClientStore, type EmailAuthDelivery, type EmailAuthErrorCode, type EmailAuthHandler, type EmailAuthHandlers, type EmailAuthHooks, type EmailAuthMode, type EmailAuthOptions, type EmailAuthPaths, type EmailAuthSession, type EmailAuthTtl, type EmailAuthUser, type EmailAuthUserStore, type EmailCodeOptions, type IssueTokensArgs, type IssuedTokens, type JwtOptions, type OAuthClient, type OAuthClientMetadata, type OAuthHandlers, type OAuthOptions, type OAuthServerOptions, type OnAuthorizeArgs, type OnAuthorizeResult, type OnRefreshTokenArgs, type OnRefreshTokenResult, type OneTimeTokenPurpose, type OneTimeTokenStore, type PasswordOptions, type ProtectedResourceMetadata, type RequestRateLimit, type RequestRateLimitStore, type StoredAuthorizationCode, type StoredOneTimeToken, type SystemOptions, createEmailAuthHandlers, createOAuthHandlers, emailAuthErrorCodes, getWwwAuthenticateHeader, normalizeEmail, protectedResourceMetadataDocument, protectedResourceMetadataPaths, protectedResourceMetadataUrl };
package/dist/index.d.mts CHANGED
@@ -1,7 +1,6 @@
1
1
 
2
2
  import { AuthCodeStore, AuthorizeRequest, ClientStore, EmailAuthDelivery, EmailAuthErrorCode, EmailAuthHandler, EmailAuthHandlers, EmailAuthHooks, EmailAuthMode, EmailAuthOptions, EmailAuthOptions as EmailAuthOptions$1, EmailAuthPaths, EmailAuthSession, EmailAuthTtl, EmailAuthUser, EmailAuthUserStore, EmailCodeOptions, IssueTokensArgs, IssuedTokens, OAuthClient, OAuthClientMetadata, OAuthHandlers, OAuthServerOptions, OAuthServerOptions as OAuthServerOptions$1, OnAuthorizeArgs, OnAuthorizeResult, OnRefreshTokenArgs, OnRefreshTokenResult, OneTimeTokenPurpose, OneTimeTokenStore, PasswordOptions, ProtectedResourceMetadata, RequestRateLimit, RequestRateLimitStore, StoredAuthorizationCode, StoredOneTimeToken, createEmailAuthHandlers, createOAuthHandlers, emailAuthErrorCodes, getWwwAuthenticateHeader, normalizeEmail, protectedResourceMetadataDocument, protectedResourceMetadataPaths, protectedResourceMetadataUrl } from "@ttoss/auth-core";
3
3
  import { Context, Middleware, Next, Router } from "@ttoss/http-server";
4
-
5
4
  //#region src/types.d.ts
6
5
  type AuthenticatedUser = {
7
6
  id: string;
@@ -31,7 +30,8 @@ type ApiTokenOptions = {
31
30
  lookup: (tokenHash: string, ctx: Context) => Promise<AuthenticatedUser | null>;
32
31
  };
33
32
  type SystemOptions = {
34
- secret: string; /** User attached to ctx.state.user for system calls. */
33
+ secret: string;
34
+ /** User attached to ctx.state.user for system calls. */
35
35
  user: AuthenticatedUser;
36
36
  };
37
37
  type OAuthOptions = {
@@ -59,7 +59,8 @@ type OAuthOptions = {
59
59
  requiredScopes?: string[];
60
60
  };
61
61
  type AuthMiddlewareOptions = {
62
- /** Ordered list of strategies to attempt. First match wins. */strategies: AuthStrategy[];
62
+ /** Ordered list of strategies to attempt. First match wins. */
63
+ strategies: AuthStrategy[];
63
64
  jwt?: JwtOptions;
64
65
  apiToken?: ApiTokenOptions;
65
66
  system?: SystemOptions;
@@ -91,7 +92,7 @@ type AuthMiddlewareOptions = {
91
92
  * header, RFC 9728 when `resourceMetadataUrl` is set) for missing/invalid
92
93
  * tokens, and `403` when a verified token is missing a required scope.
93
94
  */
94
- declare const authMiddleware: (options: AuthMiddlewareOptions) => (ctx: Context, next: Next) => Promise<void>;
95
+ export declare const authMiddleware: (options: AuthMiddlewareOptions) => (ctx: Context, next: Next) => Promise<void>;
95
96
  //#endregion
96
97
  //#region src/emailAuth.d.ts
97
98
  /**
@@ -128,7 +129,7 @@ declare const authMiddleware: (options: AuthMiddlewareOptions) => (ctx: Context,
128
129
  * );
129
130
  * ```
130
131
  */
131
- declare const emailAuth: (options: EmailAuthOptions$1 & {
132
+ export declare const emailAuth: (options: EmailAuthOptions$1 & {
132
133
  /**
133
134
  * Prefix applied to every mounted path, e.g. `/v1`. Useful when the app
134
135
  * versions its API and the engine's default paths are otherwise fine.
@@ -156,7 +157,7 @@ declare const emailAuth: (options: EmailAuthOptions$1 & {
156
157
  * app.use(oauthServer({ issuer, clientStore, authCodeStore, issueTokens, onAuthorize }).routes());
157
158
  * ```
158
159
  */
159
- declare const oauthServer: (options: OAuthServerOptions$1) => Router;
160
+ export declare const oauthServer: (options: OAuthServerOptions$1) => Router;
160
161
  /**
161
162
  * Koa middleware that serves the RFC 9728 Protected Resource Metadata
162
163
  * document. Mount it **before** `authMiddleware` so the discovery endpoint
@@ -166,9 +167,12 @@ declare const oauthServer: (options: OAuthServerOptions$1) => Router;
166
167
  * the resource: the root, plus the path-derived location of RFC 9728 §3.1 when
167
168
  * the resource identifier carries a path.
168
169
  */
169
- declare const createProtectedResourceMetadataMiddleware: (args: {
170
- /** The protected resource's identifier URI. */resource: string; /** Authorization server issuer URIs that issue tokens for this resource. */
171
- authorizationServers: string[]; /** Scopes this resource accepts, advertised as `scopes_supported`. */
170
+ export declare const createProtectedResourceMetadataMiddleware: (args: {
171
+ /** The protected resource's identifier URI. */
172
+ resource: string;
173
+ /** Authorization server issuer URIs that issue tokens for this resource. */
174
+ authorizationServers: string[];
175
+ /** Scopes this resource accepts, advertised as `scopes_supported`. */
172
176
  scopesSupported?: string[];
173
177
  }) => Middleware;
174
178
  //#endregion
@@ -177,7 +181,7 @@ declare const createProtectedResourceMetadataMiddleware: (args: {
177
181
  * Returns true if origin matches any entry in the allowlist.
178
182
  * Strings are compared exactly; RegExps are tested.
179
183
  */
180
- declare const isOriginAllowed: (origin: string, allowedOrigins: Array<string | RegExp | undefined>) => boolean;
184
+ export declare const isOriginAllowed: (origin: string, allowedOrigins: Array<string | RegExp | undefined>) => boolean;
181
185
  //#endregion
182
186
  //#region src/requireAuth.d.ts
183
187
  /**
@@ -187,6 +191,6 @@ declare const isOriginAllowed: (origin: string, allowedOrigins: Array<string | R
187
191
  * @example
188
192
  * router.get('/me', requireAuth({ strategies: ['jwt', 'apiToken'] }), handler);
189
193
  */
190
- declare const requireAuth: (options: AuthMiddlewareOptions) => ((ctx: Context, next: Next) => Promise<void>);
194
+ export declare const requireAuth: (options: AuthMiddlewareOptions) => ((ctx: Context, next: Next) => Promise<void>);
191
195
  //#endregion
192
- export { type ApiTokenOptions, type AuthCodeStore, type AuthMiddlewareOptions, type AuthStrategy, type AuthenticatedUser, type AuthorizeRequest, type ClientStore, type EmailAuthDelivery, type EmailAuthErrorCode, type EmailAuthHandler, type EmailAuthHandlers, type EmailAuthHooks, type EmailAuthMode, type EmailAuthOptions, type EmailAuthPaths, type EmailAuthSession, type EmailAuthTtl, type EmailAuthUser, type EmailAuthUserStore, type EmailCodeOptions, type IssueTokensArgs, type IssuedTokens, type JwtOptions, type OAuthClient, type OAuthClientMetadata, type OAuthHandlers, type OAuthOptions, type OAuthServerOptions, type OnAuthorizeArgs, type OnAuthorizeResult, type OnRefreshTokenArgs, type OnRefreshTokenResult, type OneTimeTokenPurpose, type OneTimeTokenStore, type PasswordOptions, type ProtectedResourceMetadata, type RequestRateLimit, type RequestRateLimitStore, type StoredAuthorizationCode, type StoredOneTimeToken, type SystemOptions, authMiddleware, createEmailAuthHandlers, createOAuthHandlers, createProtectedResourceMetadataMiddleware, emailAuth, emailAuthErrorCodes, getWwwAuthenticateHeader, isOriginAllowed, normalizeEmail, oauthServer, protectedResourceMetadataDocument, protectedResourceMetadataPaths, protectedResourceMetadataUrl, requireAuth };
196
+ export { type ApiTokenOptions, type AuthCodeStore, type AuthMiddlewareOptions, type AuthStrategy, type AuthenticatedUser, type AuthorizeRequest, type ClientStore, type EmailAuthDelivery, type EmailAuthErrorCode, type EmailAuthHandler, type EmailAuthHandlers, type EmailAuthHooks, type EmailAuthMode, type EmailAuthOptions, type EmailAuthPaths, type EmailAuthSession, type EmailAuthTtl, type EmailAuthUser, type EmailAuthUserStore, type EmailCodeOptions, type IssueTokensArgs, type IssuedTokens, type JwtOptions, type OAuthClient, type OAuthClientMetadata, type OAuthHandlers, type OAuthOptions, type OAuthServerOptions, type OnAuthorizeArgs, type OnAuthorizeResult, type OnRefreshTokenArgs, type OnRefreshTokenResult, type OneTimeTokenPurpose, type OneTimeTokenStore, type PasswordOptions, type ProtectedResourceMetadata, type RequestRateLimit, type RequestRateLimitStore, type StoredAuthorizationCode, type StoredOneTimeToken, type SystemOptions, createEmailAuthHandlers, createOAuthHandlers, emailAuthErrorCodes, getWwwAuthenticateHeader, normalizeEmail, protectedResourceMetadataDocument, protectedResourceMetadataPaths, protectedResourceMetadataUrl };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/http-server-auth",
3
- "version": "0.9.0",
3
+ "version": "0.10.1",
4
4
  "description": "Authentication middleware for @ttoss/http-server",
5
5
  "keywords": [
6
6
  "auth",
@@ -32,18 +32,18 @@
32
32
  "dist"
33
33
  ],
34
34
  "dependencies": {
35
- "@ttoss/auth-core": "^0.18.0"
35
+ "@ttoss/auth-core": "^0.20.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/koa": "^3.0.3",
39
- "jest": "^30.4.2",
40
- "supertest": "^7.2.2",
41
- "tsdown": "^0.22.2",
42
- "@ttoss/config": "^1.41.0",
43
- "@ttoss/http-server": "^0.13.1"
39
+ "jest": "^30.5.2",
40
+ "supertest": "^7.3.1",
41
+ "tsdown": "^0.23.1",
42
+ "@ttoss/http-server": "^0.14.1",
43
+ "@ttoss/config": "^3.0.0"
44
44
  },
45
45
  "peerDependencies": {
46
- "@ttoss/http-server": "^0.13.1"
46
+ "@ttoss/http-server": "^0.14.1"
47
47
  },
48
48
  "publishConfig": {
49
49
  "access": "public",