The invalid state error occurs when the state parameter in the login request doesn’t match the one generated, stored, or validated during the login flow.
In this situation, I recommend checking your network activity to verify that the state parameter in the login request matches the one you get when you are redirected to the callback URL (redirect_uri).
Finally found the problem. Seems that the user we were trying to log with had been previously created on WordPress via another login plugin, which was causing a conflict. Closing this.