/// <summary> /// Create <see cref="ClaimsIdentity"/> for specified <see cref="IUser"/>. /// </summary> /// <param name="user">The tenant user to create the principal for.</param> /// <param name="tenant">The tenant which the user is a member of.</param> /// <param name="tenantRole">The user role within the tenant.</param> /// <param name="authenticationType">Authentication type to use in authentication scheme.</param> /// <returns>Instance of <see cref="ClaimsIdentity"/>.</returns> public static ClaimsIdentity CreateTenantUserIdentity( IUser user, ITenant tenant, OrganizationRole tenantRole, string authenticationType) { if (user is null) { throw new ArgumentNullException(nameof(user)); } if (tenant is null) { throw new ArgumentNullException(nameof(tenant)); } var claims = new[] { new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()), new Claim(ClaimTypes.Role, user.Role.ToString()), new Claim(FunderMapsAuthenticationClaimTypes.Tenant, tenant.Id.ToString()), new Claim(FunderMapsAuthenticationClaimTypes.TenantRole, tenantRole.ToString()), }; return(new(claims, authenticationType, ClaimTypes.Name, ClaimTypes.Role)); }
public static async Task <HttpResponseMessage> SendAssignRoleToUserAsync(int userId, OrganizationRole role, int organizationId = TestEnvironment.DefaultOrganizationId) { var cookie = await GetCookieAsync(OrganizationRole.GlobalAdmin); var roleDto = new OrgRightDTO { UserId = userId, Role = role.ToString("G") }; return(await PostWithCookieAsync(TestEnvironment.CreateUrl($"odata/Organizations({organizationId})/Rights"), cookie, roleDto)); }