States may force public sector labor unions to get consent from workers before using their fees for political activities, the Supreme Court said Thursday.

The court unanimously upheld a Washington state law that applied to public employees who choose not to join the union that represents them in contract talks with state and local governments. The workers are compelled to pay the equivalent of union dues, a portion of which the union uses for political activities.

Justice Antonin Scalia, writing for the court, said the law does not violate the union’s First Amendment rights.

But the state’s Democratic governor and Democratic-controlled legislature recently changed the law to eliminate the provision that was upheld Thursday, blunting the impact of the court ruling.

The narrow issue before the justices was whether, as the law formerly prescribed, employees must opt in, or affirmatively consent, to having some of their money used in election campaigns.

The justices said that a state could indeed require such consent. But there also is nothing to bar the state from putting the onus on nonmember workers to opt out, or seek a refund of a portion of their fees.

That, in effect, is what Washington law now requires after the recent change.