The city of Philadelphia was within its rights to terminate its contract with a Catholic foster care agency over its refusal to work with same-sex couples, a federal appeals court has ruled.

On Monday, the U.S. Court of Appeals for the Third Circuit upheld a ruling that Catholic Social Services’ rights to First Amendment religious liberty were not infringed by the city’s requirement that its contractors adhere to a nondiscrimination policy.