Google OAuth 2.0 devuelve 400 "Bad Request" incluso desde Playground

Estoy tratando de usar elBiblioteca de cliente PHP League OAuth2 para autenticación en mi aplicación CodeIgniter. Sin embargo, siempre recibo el error 400 "Solicitud incorrecta". Entonces, intenté usar mi propio ID de cliente y secreto de cliente a través deEl patio de juegos OAuth 2.0 de Google y da el mismo error. CuriosamenteJasper Reports Community aparece el mismo error cuando intento iniciar sesión con mi cuenta de Google. De vuelta al campo de juego, probé el inicio de sesión de Google Plus y el antiguo punto final. ¿Google ha tenido una interrupción?

La URL que falla es

https://accounts.google.com/o/oauth2/auth?
client_id=xxxxx-xxxxx.apps.googleusercontent.com
&redirect_uri=mywebsite.com%2Fauth%2Fsession%2Fgoogle
&state=yyyyyzzzzzwwwww
&scope=profile
&response_type=code
&approval_prompt=auto

(El estado de las variables, redirect_uri, etc. se ha ocultado por seguridad). Aquí está mi código de controlador, basado en el ejemplo de Phil Sturgeon:

class Auth extends CI_Controller {
    public function __construct() {
        parent::__construct();
        log_message('debug', 'Auth: controller loaded.');
    }

    public function session($provider_name) {
        $this->load->helper('url_helper');
        switch (strtolower($provider_name)) {
            case "eventbrite":
                $provider_name = 'Eventbrite';
                break;
            case "facebook":
                $provider_name = 'Facebook';
                break;
            case "github":
                $provider_name = 'Github';
                break;
            case "google":
                $provider_name = 'Google';
                break;
            case "instagram":
                $provider_name = 'Instagram';
                break;
            case "linkedin":
                $provider_name = 'LinkedIn';
                break;
            case "microsoft":
                $provider_name = 'Microsoft';
                break;
            case "vkontakte":
                $provider_name = 'Vkontakte';
                break;
        }

        log_message('debug', 'Auth: session to ' . $provider_name);
        $class = 'League\\OAuth2\\Client\\Provider\\'.$provider_name;
        $provider = new $class(array(
            'clientId'     => $this->config->item('client_id'),
            'clientSecret' => $this->config->item('client_secret'),
            'redirectUri'  => $this->config->item('redirect_uri')
        ));
        log_message('debug', 'Auth: connect ' . $this->config->item('client_id'));

        if (! $this->input->get('code')) {
            // By sending no options it'll come back here
            $url = $provider->getAuthorizationUrl();
            log_message('error', 'Auth: redirect to ' . $url);

            redirect($url);
        } else {
            // Have a go at creating an access token from the code
            // Try to get an access token (using the authorization code grant)
            $token = new stdClass();

            // If you are using Eventbrite you will need to add the grant_type parameter (see below)
            if ($provider_name == 'eventbrite') {
                $token = $provider->getAccessToken('authorization_code', [
                    'code'       => $_GET['code'],
                    'grant_type' => 'authorization_code'
                ]);
            } else {
                $token = $provider->getAccessToken('authorization_code', [
                    'code' => $_GET['code']
                ]);
            }


            // Use this object to try and get some user details (username, full name, etc)
            try {

                // We got an access token, let's now get the user's details
                $userDetails = $provider->getUserDetails($token);

                // Use these details to create a new profile
                //printf('Hello %s!', $userDetails->firstName);

            } catch (Exception $e) {

                // Failed to get user details
                show_error("That didn't work: " . $e);
                log_message('error', "Auth: That didn't work: " . $e);
            }

            // Here you should use this information to A) look for a user B) help a new user sign up with existing data.
            // If you store it all in a cookie and redirect to a registration page this is crazy-simple.
            echo "<pre>Tokens: ";
            var_dump($token);

            echo "\n\nUser Info: ";
            var_dump($userDetails);

        }
    }
}

Respuestas a la pregunta(0)

Su respuesta a la pregunta