@warlock.js/auth 4.0.48 → 4.0.58
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/cjs/commands/auth-cleanup-command.d.ts +10 -0
- package/cjs/commands/auth-cleanup-command.d.ts.map +1 -0
- package/cjs/commands/auth-cleanup-command.js +29 -0
- package/cjs/commands/auth-cleanup-command.js.map +1 -0
- package/cjs/commands/jwt-secret-generator-command.d.ts +2 -0
- package/cjs/commands/jwt-secret-generator-command.d.ts.map +1 -0
- package/cjs/commands/jwt-secret-generator-command.js +7 -0
- package/cjs/commands/jwt-secret-generator-command.js.map +1 -0
- package/cjs/contracts/auth-contract.d.ts +23 -0
- package/cjs/contracts/auth-contract.d.ts.map +1 -0
- package/cjs/contracts/index.d.ts +3 -0
- package/cjs/contracts/index.d.ts.map +1 -0
- package/cjs/contracts/types.d.ts +157 -0
- package/cjs/contracts/types.d.ts.map +1 -0
- package/cjs/contracts/types.js +20 -0
- package/cjs/contracts/types.js.map +1 -0
- package/cjs/index.d.ts +8 -0
- package/cjs/index.d.ts.map +1 -0
- package/cjs/index.js +1 -56
- package/cjs/index.js.map +1 -1
- package/cjs/middleware/auth.middleware.d.ts +2 -0
- package/cjs/middleware/auth.middleware.d.ts.map +1 -0
- package/cjs/middleware/auth.middleware.js +72 -0
- package/cjs/middleware/auth.middleware.js.map +1 -0
- package/cjs/middleware/index.d.ts +2 -0
- package/cjs/middleware/index.d.ts.map +1 -0
- package/cjs/models/access-token/access-token.d.ts +9 -0
- package/cjs/models/access-token/access-token.d.ts.map +1 -0
- package/cjs/models/access-token/access-token.js +18 -0
- package/cjs/models/access-token/access-token.js.map +1 -0
- package/cjs/models/access-token/index.d.ts +3 -0
- package/cjs/models/access-token/index.d.ts.map +1 -0
- package/cjs/models/access-token/migration.d.ts +3 -0
- package/cjs/models/access-token/migration.d.ts.map +1 -0
- package/cjs/models/access-token/migration.js +10 -0
- package/cjs/models/access-token/migration.js.map +1 -0
- package/cjs/models/auth.d.ts +54 -0
- package/cjs/models/auth.d.ts.map +1 -0
- package/cjs/models/auth.js +56 -0
- package/cjs/models/auth.js.map +1 -0
- package/cjs/models/casts/cast-password.d.ts +7 -0
- package/cjs/models/casts/cast-password.d.ts.map +1 -0
- package/cjs/models/casts/index.d.ts +2 -0
- package/cjs/models/casts/index.d.ts.map +1 -0
- package/cjs/models/index.d.ts +4 -0
- package/cjs/models/index.d.ts.map +1 -0
- package/cjs/models/refresh-token/index.d.ts +2 -0
- package/cjs/models/refresh-token/index.d.ts.map +1 -0
- package/cjs/models/refresh-token/migration.d.ts +3 -0
- package/cjs/models/refresh-token/migration.d.ts.map +1 -0
- package/cjs/models/refresh-token/refresh-token.d.ts +32 -0
- package/cjs/models/refresh-token/refresh-token.d.ts.map +1 -0
- package/cjs/models/refresh-token/refresh-token.js +53 -0
- package/cjs/models/refresh-token/refresh-token.js.map +1 -0
- package/cjs/services/auth-events.d.ts +85 -0
- package/cjs/services/auth-events.d.ts.map +1 -0
- package/cjs/services/auth-events.js +65 -0
- package/cjs/services/auth-events.js.map +1 -0
- package/cjs/services/auth.service.d.ts +91 -0
- package/cjs/services/auth.service.d.ts.map +1 -0
- package/cjs/services/auth.service.js +303 -0
- package/cjs/services/auth.service.js.map +1 -0
- package/cjs/services/generate-jwt-secret.d.ts +2 -0
- package/cjs/services/generate-jwt-secret.d.ts.map +1 -0
- package/cjs/services/generate-jwt-secret.js +47 -0
- package/cjs/services/generate-jwt-secret.js.map +1 -0
- package/cjs/services/index.d.ts +5 -0
- package/cjs/services/index.d.ts.map +1 -0
- package/cjs/services/jwt.d.ts +23 -0
- package/cjs/services/jwt.d.ts.map +1 -0
- package/cjs/services/jwt.js +39 -0
- package/cjs/services/jwt.js.map +1 -0
- package/cjs/utils/auth-error-codes.d.ts +18 -0
- package/cjs/utils/auth-error-codes.d.ts.map +1 -0
- package/cjs/utils/auth-error-codes.js +18 -0
- package/cjs/utils/auth-error-codes.js.map +1 -0
- package/cjs/utils/duration.d.ts +45 -0
- package/cjs/utils/duration.d.ts.map +1 -0
- package/cjs/utils/duration.js +93 -0
- package/cjs/utils/duration.js.map +1 -0
- package/cjs/utils/index.d.ts +3 -0
- package/cjs/utils/index.d.ts.map +1 -0
- package/esm/commands/auth-cleanup-command.d.ts +10 -0
- package/esm/commands/auth-cleanup-command.d.ts.map +1 -0
- package/esm/commands/auth-cleanup-command.js +29 -0
- package/esm/commands/auth-cleanup-command.js.map +1 -0
- package/esm/commands/jwt-secret-generator-command.d.ts +2 -0
- package/esm/commands/jwt-secret-generator-command.d.ts.map +1 -0
- package/esm/commands/jwt-secret-generator-command.js +7 -0
- package/esm/commands/jwt-secret-generator-command.js.map +1 -0
- package/esm/contracts/auth-contract.d.ts +23 -0
- package/esm/contracts/auth-contract.d.ts.map +1 -0
- package/esm/contracts/index.d.ts +3 -0
- package/esm/contracts/index.d.ts.map +1 -0
- package/esm/contracts/types.d.ts +157 -0
- package/esm/contracts/types.d.ts.map +1 -0
- package/esm/contracts/types.js +20 -0
- package/esm/contracts/types.js.map +1 -0
- package/esm/index.d.ts +8 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +1 -9
- package/esm/index.js.map +1 -1
- package/esm/middleware/auth.middleware.d.ts +2 -0
- package/esm/middleware/auth.middleware.d.ts.map +1 -0
- package/esm/middleware/auth.middleware.js +72 -0
- package/esm/middleware/auth.middleware.js.map +1 -0
- package/esm/middleware/index.d.ts +2 -0
- package/esm/middleware/index.d.ts.map +1 -0
- package/esm/models/access-token/access-token.d.ts +9 -0
- package/esm/models/access-token/access-token.d.ts.map +1 -0
- package/esm/models/access-token/access-token.js +18 -0
- package/esm/models/access-token/access-token.js.map +1 -0
- package/esm/models/access-token/index.d.ts +3 -0
- package/esm/models/access-token/index.d.ts.map +1 -0
- package/esm/models/access-token/migration.d.ts +3 -0
- package/esm/models/access-token/migration.d.ts.map +1 -0
- package/esm/models/access-token/migration.js +10 -0
- package/esm/models/access-token/migration.js.map +1 -0
- package/esm/models/auth.d.ts +54 -0
- package/esm/models/auth.d.ts.map +1 -0
- package/esm/models/auth.js +56 -0
- package/esm/models/auth.js.map +1 -0
- package/esm/models/casts/cast-password.d.ts +7 -0
- package/esm/models/casts/cast-password.d.ts.map +1 -0
- package/esm/models/casts/index.d.ts +2 -0
- package/esm/models/casts/index.d.ts.map +1 -0
- package/esm/models/index.d.ts +4 -0
- package/esm/models/index.d.ts.map +1 -0
- package/esm/models/refresh-token/index.d.ts +2 -0
- package/esm/models/refresh-token/index.d.ts.map +1 -0
- package/esm/models/refresh-token/migration.d.ts +3 -0
- package/esm/models/refresh-token/migration.d.ts.map +1 -0
- package/esm/models/refresh-token/refresh-token.d.ts +32 -0
- package/esm/models/refresh-token/refresh-token.d.ts.map +1 -0
- package/esm/models/refresh-token/refresh-token.js +53 -0
- package/esm/models/refresh-token/refresh-token.js.map +1 -0
- package/esm/services/auth-events.d.ts +85 -0
- package/esm/services/auth-events.d.ts.map +1 -0
- package/esm/services/auth-events.js +65 -0
- package/esm/services/auth-events.js.map +1 -0
- package/esm/services/auth.service.d.ts +91 -0
- package/esm/services/auth.service.d.ts.map +1 -0
- package/esm/services/auth.service.js +303 -0
- package/esm/services/auth.service.js.map +1 -0
- package/esm/services/generate-jwt-secret.d.ts +2 -0
- package/esm/services/generate-jwt-secret.d.ts.map +1 -0
- package/esm/services/generate-jwt-secret.js +47 -0
- package/esm/services/generate-jwt-secret.js.map +1 -0
- package/esm/services/index.d.ts +5 -0
- package/esm/services/index.d.ts.map +1 -0
- package/esm/services/jwt.d.ts +23 -0
- package/esm/services/jwt.d.ts.map +1 -0
- package/esm/services/jwt.js +39 -0
- package/esm/services/jwt.js.map +1 -0
- package/esm/utils/auth-error-codes.d.ts +18 -0
- package/esm/utils/auth-error-codes.d.ts.map +1 -0
- package/esm/utils/auth-error-codes.js +18 -0
- package/esm/utils/auth-error-codes.js.map +1 -0
- package/esm/utils/duration.d.ts +45 -0
- package/esm/utils/duration.d.ts.map +1 -0
- package/esm/utils/duration.js +93 -0
- package/esm/utils/duration.js.map +1 -0
- package/esm/utils/index.d.ts +3 -0
- package/esm/utils/index.d.ts.map +1 -0
- package/package.json +35 -48
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-cleanup-command.d.ts","sourceRoot":"","sources":["../../src/commands/auth-cleanup-command.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,QAqBzC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';var copper=require('@mongez/copper'),core=require('@warlock.js/core'),auth_service=require('../services/auth.service.js');/**
|
|
2
|
+
* Register the auth:cleanup CLI command
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```bash
|
|
6
|
+
* warlock auth:cleanup
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
function registerAuthCleanupCommand() {
|
|
10
|
+
return core.command({
|
|
11
|
+
name: "auth.cleanup",
|
|
12
|
+
description: "Remove expired refresh tokens from the database",
|
|
13
|
+
preload: {
|
|
14
|
+
env: true,
|
|
15
|
+
config: ["auth", "database"],
|
|
16
|
+
connectors: ["database"],
|
|
17
|
+
},
|
|
18
|
+
action: async () => {
|
|
19
|
+
console.log(copper.colors.cyan("🧹 Cleaning up expired tokens..."));
|
|
20
|
+
const count = await auth_service.authService.cleanupExpiredTokens();
|
|
21
|
+
if (count === 0) {
|
|
22
|
+
console.log(copper.colors.green("✅ No expired tokens found."));
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
console.log(copper.colors.green(`✅ Removed ${count} expired token(s).`));
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}exports.registerAuthCleanupCommand=registerAuthCleanupCommand;//# sourceMappingURL=auth-cleanup-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-cleanup-command.js","sources":["../../src/commands/auth-cleanup-command.ts"],"sourcesContent":[null],"names":["command","colors","authService"],"mappings":"uIAIA;;;;;;;AAOG;SACa,0BAA0B,GAAA;AACxC,IAAA,OAAOA,YAAO,CAAC;AACb,QAAA,IAAI,EAAE,cAAc;AACpB,QAAA,WAAW,EAAE,iDAAiD;AAC9D,QAAA,OAAO,EAAE;AACP,YAAA,GAAG,EAAE,IAAI;AACT,YAAA,MAAM,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC;YAC5B,UAAU,EAAE,CAAC,UAAU,CAAC;AACzB,SAAA;QACD,MAAM,EAAE,YAAW;YACjB,OAAO,CAAC,GAAG,CAACC,aAAM,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC,CAAC;AAE7D,YAAA,MAAM,KAAK,GAAG,MAAMC,wBAAW,CAAC,oBAAoB,EAAE,CAAC;YAEvD,IAAI,KAAK,KAAK,CAAC,EAAE;gBACf,OAAO,CAAC,GAAG,CAACD,aAAM,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC,CAAC;AACzD,aAAA;AAAM,iBAAA;AACL,gBAAA,OAAO,CAAC,GAAG,CAACA,aAAM,CAAC,KAAK,CAAC,CAAA,UAAA,EAAa,KAAK,CAAA,kBAAA,CAAoB,CAAC,CAAC,CAAC;AACnE,aAAA;SACF;AACF,KAAA,CAAC,CAAC;AACL"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt-secret-generator-command.d.ts","sourceRoot":"","sources":["../../src/commands/jwt-secret-generator-command.ts"],"names":[],"mappings":"AAGA,wBAAgB,iCAAiC,QAMhD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use strict';var core=require('@warlock.js/core'),generateJwtSecret=require('../services/generate-jwt-secret.js');function registerJWTSecretGeneratorCommand() {
|
|
2
|
+
return core.command({
|
|
3
|
+
name: "jwt.generate",
|
|
4
|
+
description: "Generate JWT Secret key in .env file",
|
|
5
|
+
action: generateJwtSecret.generateJWTSecret,
|
|
6
|
+
});
|
|
7
|
+
}exports.registerJWTSecretGeneratorCommand=registerJWTSecretGeneratorCommand;//# sourceMappingURL=jwt-secret-generator-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt-secret-generator-command.js","sources":["../../src/commands/jwt-secret-generator-command.ts"],"sourcesContent":[null],"names":["command","generateJWTSecret"],"mappings":"2HAGgB,iCAAiC,GAAA;AAC/C,IAAA,OAAOA,YAAO,CAAC;AACb,QAAA,IAAI,EAAE,cAAc;AACpB,QAAA,WAAW,EAAE,sCAAsC;AACnD,QAAA,MAAM,EAAEC,mCAAiB;AAC1B,KAAA,CAAC,CAAC;AACL"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface Authenticable {
|
|
2
|
+
/**
|
|
3
|
+
* Generate access token
|
|
4
|
+
*/
|
|
5
|
+
generateAccessToken(): Promise<string>;
|
|
6
|
+
/**
|
|
7
|
+
* Generate refresh token
|
|
8
|
+
*/
|
|
9
|
+
generateRefreshToken(): Promise<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Change password
|
|
12
|
+
*/
|
|
13
|
+
changePassword(password: string): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Verify Password
|
|
16
|
+
*/
|
|
17
|
+
verifyPassword(password: string): Promise<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Get user type
|
|
20
|
+
*/
|
|
21
|
+
getUserType(): string;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=auth-contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-contract.d.ts","sourceRoot":"","sources":["../../src/contracts/auth-contract.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAEvC;;OAEG;IACH,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAExC;;OAEG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhD;;OAEG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEnD;;OAEG;IACH,WAAW,IAAI,MAAM,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { ChildModel } from "@warlock.js/cascade";
|
|
2
|
+
import { type Algorithm } from "fast-jwt";
|
|
3
|
+
import type { Auth } from "../models/auth";
|
|
4
|
+
import type { Duration, ExpiresIn } from "../utils/duration";
|
|
5
|
+
/**
|
|
6
|
+
* Symbol to indicate no expiration for tokens
|
|
7
|
+
* Use this when you explicitly want tokens to never expire
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // src/config/auth.ts
|
|
12
|
+
* import { NO_EXPIRATION, type AuthConfigurations } from "@warlock.js/auth";
|
|
13
|
+
*
|
|
14
|
+
* const authConfigurations: AuthConfigurations = {
|
|
15
|
+
* jwt: {
|
|
16
|
+
* secret: env("JWT_SECRET"),
|
|
17
|
+
* expiresIn: NO_EXPIRATION, // Token never expires
|
|
18
|
+
* },
|
|
19
|
+
* };
|
|
20
|
+
*
|
|
21
|
+
* export default authConfigurations;
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare const NO_EXPIRATION: unique symbol;
|
|
25
|
+
/**
|
|
26
|
+
* Behavior when logout is called without a refresh token
|
|
27
|
+
* - "revoke-all": Revoke all refresh tokens for the user (secure default)
|
|
28
|
+
* - "error": Return an error requiring the refresh token
|
|
29
|
+
*/
|
|
30
|
+
export type LogoutWithoutTokenBehavior = "revoke-all" | "error";
|
|
31
|
+
export type AuthConfigurations = {
|
|
32
|
+
/**
|
|
33
|
+
* Define all user types
|
|
34
|
+
* This is important to differentiate between user types when validating and generating tokens
|
|
35
|
+
*/
|
|
36
|
+
userType: {
|
|
37
|
+
[userType: string]: ChildModel<Auth>;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* JWT configurations
|
|
41
|
+
*/
|
|
42
|
+
jwt: {
|
|
43
|
+
/**
|
|
44
|
+
* JWT secret key for signing access tokens
|
|
45
|
+
*/
|
|
46
|
+
secret: string;
|
|
47
|
+
/**
|
|
48
|
+
* JWT algorithm
|
|
49
|
+
* @default "HS256"
|
|
50
|
+
*/
|
|
51
|
+
algorithm?: Algorithm;
|
|
52
|
+
/**
|
|
53
|
+
* Access token expiration time
|
|
54
|
+
* Supports Duration object, string format, or NO_EXPIRATION
|
|
55
|
+
* @example { hours: 1 }, { days: 7, hours: 12 }, "1h", "1d 2h", NO_EXPIRATION
|
|
56
|
+
* @default { hours: 1 }
|
|
57
|
+
*/
|
|
58
|
+
expiresIn?: ExpiresIn;
|
|
59
|
+
/**
|
|
60
|
+
* Refresh token configurations
|
|
61
|
+
*/
|
|
62
|
+
refresh?: {
|
|
63
|
+
/**
|
|
64
|
+
* Separate secret for refresh tokens (recommended for security)
|
|
65
|
+
* If not provided, falls back to main JWT secret
|
|
66
|
+
*/
|
|
67
|
+
secret?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Enable refresh token
|
|
70
|
+
* @default true
|
|
71
|
+
*/
|
|
72
|
+
enabled?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Refresh token expiration time
|
|
75
|
+
* Supports Duration object or string format
|
|
76
|
+
* @example { days: 7 }, { weeks: 1 }, "7d", "1w"
|
|
77
|
+
* @default { days: 7 }
|
|
78
|
+
*/
|
|
79
|
+
expiresIn?: Duration | string | number;
|
|
80
|
+
/**
|
|
81
|
+
* Enable token rotation (issue new refresh token on each use)
|
|
82
|
+
* Old refresh token is invalidated after use
|
|
83
|
+
* @default true
|
|
84
|
+
*/
|
|
85
|
+
rotation?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Maximum number of active refresh tokens per user
|
|
88
|
+
* When exceeded, oldest tokens are revoked
|
|
89
|
+
* @default 5
|
|
90
|
+
*/
|
|
91
|
+
maxPerUser?: number;
|
|
92
|
+
/**
|
|
93
|
+
* Behavior when logout is called without a refresh token
|
|
94
|
+
* - "revoke-all": Revoke all tokens for security (default)
|
|
95
|
+
* - "error": Require refresh token, return error if missing
|
|
96
|
+
* @default "revoke-all"
|
|
97
|
+
*/
|
|
98
|
+
logoutWithoutToken?: LogoutWithoutTokenBehavior;
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Password configurations
|
|
103
|
+
*/
|
|
104
|
+
password?: {
|
|
105
|
+
/**
|
|
106
|
+
* Password salt
|
|
107
|
+
* The higher the salt, the more secure the password is
|
|
108
|
+
* But, it will take more time to generate the password
|
|
109
|
+
* @default 12
|
|
110
|
+
*/
|
|
111
|
+
salt?: number;
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Token pair returned after login or token refresh
|
|
116
|
+
*/
|
|
117
|
+
export type TokenPair = {
|
|
118
|
+
/**
|
|
119
|
+
* JWT access token (short-lived)
|
|
120
|
+
*/
|
|
121
|
+
accessToken: string;
|
|
122
|
+
/**
|
|
123
|
+
* JWT refresh token (long-lived)
|
|
124
|
+
*/
|
|
125
|
+
refreshToken: string;
|
|
126
|
+
/**
|
|
127
|
+
* Access token expiration time in seconds or time string
|
|
128
|
+
*/
|
|
129
|
+
expiresIn: number | string;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Device information for session tracking
|
|
133
|
+
*/
|
|
134
|
+
export type DeviceInfo = {
|
|
135
|
+
/**
|
|
136
|
+
* User agent string from request
|
|
137
|
+
*/
|
|
138
|
+
userAgent?: string;
|
|
139
|
+
/**
|
|
140
|
+
* Client IP address
|
|
141
|
+
*/
|
|
142
|
+
ip?: string;
|
|
143
|
+
/**
|
|
144
|
+
* Optional device identifier
|
|
145
|
+
*/
|
|
146
|
+
deviceId?: string;
|
|
147
|
+
/**
|
|
148
|
+
* Token family ID (for rotation tracking)
|
|
149
|
+
* @internal
|
|
150
|
+
*/
|
|
151
|
+
familyId?: string;
|
|
152
|
+
/**
|
|
153
|
+
* Access token payload
|
|
154
|
+
*/
|
|
155
|
+
payload?: Record<string, any>;
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/contracts/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE7D;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,aAAa,eAA0B,CAAC;AAErD;;;;GAIG;AACH,MAAM,MAAM,0BAA0B,GAAG,YAAY,GAAG,OAAO,CAAC;AAEhE,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,QAAQ,EAAE;QACR,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;KACtC,CAAC;IACF;;OAEG;IACH,GAAG,EAAE;QACH;;WAEG;QACH,MAAM,EAAE,MAAM,CAAC;QACf;;;WAGG;QACH,SAAS,CAAC,EAAE,SAAS,CAAC;QACtB;;;;;WAKG;QACH,SAAS,CAAC,EAAE,SAAS,CAAC;QACtB;;WAEG;QACH,OAAO,CAAC,EAAE;YACR;;;eAGG;YACH,MAAM,CAAC,EAAE,MAAM,CAAC;YAChB;;;eAGG;YACH,OAAO,CAAC,EAAE,OAAO,CAAC;YAClB;;;;;eAKG;YACH,SAAS,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;YACvC;;;;eAIG;YACH,QAAQ,CAAC,EAAE,OAAO,CAAC;YACnB;;;;eAIG;YACH,UAAU,CAAC,EAAE,MAAM,CAAC;YACpB;;;;;eAKG;YACH,kBAAkB,CAAC,EAAE,0BAA0B,CAAC;SACjD,CAAC;KACH,CAAC;IACF;;OAEG;IACH,QAAQ,CAAC,EAAE;QACT;;;;;WAKG;QACH,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';/**
|
|
2
|
+
* Symbol to indicate no expiration for tokens
|
|
3
|
+
* Use this when you explicitly want tokens to never expire
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* // src/config/auth.ts
|
|
8
|
+
* import { NO_EXPIRATION, type AuthConfigurations } from "@warlock.js/auth";
|
|
9
|
+
*
|
|
10
|
+
* const authConfigurations: AuthConfigurations = {
|
|
11
|
+
* jwt: {
|
|
12
|
+
* secret: env("JWT_SECRET"),
|
|
13
|
+
* expiresIn: NO_EXPIRATION, // Token never expires
|
|
14
|
+
* },
|
|
15
|
+
* };
|
|
16
|
+
*
|
|
17
|
+
* export default authConfigurations;
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
const NO_EXPIRATION = Symbol("NO_EXPIRATION");exports.NO_EXPIRATION=NO_EXPIRATION;//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../src/contracts/types.ts"],"sourcesContent":[null],"names":[],"mappings":"aAKA;;;;;;;;;;;;;;;;;;AAkBG;MACU,aAAa,GAAG,MAAM,CAAC,eAAe"}
|
package/cjs/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./commands/auth-cleanup-command";
|
|
2
|
+
export * from "./commands/jwt-secret-generator-command";
|
|
3
|
+
export * from "./contracts";
|
|
4
|
+
export * from "./middleware";
|
|
5
|
+
export * from "./models";
|
|
6
|
+
export * from "./services";
|
|
7
|
+
export * from "./utils";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,yCAAyC,CAAC;AACxD,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
|
package/cjs/index.js
CHANGED
|
@@ -1,56 +1 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var authCleanupCommand = require('./commands/auth-cleanup-command');
|
|
4
|
-
var jwtSecretGeneratorCommand = require('./commands/jwt-secret-generator-command');
|
|
5
|
-
var contracts = require('./contracts');
|
|
6
|
-
var middleware = require('./middleware');
|
|
7
|
-
var models = require('./models');
|
|
8
|
-
var services = require('./services');
|
|
9
|
-
var utils = require('./utils');
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Object.keys(authCleanupCommand).forEach(function (k) {
|
|
14
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function () { return authCleanupCommand[k]; }
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
Object.keys(jwtSecretGeneratorCommand).forEach(function (k) {
|
|
20
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
get: function () { return jwtSecretGeneratorCommand[k]; }
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
Object.keys(contracts).forEach(function (k) {
|
|
26
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
27
|
-
enumerable: true,
|
|
28
|
-
get: function () { return contracts[k]; }
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
Object.keys(middleware).forEach(function (k) {
|
|
32
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () { return middleware[k]; }
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
Object.keys(models).forEach(function (k) {
|
|
38
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
39
|
-
enumerable: true,
|
|
40
|
-
get: function () { return models[k]; }
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
Object.keys(services).forEach(function (k) {
|
|
44
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
45
|
-
enumerable: true,
|
|
46
|
-
get: function () { return services[k]; }
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
Object.keys(utils).forEach(function (k) {
|
|
50
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
51
|
-
enumerable: true,
|
|
52
|
-
get: function () { return utils[k]; }
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
//# sourceMappingURL=index.js.map
|
|
56
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
'use strict';var authCleanupCommand=require('./commands/auth-cleanup-command.js'),jwtSecretGeneratorCommand=require('./commands/jwt-secret-generator-command.js'),types=require('./contracts/types.js'),auth_middleware=require('./middleware/auth.middleware.js'),accessToken=require('./models/access-token/access-token.js');require('./models/access-token/migration.js');var auth=require('./models/auth.js'),refreshToken=require('./models/refresh-token/refresh-token.js'),authEvents=require('./services/auth-events.js'),auth_service=require('./services/auth.service.js'),generateJwtSecret=require('./services/generate-jwt-secret.js'),jwt=require('./services/jwt.js'),authErrorCodes=require('./utils/auth-error-codes.js'),duration=require('./utils/duration.js');exports.registerAuthCleanupCommand=authCleanupCommand.registerAuthCleanupCommand;exports.registerJWTSecretGeneratorCommand=jwtSecretGeneratorCommand.registerJWTSecretGeneratorCommand;exports.NO_EXPIRATION=types.NO_EXPIRATION;exports.authMiddleware=auth_middleware.authMiddleware;exports.AccessToken=accessToken.AccessToken;exports.Auth=auth.Auth;exports.RefreshToken=refreshToken.RefreshToken;exports.authEvents=authEvents.authEvents;exports.authService=auth_service.authService;exports.generateJWTSecret=generateJwtSecret.generateJWTSecret;exports.jwt=jwt.jwt;Object.defineProperty(exports,'AuthErrorCodes',{enumerable:true,get:function(){return authErrorCodes.AuthErrorCodes}});exports.parseExpirationToMs=duration.parseExpirationToMs;exports.toJwtExpiresIn=duration.toJwtExpiresIn;//# sourceMappingURL=index.js.map
|
package/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.middleware.d.ts","sourceRoot":"","sources":["../../src/middleware/auth.middleware.ts"],"names":[],"mappings":"AAMA,wBAAgB,cAAc,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,cAsFjE"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';var core=require('@warlock.js/core'),logger=require('@warlock.js/logger'),accessToken=require('../models/access-token/access-token.js');require('../models/access-token/migration.js');var jwt=require('../services/jwt.js'),authErrorCodes=require('../utils/auth-error-codes.js');function authMiddleware(allowedUserType) {
|
|
2
|
+
const allowedTypes = !allowedUserType
|
|
3
|
+
? []
|
|
4
|
+
: Array.isArray(allowedUserType)
|
|
5
|
+
? allowedUserType
|
|
6
|
+
: [allowedUserType];
|
|
7
|
+
const auth = async (request, response) => {
|
|
8
|
+
try {
|
|
9
|
+
const authorizationValue = request.authorizationValue;
|
|
10
|
+
if (!allowedTypes.length && !authorizationValue)
|
|
11
|
+
return;
|
|
12
|
+
if (!authorizationValue) {
|
|
13
|
+
return response.unauthorized({
|
|
14
|
+
error: core.t("auth.errors.missingAccessToken"),
|
|
15
|
+
errorCode: authErrorCodes.AuthErrorCodes.MissingAccessToken,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
// get current user jwt
|
|
19
|
+
const user = await jwt.jwt.verify(authorizationValue);
|
|
20
|
+
// store decoded access token object in request object
|
|
21
|
+
request.decodedAccessToken = user;
|
|
22
|
+
// use our own jwt verify to verify the token
|
|
23
|
+
const accessToken$1 = await accessToken.AccessToken.first({
|
|
24
|
+
token: authorizationValue,
|
|
25
|
+
});
|
|
26
|
+
if (!accessToken$1) {
|
|
27
|
+
return response.unauthorized({
|
|
28
|
+
error: core.t("auth.errors.invalidAccessToken"),
|
|
29
|
+
errorCode: authErrorCodes.AuthErrorCodes.InvalidAccessToken,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
// now, we need to get an instance of user using its corresponding model
|
|
33
|
+
const userType = user.userType || accessToken$1.get("userType");
|
|
34
|
+
// check if the user type is allowed
|
|
35
|
+
if (allowedTypes.length && !allowedTypes.includes(userType)) {
|
|
36
|
+
return response.unauthorized({
|
|
37
|
+
error: core.t("auth.errors.unauthorized"),
|
|
38
|
+
errorCode: authErrorCodes.AuthErrorCodes.Unauthorized,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
// get user model class
|
|
42
|
+
const UserModel = core.config.key(`auth.userType.${userType}`);
|
|
43
|
+
if (!UserModel) {
|
|
44
|
+
throw new Error(`User type ${userType} is unknown type.`);
|
|
45
|
+
}
|
|
46
|
+
// get user model instance
|
|
47
|
+
const currentUser = await UserModel.find(user.id);
|
|
48
|
+
if (!currentUser) {
|
|
49
|
+
accessToken$1.destroy();
|
|
50
|
+
return response.unauthorized({
|
|
51
|
+
error: core.t("auth.errors.invalidAccessToken"),
|
|
52
|
+
errorCode: authErrorCodes.AuthErrorCodes.InvalidAccessToken,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
// update last access
|
|
56
|
+
accessToken$1.set("lastAccess", new Date());
|
|
57
|
+
await accessToken$1.save({ skipEvents: true });
|
|
58
|
+
// set current user
|
|
59
|
+
request.user = currentUser;
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
logger.log.error("http", "auth", err);
|
|
63
|
+
// unset current user
|
|
64
|
+
request.clearCurrentUser();
|
|
65
|
+
return response.unauthorized({
|
|
66
|
+
error: core.t("auth.errors.invalidAccessToken"),
|
|
67
|
+
errorCode: authErrorCodes.AuthErrorCodes.InvalidAccessToken,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
return auth;
|
|
72
|
+
}exports.authMiddleware=authMiddleware;//# sourceMappingURL=auth.middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.middleware.js","sources":["../../src/middleware/auth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3B,gBAAA,KAAK,EAAEN,MAAC,CAAC,gCAAgC,CAAC;gBAC1C,SAAS,EAAEC,6BAAc,CAAC,kBAAkB;AAC7C,aAAA,CAAC,CAAC;AACJ,SAAA;AACH,KAAC,CAAC;AAEF,IAAA,OAAO,IAAI,CAAC;AACd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-token.d.ts","sourceRoot":"","sources":["../../../src/models/access-token/access-token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAe5C,qBAAa,WAAY,SAAQ,KAAK;IACpC;;OAEG;IACH,OAAc,KAAK,SAAkB;IAErC,OAAc,MAAM,MAAqB;CAC1C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';var cascade=require('@warlock.js/cascade'),seal=require('@warlock.js/seal');const accessTokenSchema = seal.v.object({
|
|
2
|
+
token: seal.v.string().required(),
|
|
3
|
+
lastAccess: seal.v.date().default(() => new Date()),
|
|
4
|
+
user: seal.v
|
|
5
|
+
.object({
|
|
6
|
+
id: seal.v.number().required(),
|
|
7
|
+
userType: seal.v.string(),
|
|
8
|
+
})
|
|
9
|
+
.allowUnknown()
|
|
10
|
+
.required(),
|
|
11
|
+
});
|
|
12
|
+
class AccessToken extends cascade.Model {
|
|
13
|
+
/**
|
|
14
|
+
* {@inheritDoc}
|
|
15
|
+
*/
|
|
16
|
+
static table = "accessTokens";
|
|
17
|
+
static schema = accessTokenSchema;
|
|
18
|
+
}exports.AccessToken=AccessToken;//# sourceMappingURL=access-token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-token.js","sources":["../../../src/models/access-token/access-token.ts"],"sourcesContent":[null],"names":["v","Model"],"mappings":"yFAGA,MAAM,iBAAiB,GAAGA,MAAC,CAAC,MAAM,CAAC;AACjC,IAAA,KAAK,EAAEA,MAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;AAC5B,IAAA,UAAU,EAAEA,MAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;AAC9C,IAAA,IAAI,EAAEA,MAAC;AACJ,SAAA,MAAM,CAAC;AACN,QAAA,EAAE,EAAEA,MAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;AACzB,QAAA,QAAQ,EAAEA,MAAC,CAAC,MAAM,EAAE;KACrB,CAAC;AACD,SAAA,YAAY,EAAE;AACd,SAAA,QAAQ,EAAE;AACd,CAAA,CAAC,CAAC;AAEG,MAAO,WAAY,SAAQC,aAAK,CAAA;AACpC;;AAEG;AACI,IAAA,OAAO,KAAK,GAAG,cAAc,CAAC;AAE9B,IAAA,OAAO,MAAM,GAAG,iBAAiB,CAAC;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/models/access-token/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../../src/models/access-token/migration.ts"],"names":[],"mappings":";AAGA,wBASG"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';var cascade=require('@warlock.js/cascade'),accessToken=require('./access-token.js');cascade.migrate(accessToken.AccessToken, {
|
|
2
|
+
name: "accessToken",
|
|
3
|
+
up() {
|
|
4
|
+
this.string("accessToken").index();
|
|
5
|
+
this.date("lastAccess");
|
|
6
|
+
},
|
|
7
|
+
down() {
|
|
8
|
+
this.dropIndex("token");
|
|
9
|
+
},
|
|
10
|
+
});//# sourceMappingURL=migration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.js","sources":["../../../src/models/access-token/migration.ts"],"sourcesContent":[null],"names":["migrate","AccessToken"],"mappings":"iGAGeA,eAAO,CAACC,uBAAW,EAAE;AAClC,IAAA,IAAI,EAAE,aAAa;IACnB,EAAE,GAAA;QACA,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,KAAK,EAAE,CAAC;AACnC,QAAA,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;KACzB;IACD,IAAI,GAAA;AACF,QAAA,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;KACzB;AACF,CAAA,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type ChildModel, Model, type ModelSchema } from "@warlock.js/cascade";
|
|
2
|
+
import type { DeviceInfo, TokenPair } from "../contracts/types";
|
|
3
|
+
import type { RefreshToken } from "./refresh-token/refresh-token";
|
|
4
|
+
export declare abstract class Auth<Schema extends ModelSchema = ModelSchema> extends Model<Schema> {
|
|
5
|
+
/**
|
|
6
|
+
* Get user type
|
|
7
|
+
*/
|
|
8
|
+
abstract get userType(): string;
|
|
9
|
+
/**
|
|
10
|
+
* Get access token payload
|
|
11
|
+
*/
|
|
12
|
+
accessTokenPayload(): {
|
|
13
|
+
id: any;
|
|
14
|
+
_id: any;
|
|
15
|
+
userType: string;
|
|
16
|
+
/**
|
|
17
|
+
* Generate access token
|
|
18
|
+
*/
|
|
19
|
+
createdAt: number;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Create both access and refresh tokens
|
|
23
|
+
*/
|
|
24
|
+
createTokenPair(deviceInfo?: DeviceInfo): Promise<TokenPair>;
|
|
25
|
+
/**
|
|
26
|
+
* Generate access token
|
|
27
|
+
*/
|
|
28
|
+
generateAccessToken(data?: any): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Generate refresh token
|
|
31
|
+
*/
|
|
32
|
+
generateRefreshToken(deviceInfo?: DeviceInfo): Promise<RefreshToken>;
|
|
33
|
+
/**
|
|
34
|
+
* Remove current access token
|
|
35
|
+
*/
|
|
36
|
+
removeAccessToken(token: string): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Revoke all tokens (logout from all devices)
|
|
39
|
+
*/
|
|
40
|
+
revokeAllTokens(): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Get active sessions
|
|
43
|
+
*/
|
|
44
|
+
activeSessions(): Promise<RefreshToken[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Attempt to login the user
|
|
47
|
+
*/
|
|
48
|
+
static attempt(this: ChildModel<Auth>, data: any): Promise<Auth | null>;
|
|
49
|
+
/**
|
|
50
|
+
* Confirm password
|
|
51
|
+
*/
|
|
52
|
+
confirmPassword(password: string): boolean;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/models/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEhE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElE,8BAAsB,IAAI,CAAC,MAAM,SAAS,WAAW,GAAG,WAAW,CAAE,SAAQ,KAAK,CAAC,MAAM,CAAC;IACxF;;OAEG;IACH,aAAoB,QAAQ,IAAI,MAAM,CAAC;IAEvC;;OAEG;IACI,kBAAkB;;;;QAWzB;;WAEG;;;IATH;;OAEG;IACU,eAAe,CAAC,UAAU,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;IAIzE;;OAEG;IACU,mBAAmB,CAAC,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAI7D;;OAEG;IACU,oBAAo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