// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq; using Microsoft.AspNetCore.Identity; namespace System.Security.Claims { /// /// Claims related extensions for . /// public static class PrincipalExtensions { /// /// Returns the value for the first claim of the specified type otherwise null the claim is not present. /// /// The instance this method extends. /// The claim type whose first value should be returned. /// The value of the first instance of the specified claim type, or null if the claim is not present. public static string FindFirstValue(this ClaimsPrincipal principal, string claimType) { if (principal == null) { throw new ArgumentNullException(nameof(principal)); } var claim = principal.FindFirst(claimType); return claim != null ? claim.Value : null; } } }