Closed dantart closed 3 weeks ago
Guys, this is insane ... after debugging a lot I fixed it with this:
adding
return $account;
in line 95 of https://github.com/2amigos/yii2-usuario/blob/master/src/User/Service/SocialNetworkAccountConnectService.php
if not, that function returns "false" (when the account already exists in the social_account table), and that "false" is tried to be injected in the Da\User\Event\SocialNetworkAuthEvent class, therefore, the above error appears.
Can't believe this is happen just to me.
I never used social auth, but indeed your fix looks correct...
Same happened here, worked with this fix in PHP 7.4.12.
Guys, this is insane ... after debugging a lot I fixed it with this:
adding
return $account;
in line 95 of https://github.com/2amigos/yii2-usuario/blob/master/src/User/Service/SocialNetworkAccountConnectService.php
if not, that function returns "false" (when the account already exists in the social_account table), and that "false" is tried to be injected in the Da\User\Event\SocialNetworkAuthEvent class, therefore, the above error appears.
Can't believe this is happen just to me.
This is old but I've just stumbled on it today.
Happened when trying to connect to an already taken Social Network Account from a random logged User.
Solution is precisely what reported above in this thread. Here I'm just confirming:
replace return false
with return $account
in Da\User\Service\SocialNetworkAccountConnectService::getSocialNetworkAccount()
with this fix, you'll see this: instead of
Because Da\User\Service\SocialNetworkAccountConnectService::run()
can move forward with the validation.
I would also add a note, even if maybe this is worth the creation of an additional issue.
When creating the new social
record, only the client_id
, data
and provider
fields get populated.
As an enhancement:
Given we do have a Contract (aka Interface) called AuthClientInterface
and that particular Interface imposes to add in the extra methods getEmail()
and getUserName()
, it would be ideal to use them in Da\User\Service\SocialNetworkAccountConnectService::getSocialNetworkAccount()
to populate the email
and username
fields of the new social
record.
This already happens for Da\User\Service\SocialNetworkAuthenticateService
with this fix, you'll see this:
This error is thrown when attempting a second registration? If so, make a PR and I'll merge
When I use for FIRST time it works perfectly, and save record in the database.
But when I try to use it as second time (with an already registered user), I always have this error when coming back from the social network:
Argument 1 passed to Da\User\Event\SocialNetworkAuthEvent::__construct() must be an instance of Da\User\Model\SocialNetworkAccount, bool given
The URL at top is like this (in case of Google, but it happens with all social networks) https://mydomain.com/user/security/authclient/google?state=XXXXXXXXXXXXXXXXXXXXXXXX&code=XXXXXXXXXXXXXXXXXXXXXXXX&scope=email+profile+openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&authuser=7&prompt=none#
Why is this?
It starts with the "SocialNetworkAuthEvent" object, but in some point , it's "lost" with a "false":
(this screenshot is with LinkedIn ... as I said, it happens with all social networks)