Azure Mobile App – Get username from custom authentication when User.Identity.Name is blank

If you’ve setup custom authentication with Aspnet Identity as mentioned in my previous post or using some other custom authentication and you need to get the authorized users username, the below should do the trick:

ClaimsPrincipal claimsUser = (ClaimsPrincipal)this.User;
            string id = claimsUser.FindFirst(ClaimTypes.NameIdentifier).Value;

I used this to filter my GetAllItems table controller like so:

return Query().Where(todo=> todo.Username == id);