When accessing the email claims using OWIN and a Microsoft Account, you might encounter situations where your application does not receive a email claim, when you expect. We’ve experienced this issue most commonly with hotmail.com and outlook.com logins. Note below where the email claim is not completed in the left screen (a hotmail.com account) but is available for my kloud.com.au email address.


In this situation, there is a bug in the Owin Microsoft Account identity provider where a value isn’t correctly being checked for null. You can see the detail here: https://github.com/aspnet/AspNetKatana/issues/107.
This bug will be fixed in the 4.0.0 version of the Microsoft.Owin.Security.MicrosoftAccount nuget package, but if you need to use it now, you may add a new class called “MSProvider” to your project, and include it as part of your configuration options for your MicrosoftAccountAuthentication:


This will then solve your issue, and your claims will now always return email addresses.

Show me the code!

The code for this demo is hosted on github: https://github.com/bsmithb2/MicrosoftAccountEmailIssue. You will need to create a Converged App in the Microsoft portal (https://apps.dev.microsoft.com/#/appList) and then add the Client Id and Secret to your Microsoft Account configuration above. You’ll also need to add a “Web Platform” about halfway down with these details and then save:
microsoft account.PNG
 

Category:
Uncategorized