Get NameIdentifier claim in Azure App Services using OnlineIdAuthenticator
<p>I am using the OnlineIdAuthenticator class to get an authentication token in order to log in to Azure App Services, but I'm unable to get the NameIdentifier claim server side. I need the Id to uniquely identify a user and store it in a database.</p>

<p>I want to use the OnlineIdAuthenticator to enable single sign on, so the user isn't prompted to login every time he starts my app (a Windows Store App).</p>

<p>I use this method in my app to get the token and login:</p>

<pre><code>    protected override async Task&lt;bool&gt; LoginAsync()
    {
        var authenticator = new OnlineIdAuthenticator();

        var mobileServicesTicket = new OnlineIdServiceTicketRequest("myapp.azurewebsites.net", "JWT");

        var ticketRequests = new List&lt;OnlineIdServiceTicketRequest&gt;() { mobileServicesTicket };

        var authResult = await authenticator.AuthenticateUserAsync(ticketRequests, CredentialPromptType.PromptIfNeeded);

        if ((authResult.Tickets.Count == 1) &amp;&amp; (authResult.Tickets[0].ErrorCode == 0))
        {
            var accessToken = authResult.Tickets[0];

            var token = new JObject();
            token.Add("authenticationToken", accessToken.Value);

            var _mobileServiceClient = ServiceLocator.Current.GetInstance&lt;IMobileServiceClient&gt;();
            var user = await _mobileServiceClient.LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount, token);

            return true;
        }
        else
        {
            return false;
        }
    }
</code></pre>

<p>Server side I use this method to get the unique Id:</p>

<pre><code>    public static async Task&lt;string&gt; GetUserId(IPrincipal pricipal, HttpRequestMessage request)
    {         
        ProviderCredentials credentials = await pricipal.GetAppServiceIdentityAsync&lt;MicrosoftAccountCredentials&gt;(request);
        return credentials.Provider + ":" + credentials.Claims[ClaimTypes.NameIdentifier];
    }
</code></pre>

<p>The Claims collection above contain these keys:</p>

<p>ver, iss, exp, uid, aud, urn:microsoft:appuri, urn:microsoft:appid</p>

<p>Everything else seems to work. I'm able to login with my MicrosoftAccount and I can call methods that require authentication, but I'm just not able to generate the user id.</p>

<p>How can I get the NameIdentifier in the Claims collection?</p>