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:
2. I also tried both formats for scopes:
- Short format: "Mail.Send", "User.Read"
- Long format: "https://graph.microsoft.com/Mail.Send"
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!



1 Reply
use
mapProfileToUser
to return email if it's using a custmo key other than email
or if you want to use other value as a fallback. You can also use it to debug to check if it's actually returning email in the profile object.