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)); }
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)); }
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)); }