Skip to main content
Glama
auth.ts•2.33 kB
import { config } from 'dotenv'; // Load environment variables config(); class MediumAuth { private clientId: string; private clientSecret: string; private accessToken: string | null = null; constructor() { // Validate credentials from environment this.clientId = this.validateCredential('MEDIUM_CLIENT_ID'); this.clientSecret = this.validateCredential('MEDIUM_CLIENT_SECRET'); } private validateCredential(key: string): string { const value = process.env[key]; if (!value) { this.logSecurityAlert(`Missing critical credential: ${key}`); throw new Error(`🚨 Security Alert: Missing ${key} in environment variables`); } return value; } public async authenticate(): Promise<void> { try { // This is a placeholder for actual Medium OAuth flow // In a real implementation, you'd: // 1. Request authorization code from Medium // 2. Exchange authorization code for access token // 3. Store and refresh the access token // Simulate authentication (replace with actual OAuth implementation) this.accessToken = await this.requestAccessToken(); this.logAuthSuccess(); } catch (error) { this.handleAuthenticationFailure(error); } } private async requestAccessToken(): Promise<string> { // Placeholder for OAuth token request // You'll need to implement the actual Medium OAuth 2.0 flow here // Simulated token for demo purposes return `medium_token_${Date.now()}`; } public getAccessToken(): string { if (!this.accessToken) { this.logSecurityAlert('Unauthorized access token request'); throw new Error('šŸ”’ Authentication Required: Call authenticate() first'); } return this.accessToken; } private logAuthSuccess() { console.log(` āœ… Medium Authentication Successful šŸ•’ Timestamp: ${new Date().toISOString()} `); } private logSecurityAlert(message: string) { console.error(` āš ļø SECURITY ALERT āš ļø Message: ${message} Timestamp: ${new Date().toISOString()} `); } private handleAuthenticationFailure(error: any) { this.logSecurityAlert(`Authentication Failed: ${error.message}`); throw new Error(`🚫 Medium Authentication Failed: ${error.message}`); } } export default MediumAuth;

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jackyckma/medium-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server