u
This commit is contained in:
34
src/store/mcp/createRefreshToken.js
Normal file
34
src/store/mcp/createRefreshToken.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import { INSERT_REFRESH_TOKEN as MSSQL_INSERT } from '../../providers/mssql/queries/mcp.js';
|
||||
import { INSERT_REFRESH_TOKEN as SQLITE_INSERT } from '../../providers/sqlite3/queries/mcp.js';
|
||||
|
||||
export default function createRefreshToken(provider) {
|
||||
const sql = provider.dialect === 'sqlite3' ? SQLITE_INSERT : MSSQL_INSERT;
|
||||
/**
|
||||
* Stores an OAuth 2.1 refresh token.
|
||||
*
|
||||
* @param {object} input
|
||||
* @param {string} input.refreshToken - The refresh token string.
|
||||
* @param {string} input.clientId - The client ID.
|
||||
* @param {number} input.googleAuthId - The user ID.
|
||||
* @param {string|null} [input.scope] - Scopes granted.
|
||||
* @param {string|Date} input.expiresAt - Expiration Date or ISO string.
|
||||
* @returns {Promise<object>} Created token record or id.
|
||||
*/
|
||||
return async ({
|
||||
refreshToken,
|
||||
clientId,
|
||||
googleAuthId,
|
||||
scope = 'mcp:tools',
|
||||
expiresAt,
|
||||
}) => {
|
||||
const exp = expiresAt instanceof Date ? expiresAt.toISOString() : expiresAt;
|
||||
const result = await provider.query(sql, {
|
||||
refreshToken,
|
||||
clientId,
|
||||
googleAuthId,
|
||||
scope,
|
||||
expiresAt: exp,
|
||||
});
|
||||
return result.rows[0]?.id ?? result.insertId;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user