Search code examples
symfonygoogle-oauth

Redirect uri not working


I'm trying to implement the oauth google authentication in symfony2 with hwi oauth bundle. I added the button and the popup open and succesfull autenticate the user and then execute my signinCallback function in javascript. The problem is that i need register the user in the database after the login action, so I configured the redirect_uri for that reason. I test the action with a succesfull autentication with github, without popup, just creating a <a href="https://github.com/login/oauth/authorize?scope=user:email&client_id=MY_ID">Click here</a>, and that redirect to that page and after autentication redirect me to the correct redirect uri. The problem with google is that after a succesfull atentication only call the javascript function, not to the configured uri. Is there a way to make the google autentication in the same way of github?. I also try in the signinCallback function call document.location = "{{ url("hwi_oauth_service_redirect", {service: "google"}) }}" , but get some error related to required parameters of course .


Solution

  • If it helps someone that's how I solved:

    function signinCallback(authResult) {
            if (authResult['access_token']) {
                // Properly authorized
                // Hide the button
                document.getElementById('customBtn').setAttribute('style', 'display: none');
                document.location = "{{ url("hwi_oauth_service_redirect", {service: "google"}) }}";
            } else if (authResult['error']) {
                // If error
                // console.log('There was an error: ' + authResult['error']);
            }
        }