示例#1
0
        public static string GetName(this IIdentity identity)
        {
            if (!string.IsNullOrWhiteSpace(identity.ClaimValue("name")))
            {
                return(identity.ClaimValue("name"));
            }

            if (!string.IsNullOrWhiteSpace(identity.Name))
            {
                return(identity.Name);
            }

            var nameClaim = identity.ClaimValue(ClaimTypes.Name);

            if (!string.IsNullOrWhiteSpace(nameClaim))
            {
                return(nameClaim);
            }

            return(identity.GetEmailAddress());
        }
示例#2
0
        public static string GetEmailAddress(this IIdentity identity)
        {
            var username = identity.ClaimValue(ClaimTypes.Email);

            if (string.IsNullOrWhiteSpace(username))
            {
                username = identity.ClaimValue("preferred_username");
            }

            // temporarily we fallback to Upn claim as both v1 and v2 endpoints are allowed (for PRs and branches sites)
            if (string.IsNullOrWhiteSpace(username))
            {
                username = identity.ClaimValue(ClaimTypes.Upn);
            }

            if (string.IsNullOrWhiteSpace(username))
            {
                username = identity.Name;
            }

            return(username);
        }
示例#3
0
        public static Guid GetUserId(this IIdentity identity)
        {
            var userIdValue = identity.ClaimValue("user_id");

            return(!string.IsNullOrWhiteSpace(userIdValue) ? Guid.Parse(userIdValue) : Guid.Empty);
        }
示例#4
0
 public static string LastName(this IIdentity identity)
 {
     return(identity.ClaimValue(ClaimTypes.Surname));
 }
示例#5
0
 public static string NameIdentifier(this IIdentity identity)
 {
     return(identity.ClaimValue(ClaimTypes.NameIdentifier));
 }
示例#6
0
 public static string FirstName(this IIdentity identity)
 {
     return(identity.ClaimValue(ClaimTypes.GivenName));
 }
示例#7
0
 public static string Domain(this IIdentity identity)
 {
     return(identity.ClaimValue(AdditionalClaimTypes.Domain));
 }
示例#8
0
 public static string TenantId(this IIdentity identity)
 {
     return(identity.ClaimValue(AdditionalClaimTypes.TenantId));
 }
示例#9
0
 public static string PreferredLanguage(this IIdentity identity)
 {
     return(identity.ClaimValue(AdditionalClaimTypes.PreferredLanguage));
 }
示例#10
0
 public static string ObjectIdentifier(this IIdentity identity)
 {
     return(identity.ClaimValue(AdditionalClaimTypes.ObjectIdentifier));
 }