microsoftgraph / aspnetcore-connect-sample

[ARCHIVED] This ASP.NET Core MVC sample shows how to connect to Microsoft Graph using delegated permissions and the Azure AD v2.0 (MSAL) endpoint.
MIT License
123 stars 96 forks source link

User.Identity.Name returning full name instead of email and photo returning 'ResourceNotFound' #33

Closed dmundra closed 5 years ago

dmundra commented 5 years ago

Hi,

When I try the application for 'User.Identity.Name' I get full name instead of email. So I changed the ger users's email line to

email = email ?? User.FindFirst(Startup.UpnType)?.Value;

where public const string UpnType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn";

For GetPictureStream in the first catch I was getting Request_ResourceNotFound but nothing would happen so I added

else
{
    throw;
}

Then the second catch would work and I got the default image. I am not sure why v1.0 is not returning an image. Any ideas?

mark-szabo commented 5 years ago

Hi @dmundra, sorry for the very late response!

  1. User.Identity.Name contains the username which is not always the email address.

  2. Getting user's profile picture is only partially supported with the v1.0 endpoint:

Note This operation in version 1.0 supports only a user's work or school mailboxes and not personal mailboxes.

https://docs.microsoft.com/en-us/graph/api/profilephoto-get?view=graph-rest-1.0