@entro314labs/ai-changelog-generator
Version:
AI-powered changelog generator with MCP server support - works with most providers, online and local models
156 lines (155 loc) • 4.39 kB
TypeScript
/**
* OAuth Handler Service
*
* Handles OAuth 2.0 authentication flows for AI providers.
* Supports:
* - Google OAuth (for Gemini API)
* - Azure AD OAuth (for Azure OpenAI)
*
* Features:
* - Authorization Code flow with PKCE
* - Token refresh
* - Secure token storage
*/
import { URLSearchParams } from 'node:url';
interface OAuthTokens {
access_token?: string;
refresh_token?: string;
expires_in?: number;
token_type?: string;
scope?: string;
expiresAt?: number | null;
savedAt?: number;
[key: string]: any;
}
export declare class OAuthHandlerService {
[key: string]: any;
constructor(provider: string, options?: Record<string, any>);
/**
* Generate PKCE code verifier and challenge
* @returns {{ verifier: string, challenge: string }}
*/
generatePKCE(): {
verifier: string;
challenge: string;
};
/**
* Generate state parameter for CSRF protection
* @returns {string}
*/
generateState(): string;
/**
* Build authorization URL
* @param {Object} pkce - PKCE parameters
* @param {string} state - State parameter
* @returns {string}
*/
buildAuthorizationUrl(pkce: any, state: any): string;
/**
* Start local server to receive OAuth callback
* @param {string} expectedState - Expected state parameter
* @returns {Promise<string>} Authorization code
*/
startCallbackServer(expectedState: string): Promise<string>;
/**
* Stop the callback server
*/
stopCallbackServer(): void;
/**
* Exchange authorization code for tokens
* @param {string} code - Authorization code
* @param {string} verifier - PKCE code verifier
* @returns {Promise<Object>} Token response
*/
exchangeCodeForTokens(code: any, verifier: any): Promise<OAuthTokens>;
/**
* Refresh access token using refresh token
* @param {string} refreshToken - Refresh token
* @returns {Promise<Object>} New token response
*/
refreshAccessToken(refreshToken: string): Promise<OAuthTokens>;
/**
* Make token endpoint request
* @param {URLSearchParams} params
* @returns {Promise<Object>}
*/
makeTokenRequest(params: URLSearchParams): Promise<OAuthTokens>;
/**
* Save tokens to secure storage
* @param {Object} tokens
*/
saveTokens(tokens: OAuthTokens): void;
/**
* Load tokens from storage
* @returns {Object|null}
*/
loadTokens(): OAuthTokens | null;
/**
* Clear stored tokens
*/
clearTokens(): void;
/**
* Check if tokens are valid and not expired
* @returns {boolean}
*/
hasValidTokens(): boolean;
/**
* Get valid access token, refreshing if needed
* @returns {Promise<string>}
*/
getValidAccessToken(): Promise<any>;
/**
* Perform full OAuth flow
* @param {Function} openBrowser - Function to open browser (receives URL)
* @returns {Promise<Object>} Token response
*/
authenticate(openBrowser: any): Promise<OAuthTokens>;
/**
* Check authentication status
* @returns {Object}
*/
getAuthStatus(): {
authenticated: boolean;
reason: string;
expired?: undefined;
expiresAt?: undefined;
canRefresh?: undefined;
} | {
reason?: undefined;
authenticated: boolean;
expired: boolean;
canRefresh: boolean;
expiresAt?: undefined;
} | {
reason?: undefined;
authenticated: boolean;
expired: boolean;
expiresAt: Date | null;
canRefresh: boolean;
};
}
/**
* Google OAuth Handler with Gemini-specific configuration
*/
export declare class GoogleOAuthHandler extends OAuthHandlerService {
[key: string]: any;
constructor(options?: Record<string, any>);
/**
* Check for existing Gemini CLI tokens and import them
* @returns {boolean}
*/
importFromGeminiCli(): boolean;
}
/**
* Azure OAuth Handler with Azure AD-specific configuration
*/
export declare class AzureOAuthHandler extends OAuthHandlerService {
[key: string]: any;
constructor(options?: Record<string, any>);
/**
* Get Azure AD token for Azure OpenAI
* @returns {Promise<string>}
*/
getAzureToken(): Promise<any>;
}
export default OAuthHandlerService;