@tomei/sso 0.40.3 → 0.41.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -70,4 +70,11 @@ export declare class APIKey extends ObjectBase {
|
|
70
70
|
page: number;
|
71
71
|
limit: number;
|
72
72
|
}>;
|
73
|
+
revoke(apiKey: string, loginUser: LoginUser, dbTransaction: any, reason?: string): Promise<{
|
74
|
+
ApiKey: string;
|
75
|
+
Status: APIKeyStatusEnum.REVOKED;
|
76
|
+
RevokedAt: Date;
|
77
|
+
RevokedById: number;
|
78
|
+
RevokedReason: string;
|
79
|
+
}>;
|
73
80
|
}
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
12
|
exports.APIKey = void 0;
|
13
13
|
const general_1 = require("@tomei/general");
|
14
|
+
const api_key_enum_1 = require("../../enum/api-key.enum");
|
14
15
|
const api_key_repository_1 = require("./api-key.repository");
|
15
16
|
const config_1 = require("@tomei/config");
|
16
17
|
const crypto_1 = require("crypto");
|
@@ -84,6 +85,7 @@ class APIKey extends general_1.ObjectBase {
|
|
84
85
|
ApiKey: this.ApiKey,
|
85
86
|
Name: this.Name,
|
86
87
|
Status: this.Status,
|
88
|
+
Description: this.Description,
|
87
89
|
ExpirationDate: this.ExpirationDate,
|
88
90
|
CreatedAt: this.CreatedAt,
|
89
91
|
CreatedById: this.CreatedById,
|
@@ -195,6 +197,50 @@ class APIKey extends general_1.ObjectBase {
|
|
195
197
|
}
|
196
198
|
});
|
197
199
|
}
|
200
|
+
revoke(apiKey, loginUser, dbTransaction, reason) {
|
201
|
+
return __awaiter(this, void 0, void 0, function* () {
|
202
|
+
try {
|
203
|
+
const apiKeyRecord = yield APIKey._Repo.findOne({
|
204
|
+
where: { ApiKey: apiKey },
|
205
|
+
transaction: dbTransaction,
|
206
|
+
});
|
207
|
+
if (!apiKeyRecord) {
|
208
|
+
throw new general_1.ClassError('APIKey', 'APIKeyErrMsgO3', 'API key not found.', 'revoke');
|
209
|
+
}
|
210
|
+
const EntityValueBefore = Object.assign({}, apiKeyRecord.get({ plain: true }));
|
211
|
+
apiKeyRecord.Status = api_key_enum_1.APIKeyStatusEnum.REVOKED;
|
212
|
+
apiKeyRecord.RevokedAt = new Date();
|
213
|
+
apiKeyRecord.RevokedById = loginUser.UserId;
|
214
|
+
if (reason) {
|
215
|
+
apiKeyRecord.RevokedReason = reason;
|
216
|
+
}
|
217
|
+
yield APIKey._Repo.update(Object.assign({}, apiKeyRecord.get({ plain: true })), {
|
218
|
+
where: { APIKeyId: apiKeyRecord.APIKeyId },
|
219
|
+
transaction: dbTransaction,
|
220
|
+
});
|
221
|
+
const EntityValueAfter = Object.assign({}, apiKeyRecord.get({ plain: true }));
|
222
|
+
const activity = new activity_history_1.Activity();
|
223
|
+
activity.ActivityId = activity.createId();
|
224
|
+
activity.Action = activity_history_1.ActionEnum.UPDATE;
|
225
|
+
activity.Description = 'Revoke API key.';
|
226
|
+
activity.EntityType = 'APIKey';
|
227
|
+
activity.EntityId = apiKeyRecord.APIKeyId.toString();
|
228
|
+
activity.EntityValueBefore = JSON.stringify(EntityValueBefore);
|
229
|
+
activity.EntityValueAfter = JSON.stringify(EntityValueAfter);
|
230
|
+
yield activity.create(loginUser.ObjectId, dbTransaction);
|
231
|
+
return {
|
232
|
+
ApiKey: apiKeyRecord.ApiKey,
|
233
|
+
Status: apiKeyRecord.Status,
|
234
|
+
RevokedAt: apiKeyRecord.RevokedAt,
|
235
|
+
RevokedById: apiKeyRecord.RevokedById,
|
236
|
+
RevokedReason: apiKeyRecord.RevokedReason,
|
237
|
+
};
|
238
|
+
}
|
239
|
+
catch (error) {
|
240
|
+
throw error;
|
241
|
+
}
|
242
|
+
});
|
243
|
+
}
|
198
244
|
}
|
199
245
|
exports.APIKey = APIKey;
|
200
246
|
APIKey._Repo = new api_key_repository_1.APIKeyRepository();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"api-key.js","sourceRoot":"","sources":["../../../../src/components/api-key/api-key.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAwD;
|
1
|
+
{"version":3,"file":"api-key.js","sourceRoot":"","sources":["../../../../src/components/api-key/api-key.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAwD;AACxD,0DAA2D;AAC3D,6DAAwD;AAGxD,0CAAkD;AAClD,mCAAqC;AACrC,8DAA+D;AAC/D,yCAA+B;AAE/B,MAAa,MAAO,SAAQ,oBAAU;IAiBpC,IAAI,QAAQ;QACV,OAAO,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IAED,IAAI,QAAQ,CAAC,KAAa;QACxB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;IACnC,CAAC;IAED,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAID,YAAsB,UAAwB;QAC5C,KAAK,EAAE,CAAC;QACR,IAAI,UAAU,EAAE;YACd,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC;YACpC,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;YAChC,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;YAC5B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;YAC1C,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;YAChC,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC;YAChD,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,WAAW,CAAC;YAC3C,IAAI,CAAC,UAAU,GAAG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