Better Auth Microsoft OAuth - email_not_found Error

Hi team! I'm having an issue with Better Auth and Microsoft OAuth integration. When trying to authenticate with Microsoft, I'm getting this error:

"Better Auth Error: We encountered an issue while processing your request.
Error Code: email_not_found"

My setup:
  • Microsoft Azure app with these permissions: User.Read, Mail.Send, Mail.Read, Mail.ReadWrite, Calendars.Read, Calendars.ReadWrite, Contacts.Read, etc.
  • Client secret is valid and working
  • Redirect URIs should be correct
I've tried:
  1. Using the standard OAuth flow with these scopes in auth.ts:
microsoft: {
  clientId: process.env.MICROSOFT_CLIENT_ID,
  clientSecret: process.env.MICROSOFT_CLIENT_SECRET,
  scopes: [
    "openid", 
    "email", 
    "profile",
    "Mail.Send", 
    "Mail.Read", 
    "Mail.ReadWrite", 
    "User.Read"
  ]
}


  1. I also tried both formats for scopes:
Questions:
  1. Are these the correct Microsoft scopes for Better Auth to extract email?
  2. Does Better Auth need specific fields from Microsoft's response?
  3. How does Better Auth extract email from Microsoft's response? Does it look for "mail" or "userPrincipalName"?
  4. Any known issues with Microsoft OAuth in Better Auth?
Any help would be greatly appreciated!
Screenshot_2025-03-302x.png
Screenshot_2025-03-30_22x.png
Screenshot_2025-03-30_32x.png
Was this page helpful?