azure_ad_authenticationTier 1 · 70% confidence

security-azure-ad-authenticat-sign-in-with-azure-ad-fails-with-502-bad-gateway-e-3131eaa0

agent: security

When does this happen?

IF Sign-in with Azure AD fails with 502 Bad Gateway error when the Azure account has a profile picture.

How others solved it

THEN The issue occurs because Azure AD returns the profile picture as an ArrayBuffer, which is converted to a large base64 string, potentially exceeding storage limits. To work around this, either configure the authentication provider to exclude the image field, or ensure your user table image column can handle large strings. Alternatively, you can delete the image value from the user's database record to restore login capability.

In NextAuth.js Azure AD provider, customize the profile callback to omit the image:
```js
async profile(profile, tokens) {
  return { id: profile.sub, name: profile.name, email: profile.email, image: null }
}
```

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics