Microsoft OAuth refresh token invalid_grant — What it means & how to fix it
Blog post from Nango
OAuth 2.0 integrations with Microsoft's identity platform can encounter refresh token failures, often appearing as "invalid_grant" errors, which can disrupt scheduled jobs and user actions. These failures are typically due to inactivity, fixed lifetimes for Single Page Applications (SPAs), credential changes, user or admin revocations, or Conditional Access policy changes requiring re-authentication. Understanding the AADSTS codes in error descriptions helps diagnose the issue, whether it involves token inactivity, SPA lifetime expiration, or security events like password resets. Solutions include re-authenticating users when necessary and implementing proactive measures like tracking token age, storing refreshed tokens immediately, handling policy changes, and monitoring error patterns. For developers seeking to avoid these complexities, tools like Nango offer an open-source solution for managing OAuth token lifecycles, providing secure storage, automatic refreshes, and clear signals for when re-authentication is needed.