I was going through the identity server 4 doc and I came across this piece of code.
private (TestUser user, string provider, string providerUserId, IEnumerable<Claim> claims) FindUserFromExternalProvider(AuthenticateResult result)
{
var externalUser = result.Principal;
// try to determine the unique id of the external user (issued by the provider)
// the most common claim type for that are the sub claim and the NameIdentifier
// depending on the external provider, some other claim type might be used
var userIdClaim = externalUser.FindFirst(JwtClaimTypes.Subject) ??
externalUser.FindFirst(ClaimTypes.NameIdentifier) ??
throw new Exception("Unknown userid");
// remove the user id claim so we don't include it as an extra claim if/when we provision the user
var claims = externalUser.Claims.ToList();
claims.Remove(userIdClaim);
var provider = result.Properties.Items["scheme"];
var providerUserId = userIdClaim.Value;
// find external user
var user = _users.FindByExternalProvider(provider, providerUserId);
return (user, provider, providerUserId, claims);
}
and it is called like this.
var (user, provider, providerUserId, claims) = FindUserFromExternalProvider(result);
I dont quiet understand what is happening here. what sort of function definition usage is this?
You mean the returned data? It's a value tuple that is returned, see this article for a guide to Value Tuples. Value Tuples is a way to return multiple parameters without creating a custom class.
The method tries to lookup the user in the local database after the user has externally authenticated.