Search code examples
c#androidxamarinxamarin.formsidentityserver4

Get the UserID from the LoginResult class


Please see the code below:

private async void Login_Clicked(object sender, EventArgs e)
{
    LoginResult _result= await _client.LoginAsync(new LoginRequest());
}

I can get the claims of the user as follows:

var claim = _result.User.Claims

How can I get the user ID? Here is a link to the LoginResult class.


Solution

  • I am not familiar with Xamarin, but I assume you can use linq:

    // using System.Linq
    
    var sub = _result.User.Claims.FirstOrDefault(c => c.Type == "sub")?.Value
    

    This way you won't need to reference other packages. You can create your own extension based on this.