mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-12 12:54:07 -07:00
feat(cli) - Define shared interface for storage (#7049)
Co-authored-by: Shi Shu <shii@google.com>
This commit is contained in:
@@ -8,29 +8,7 @@ import { promises as fs } from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { Storage } from '../config/storage.js';
|
||||
import { getErrorMessage } from '../utils/errors.js';
|
||||
|
||||
/**
|
||||
* Interface for MCP OAuth tokens.
|
||||
*/
|
||||
export interface MCPOAuthToken {
|
||||
accessToken: string;
|
||||
refreshToken?: string;
|
||||
expiresAt?: number;
|
||||
tokenType: string;
|
||||
scope?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for stored MCP OAuth credentials.
|
||||
*/
|
||||
export interface MCPOAuthCredentials {
|
||||
serverName: string;
|
||||
token: MCPOAuthToken;
|
||||
clientId?: string;
|
||||
tokenUrl?: string;
|
||||
mcpServerUrl?: string;
|
||||
updatedAt: number;
|
||||
}
|
||||
import type { OAuthToken, OAuthCredentials } from './token-storage/types.js';
|
||||
|
||||
/**
|
||||
* Class for managing MCP OAuth token storage and retrieval.
|
||||
@@ -58,13 +36,13 @@ export class MCPOAuthTokenStorage {
|
||||
*
|
||||
* @returns A map of server names to credentials
|
||||
*/
|
||||
static async loadTokens(): Promise<Map<string, MCPOAuthCredentials>> {
|
||||
const tokenMap = new Map<string, MCPOAuthCredentials>();
|
||||
static async loadTokens(): Promise<Map<string, OAuthCredentials>> {
|
||||
const tokenMap = new Map<string, OAuthCredentials>();
|
||||
|
||||
try {
|
||||
const tokenFile = this.getTokenFilePath();
|
||||
const data = await fs.readFile(tokenFile, 'utf-8');
|
||||
const tokens = JSON.parse(data) as MCPOAuthCredentials[];
|
||||
const tokens = JSON.parse(data) as OAuthCredentials[];
|
||||
|
||||
for (const credential of tokens) {
|
||||
tokenMap.set(credential.serverName, credential);
|
||||
@@ -92,7 +70,7 @@ export class MCPOAuthTokenStorage {
|
||||
*/
|
||||
static async saveToken(
|
||||
serverName: string,
|
||||
token: MCPOAuthToken,
|
||||
token: OAuthToken,
|
||||
clientId?: string,
|
||||
tokenUrl?: string,
|
||||
mcpServerUrl?: string,
|
||||
@@ -101,7 +79,7 @@ export class MCPOAuthTokenStorage {
|
||||
|
||||
const tokens = await this.loadTokens();
|
||||
|
||||
const credential: MCPOAuthCredentials = {
|
||||
const credential: OAuthCredentials = {
|
||||
serverName,
|
||||
token,
|
||||
clientId,
|
||||
@@ -135,9 +113,7 @@ export class MCPOAuthTokenStorage {
|
||||
* @param serverName The name of the MCP server
|
||||
* @returns The stored credentials or null if not found
|
||||
*/
|
||||
static async getToken(
|
||||
serverName: string,
|
||||
): Promise<MCPOAuthCredentials | null> {
|
||||
static async getToken(serverName: string): Promise<OAuthCredentials | null> {
|
||||
const tokens = await this.loadTokens();
|
||||
return tokens.get(serverName) || null;
|
||||
}
|
||||
@@ -177,7 +153,7 @@ export class MCPOAuthTokenStorage {
|
||||
* @param token The token to check
|
||||
* @returns True if the token is expired
|
||||
*/
|
||||
static isTokenExpired(token: MCPOAuthToken): boolean {
|
||||
static isTokenExpired(token: OAuthToken): boolean {
|
||||
if (!token.expiresAt) {
|
||||
return false; // No expiry, assume valid
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user