internal static ClaimsPrincipal GetUserPrincipal()

in src/Microsoft.Azure.SignalR.Common/Utilities/ClaimsUtility.cs [179:222]


        internal static ClaimsPrincipal GetUserPrincipal(Claim[] messageClaims)
        {
            if (messageClaims == null || messageClaims.Length == 0)
            {
                return EmptyPrincipal;
            }

            var claims = new List<Claim>();
            var authenticationType = DefaultAuthenticationType;
            string nameType = null;
            string roleType = null;
            foreach (var claim in messageClaims)
            {
                if (claim.Type == Constants.ClaimType.AuthenticationType)
                {
                    authenticationType = claim.Value;
                }
                else if (claim.Type == Constants.ClaimType.NameType)
                {
                    nameType = claim.Value;
                }
                else if (claim.Type == Constants.ClaimType.RoleType)
                {
                    roleType = claim.Value;
                }
                else if (claim.Type.StartsWith(Constants.ClaimType.AzureSignalRUserPrefix))
                {
                    var claimName = claim.Type.Substring(Constants.ClaimType.AzureSignalRUserPrefix.Length);
                    claims.Add(new Claim(claimName, claim.Value));
                }
                else if (!SystemClaims.Contains(claim.Type) && !claim.Type.StartsWith(Constants.ClaimType.AzureSignalRSysPrefix))
                {
                    claims.Add(claim);
                }
            }

            if (claims.Count == 0)
            {
                // For JWT token, the authenticated claims must contain non-system claims
                return EmptyPrincipal;
            }

            return new ClaimsPrincipal(new ClaimsIdentity(claims, authenticationType, nameType, roleType));
        }