3

in a Windows 10 UWP I try use WebAuthenticationCoreManager.RequestTokenAsync to get the result from a login with a Microsoft account. I get a WebTokenRequestResult with Success. ResponseData[0] contains a WebAccount with an ID - but the UserName is empty. The scope of the call is wl.basic - so I should get a lot of information... I'm not sure how to retrieve extra information - and for the current test the Username would be OK.

I checked out the universal samples - and there I found a snippet which tries to do what I'm trying - an output of webTokenRequestResult.ResponseData[0].WebAccount.UserName.

By the way - the example output is also empty.

Is this a bug - or what do I (and the MS in the samples) have to do to get the users profile data (or at least the Username)?

ManniAT
  • 1,989
  • 2
  • 19
  • 25
  • I second this. Why is it that the UserName field is empty? I just wanted to implement something similar to google play games or apples game center where i can get a basic username and id back from the device for use in the game project. – SammyG Jul 18 '16 at 16:36

1 Answers1

1

According to the documentation (https://learn.microsoft.com/en-us/windows/uwp/security/web-account-manager), you have to make a specific REST API call to retrieve it:

var restApi = new Uri(@"https://apis.live.net/v5.0/me?access_token=" +     result.ResponseData[0].Token);

using (var client = new HttpClient())
{
    var infoResult = await client.GetAsync(restApi);
    string content = await infoResult.Content.ReadAsStringAsync();

    var jsonObject = JsonObject.Parse(content);
    string id = jsonObject["id"].GetString();
    string name = jsonObject["name"].GetString();
}

As to why the WebAccount property doesn't get set... shrugs

And FYI, the "id" returned here is entirely different from the WebAccount.Id property returned with the authentication request.

Nick Bauer
  • 1,027
  • 8
  • 13