cakephp-3.0google-authenticationcakedc

How to make redirection work properly for google login on CakeDC's user plugin?


I'm using cakeDC's users plugin (8.5.1) to restrict my CakePHP (3.89) site to only members of my organization and have followed these directions:

https://www.cakedc.com/jorge_gonzalez/2016/10/11/create_google_app_for_web_oauth2_login_step_by_step

https://www.cakedc.com/jorge_gonzalez/2016/10/11/login-with-google-oauth2-in-cakephp-using-cakedc-users-plugin

I added these two lines to my bootstrap.php file, which was slightly different from what the directions said:

Configure::write('Users.config', ['users']); //add this line before Plugin::load('CakeDC/Users...
$this->addPlugin('CakeDC/Users', ['routes' => true, 'bootstrap' => true]);

my site is https://internal.domain.com

if not logged in, it redirects to:

https://internal.domain.com/login

after login, google redirects to

https://internal.domain.com/auth/google?state=XXXXXXX&code=4/XXXXXXX&scope=XXXXXX&authuser=XXXX&hd=XXXXXX&prompt=XXXX&session_state=XXXXXX

which doesn't work as a page, that is there's no route set up for it in cake:

Database Error PDOException Error: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'avatar' at row 1

From logs I can see that the user isn't being logged in, so it's makes me believe I've done something wrong in the install.

Is it just redirecting to the wrong page here or is the plugin installed incorrectly? Google won't let me change the redirect_uri to anything else, that is to say if I put a different address there, it will say there's a uri_redirect mismatch on login and give me the link to the console to fix it.


Solution

  • Specific routes are added to match all your social login enabled providers here https://github.com/CakeDC/users/blob/8.5.1/config/bootstrap.php#L37

    Please check the route was correctly created via bin/cake routes and the google provider configuration is correctly set, see https://github.com/CakeDC/users/blob/8.5.1/Docs/Documentation/SocialAuthenticate.md#setup