示例#1
0
        public static UserIdentifier GetUserIdentifierOrNull(this IIdentity identity)
        {
            identity.CheckNotNull(nameof(identity));

            var userId = identity.GetUserId();

            if (userId == null)
            {
                return(null);
            }

            return(new UserIdentifier(identity.GetTenantId(), userId.Value));
        }
示例#2
0
        public static int?GetImpersonatorTenantId(this IIdentity identity)
        {
            identity.CheckNotNull(nameof(identity));

            var claimsIdentity = identity as ClaimsIdentity;

            var tenantIdOrNull = claimsIdentity?.Claims?.FirstOrDefault(c => c.Type == AbpClaimTypes.ImpersonatorTenantId);

            if (tenantIdOrNull == null || tenantIdOrNull.Value.IsNullOrWhiteSpace())
            {
                return(null);
            }

            return(Convert.ToInt32(tenantIdOrNull.Value));
        }
示例#3
0
        public static long?GetUserId([NotNull] this IIdentity identity)
        {
            identity.CheckNotNull(nameof(identity));

            var claimsIdentity = identity as ClaimsIdentity;

            var userIdOrNull = claimsIdentity?.Claims?.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier);

            if (userIdOrNull == null || userIdOrNull.Value.IsNullOrWhiteSpace())
            {
                return(null);
            }

            return(Convert.ToInt64(userIdOrNull.Value));
        }