Example #1
0
        /// <summary>
        /// Gets the domain-hint associated with an identity
        /// </summary>
        /// <param name="claimsPrincipal">Identity for which to compte the domain-hint</param>
        /// <returns>domain-hint for the identity, or <c>null</c> if it cannot be found</returns>
        public static string GetDomainHint(this ClaimsPrincipal claimsPrincipal)
        {
            // Tenant for MSA accounts
            const string msaTenantId = "9188040d-6c67-4c5b-b112-36a304b66dad";

            var    tenantId   = ClaimsPrincipalExtension.GetTenantId(claimsPrincipal);
            string domainHint = string.IsNullOrWhiteSpace(tenantId) ? null :
                                tenantId == msaTenantId ? "consumers" : "organizations";

            return(domainHint);
        }
Example #2
0
        /// <summary>
        /// Get the Account identifier for an MSAL.NET account from a ClaimsPrincipal
        /// </summary>
        /// <param name="claimsPrincipal">Claims principal</param>
        /// <returns>A string corresponding to an account identifier as defined in <see cref="Microsoft.Identity.Client.AccountId.Identifier"/></returns>
        public static string GetMsalAccountId(this ClaimsPrincipal claimsPrincipal)
        {
            string userObjectId = ClaimsPrincipalExtension.GetObjectId(claimsPrincipal);
            string tenantId     = ClaimsPrincipalExtension.GetTenantId(claimsPrincipal);

            if (!string.IsNullOrWhiteSpace(userObjectId) && !string.IsNullOrWhiteSpace(tenantId))
            {
                return($"{userObjectId}.{tenantId}");
            }

            return(null);
        }
Example #3
0
 /// <summary>
 /// Gets the login-hint associated with an identity
 /// </summary>
 /// <param name="claimsPrincipal">Identity for which to compte the login-hint</param>
 /// <returns>login-hint for the identity, or <c>null</c> if it cannot be found</returns>
 public static string GetLoginHint(this ClaimsPrincipal claimsPrincipal)
 {
     return(ClaimsPrincipalExtension.GetDisplayName(claimsPrincipal));
 }