OAuth Authentication Flow Module

This module orchestrates the complete OAuth 2.0 authorization flow for Spotify, coordinating multiple authentication components into a seamless authentication experience. It implements the authorization code flow with PKCE for maximum security in desktop applications.

Features:

  • Complete authorization code flow implementation with CSRF protection
  • Secure state parameter generation and validation
  • Multi-account support with optional account selection forcing
  • Comprehensive Promise-based flow management
  • Coordinated window, server, and token exchange orchestration
  • User-friendly authentication experience with visual feedback
  • Graceful error handling and recovery for all failure scenarios
  • Clean cancellation support at any point in the flow
  • Detailed activity logging for troubleshooting
  • Proper resource cleanup in all termination scenarios

The flow coordinates three main components:

  1. Authentication Window - User interface for Spotify login
  2. Callback Server - Endpoint for receiving the authorization code
  3. Token Exchange - Secure conversion of code to access/refresh tokens

Security features include:

  • Random state parameter to prevent CSRF attacks
  • Secure credential handling with no client secret exposure
  • Automatic token storage with encryption
  • Session isolation for multi-account scenarios

Functions

startAuthFlow
cancelAuthFlow