How to get user information when authenticating wi

2019-08-17 19:16发布

问题:

I am building an Azure App Service that has both Windows Desktop (not UWP) and iOS clients. I want to use Microsoft Account Authentication to authenticate users.

As a result of a previous question here I can now authenticate users using the OneDrive SDK but have fallen at the next hurdle. The One Drive SDK does not appear to provide access to user details such as their given name and email address.

Please can someone point me in the direction of an example or instructions for authenticating a user from an old school desktop application to allow them to access an Azure App Service using their Microsoft Account (NOT Azure AD) that will also provide the client with access to their email address and which does not use depreciated technology.

回答1:

After authentication via Easy Auth, we can acquire the user information from the me endpoint(https://{yourSiteName}/.auth/me) by invoking the API like code below:

var result =await client.InvokeApiAsync("/.auth/me");

And to acquire the email, we need the wl.emails scope when we authenticate with the OneDrive SDK. And after that we can get the given-name and emails from me endpoint like:

string email=(string)result[0].SelectToken("$.user_claims[?(@.typ == 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress')]")["val"]

string givenName=(string)result[0].SelectToken("$.user_claims[?(@.typ == 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname')]")["val"]