CakeDC / users

Users Plugin for CakePHP
https://www.cakedc.com
Other
521 stars 297 forks source link

SocialLogin and registration #925

Closed sasilen closed 3 years ago

sasilen commented 3 years ago

I tried this CakeDC plugin and I am not sure did I understand correctly. (Current latest cakephp, and master branch from CakeDC)

When I created superadmin and logged in, I can use google login and accounts were linked and everything seems to work

Social account was associated.

But If I haven't logged in first I will get (and profile page of course goes redirect loop)

Could not associate account, please try again.
Not authorized, please login first

Is there some configuration option for automatically provisioning these users to the users table? or is this meant to work so that you have to register first before you can link your social account? Or is this just some permission problems I should be aware of?

Thanks, // Sami

sasilen commented 3 years ago

There seems to be error when I try to login with social account Error: Error linking social account: Record not found in table "users" with primary key [NULL] Cake\Datasource\Exception\InvalidPrimaryKeyException: Record not found in table "users" with primary key [NULL] in vendor/cakephp/cakephp/src/ORM/Table.php:1493

Which works If I have already logged in as superadmin.

rochamarcelo commented 3 years ago

@sasilen which url are you using?

Not logged user is able to access using social account at /auth/facebook (/auth/twitter) url Logged he can link a social account to his account (there is a link in profile page)

sasilen commented 3 years ago

@sasilen which url are you using?

I am using /link-social/google, it looks like it tries to redirect to that profile page after successful google login but there I get "Not authorized, please login first". There are no records created on users table. Google login seems to be successful but user is not created nor logged in. "auth/google" gives me "Could not proceed with social account. Please try again"

It looks like permission issues, because if I am superadmin already logged and access /link-social/google, linking happens. and records are created to social_accounts table

rochamarcelo commented 3 years ago

@sasilen for Non-logged user you must use /auth/google.

It seems that you have created custom tables for users or social accounts, please check validations

sasilen commented 3 years ago

I am not using custom tables, but those are tables from earlier installation. I'll try again from the scratch if those are changed somehow.

sasilen commented 3 years ago

No its not about old tables, I dropped phinx* and users and social_accounts tables and performed migration again. Same results /auth/google -> "Could not proceed with social account. Please try again"

rochamarcelo commented 3 years ago

@sasilen I mean custom model tables Model/Table/UsersTable and Model/Table/SocialAccountsTable

rochamarcelo commented 3 years ago

Please let me know which configs and classes you have overwritten .

sasilen commented 3 years ago

I don't have any custom models not overwrites, and overwritten just those config options which are in the documentation (https://github.com/CakeDC/users/blob/master/Docs/Documentation/Installation.md).

Configure::write('OAuth.providers.google.options.clientId','<clientid>);
Configure::write('OAuth.providers.google.options.clientSecret','<clientsecret>');
Configure::write('OAuth.providers.google.options.redirectUri','https://url/auth/google');
Configure::write('Users.Social.login', true);
Configure::write('Users.Email.validate', false);
$this->addPlugin('CakeDC/Users');

I am playing with quite plain cake and cakedc/users also my permissions.php is quite default just made it little wider. Guess I am missing something?

rochamarcelo commented 3 years ago

@sasilen please check this example https://github.com/CakeDC/users-example we set configs at this file https://github.com/CakeDC/users-example/blob/master/config/users.php.

This example works for me. Please compare with your project.

sasilen commented 3 years ago

Thanks,

I really don't understand what was wrong. I restarted my project and only thing I made differently on my opinion was that I now used users.php like in the example and not those Configure:write lines in my Application.php.

You're the Man @rochamarcelo!