MCPcopy
hub / github.com/tiagozip/cap / validateToken

Method validateToken

server/index.js:409–437  ·  view source on GitHub ↗

* Validates a token * @param {string} token - The token to validate * @param {TokenConfig} [conf] - Validation configuration * @returns {Promise<{success: boolean}>}

(token, conf)

Source from the content-addressed store, hash-verified

407 * @returns {Promise<{success: boolean}>}
408 */
409 async validateToken(token, conf) {
410 await this._lazyCleanup();
411
412 if (!token || typeof token !== "string") {
413 return { success: false };
414 }
415
416 const parts = token.split(":");
417 if (parts.length !== 2 || !parts[0] || !parts[1]) {
418 return { success: false };
419 }
420
421 const [id, vertoken] = parts;
422 const hash = await sha256(vertoken);
423 const key = `${id}:${hash}`;
424
425 await this._waitForTokensList();
426
427 const tokenExpires = await this._getToken(key);
428 if (tokenExpires && tokenExpires > Date.now()) {
429 if (!conf?.keepToken) {
430 await this._deleteToken(key);
431 }
432
433 return { success: true };
434 }
435
436 return { success: false };
437 }
438
439 /**
440 * Loads tokens from the storage file

Callers 7

capMiddlewareFunction · 0.95
capCheckpointFunction · 0.95
capCheckpointFunction · 0.95
index.jsFile · 0.80
index.jsFile · 0.80
index.jsFile · 0.80
index.jsFile · 0.80

Calls 5

_lazyCleanupMethod · 0.95
_waitForTokensListMethod · 0.95
_getTokenMethod · 0.95
_deleteTokenMethod · 0.95
sha256Function · 0.85

Tested by

no test coverage detected