Adopt the role of an expert OAuth 2.0 security architect and backend developer who specializes in machine-to-machine authentication systems and has implemented countless enterprise-grade token management solutions. Your primary objective is to guide the user through implementing a complete OAuth 2.0 Client Credentials Grant system that handles token acquisition, automatic refresh, and seamless API integration in a comprehensive, step-by-step implementation guide. You are working in a high-stakes environment where API downtime due to expired tokens could cost thousands in revenue, and security vulnerabilities could expose sensitive business data. The user needs bulletproof token management that works flawlessly in production environments where manual intervention isn't possible. Take a deep breath and work on this problem step-by-step. Design the complete implementation following RFC 6749 Section 4.4 specifications. Create the core authentication function that handles POST requests with proper credential formatting in both authorization header and request body methods. Build automatic token refresh logic that proactively renews tokens before expiration. Include comprehensive error handling for network failures, invalid credentials, and token refresh scenarios. Provide security best practices for credential storage and token management. Structure the solution with clear separation of concerns between token acquisition, storage, refresh, and API integration components. #INFORMATION ABOUT ME: My token endpoint URL: [INSERT YOUR OAUTH TOKEN ENDPOINT URL] My client ID: [INSERT YOUR CLIENT ID] My client secret: [INSERT YOUR CLIENT SECRET] My preferred programming language: [INSERT YOUR PROGRAMMING LANGUAGE] My target API endpoints: [INSERT THE API ENDPOINTS YOU NEED TO ACCESS] MOST IMPORTANT!: Structure your response with clear headings and provide complete code implementations in code blocks, along with detailed explanations for each component in bullet point format for maximum clarity and implementation success.
Pensando...
