@riocrypto/common-server 1.0.2302 → 1.0.2304

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.
@@ -82,7 +82,17 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
82
82
  const payload = jsonwebtoken_1.default.verify(adminAccessToken, ADMIN_ACCESS_TOKEN_SECRET);
83
83
  const adminAuth = yield AdminAuth.findById(payload.id);
84
84
  if (adminAuth) {
85
- req.adminAuth = adminAuth;
85
+ // Check if token version matches (for server-side invalidation)
86
+ if (payload.tokenVersion !== undefined &&
87
+ adminAuth.tokenVersion !== undefined) {
88
+ if (payload.tokenVersion >= adminAuth.tokenVersion) {
89
+ req.adminAuth = adminAuth;
90
+ }
91
+ }
92
+ else {
93
+ // Backward compatibility for tokens without version
94
+ req.adminAuth = adminAuth;
95
+ }
86
96
  }
87
97
  }
88
98
  catch (err) { }
@@ -123,9 +133,20 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
123
133
  }
124
134
  const payload = jsonwebtoken_1.default.verify(accessToken, ACCESS_TOKEN_SECRET);
125
135
  const auth = yield Auth.findById(payload.id);
126
- if (auth) {
127
- req.auth = auth;
128
- authId = auth.id;
136
+ if (auth && !auth.isDisabled) {
137
+ // Check if token version matches (for server-side invalidation)
138
+ if (payload.tokenVersion !== undefined &&
139
+ auth.tokenVersion !== undefined) {
140
+ if (payload.tokenVersion >= auth.tokenVersion) {
141
+ req.auth = auth;
142
+ authId = auth.id;
143
+ }
144
+ }
145
+ else {
146
+ // Backward compatibility for tokens without version
147
+ req.auth = auth;
148
+ authId = auth.id;
149
+ }
129
150
  }
130
151
  }
131
152
  catch (err) { }
@@ -15,6 +15,7 @@ interface AdminAuthAttrs {
15
15
  previousPasswords?: string[];
16
16
  authenticatorSecret?: string;
17
17
  apiKeys?: APIKey[];
18
+ tokenVersion?: number;
18
19
  }
19
20
  interface AdminAuthDoc extends Document {
20
21
  password: string;
@@ -31,6 +32,7 @@ interface AdminAuthDoc extends Document {
31
32
  previousPasswords?: string[];
32
33
  authenticatorSecret?: string;
33
34
  apiKeys?: APIKey[];
35
+ tokenVersion?: number;
34
36
  }
35
37
  interface AdminAuthModel extends Model<AdminAuthDoc> {
36
38
  build(attrs: AdminAuthAttrs): AdminAuthDoc;
@@ -65,6 +65,10 @@ const buildAdminAuth = (mongoose) => {
65
65
  authenticatorSecret: {
66
66
  type: String,
67
67
  },
68
+ tokenVersion: {
69
+ type: Number,
70
+ default: 0,
71
+ },
68
72
  apiKeys: [
69
73
  {
70
74
  value: {
@@ -10,6 +10,10 @@ interface AuthAttrs {
10
10
  apiKeys?: APIKey[];
11
11
  isDisabled?: boolean;
12
12
  tokenVersion?: number;
13
+ blacklistedTokens?: Array<{
14
+ jti: string;
15
+ exp: Date;
16
+ }>;
13
17
  authenticator?: {
14
18
  secret?: string;
15
19
  verified?: boolean;
@@ -34,6 +38,10 @@ interface AuthDoc extends Document {
34
38
  apiKeys?: APIKey[];
35
39
  isDisabled?: boolean;
36
40
  tokenVersion?: number;
41
+ blacklistedTokens?: Array<{
42
+ jti: string;
43
+ exp: Date;
44
+ }>;
37
45
  authenticator?: {
38
46
  secret?: string;
39
47
  verified?: boolean;
@@ -91,6 +91,18 @@ const buildAuth = (mongoose) => {
91
91
  },
92
92
  },
93
93
  ],
94
+ blacklistedTokens: [
95
+ {
96
+ jti: {
97
+ type: String,
98
+ required: true,
99
+ },
100
+ exp: {
101
+ type: Date,
102
+ required: true,
103
+ },
104
+ },
105
+ ],
94
106
  }, {
95
107
  toJSON: {
96
108
  transform(doc, ret) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.2302",
3
+ "version": "1.0.2304",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -28,7 +28,7 @@
28
28
  "@google-cloud/secret-manager": "^5.3.0",
29
29
  "@google-cloud/storage": "^6.9.5",
30
30
  "@hyperdx/node-opentelemetry": "^0.7.0",
31
- "@riocrypto/common": "^1.0.2020",
31
+ "@riocrypto/common": "^1.0.2021",
32
32
  "@types/express": "^4.17.13",
33
33
  "axios": "^1.7.4",
34
34
  "crypto-js": "^4.2.0",