From a7e044febf6d5ae0548043569f056cfdfb02f88a Mon Sep 17 00:00:00 2001 From: Elias Luhr Date: Fri, 5 Jan 2024 14:56:15 +0100 Subject: [PATCH] Make user id attribute for social network authentification configurable --- src/User/Contracts/AuthClientInterface.php | 10 ++++++++-- .../Service/SocialNetworkAccountConnectService.php | 2 +- src/User/Service/SocialNetworkAuthenticateService.php | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/User/Contracts/AuthClientInterface.php b/src/User/Contracts/AuthClientInterface.php index 6aad034..84e284b 100644 --- a/src/User/Contracts/AuthClientInterface.php +++ b/src/User/Contracts/AuthClientInterface.php @@ -14,8 +14,9 @@ namespace Da\User\Contracts; use yii\authclient\ClientInterface; /** - * @property-read string $email - * @property-read string $username + * @property-read string|null $email + * @property-read string|null $userName + * @property-read mixed|null $userId */ interface AuthClientInterface extends ClientInterface { @@ -28,4 +29,9 @@ interface AuthClientInterface extends ClientInterface * @return string|null username */ public function getUserName(); + + /** + * @return mixed|null user id + */ + public function getUserId(); } diff --git a/src/User/Service/SocialNetworkAccountConnectService.php b/src/User/Service/SocialNetworkAccountConnectService.php index 2d6a7a5..366c5f8 100644 --- a/src/User/Service/SocialNetworkAccountConnectService.php +++ b/src/User/Service/SocialNetworkAccountConnectService.php @@ -83,7 +83,7 @@ class SocialNetworkAccountConnectService implements ServiceInterface [], [ 'provider' => $this->client->getId(), - 'client_id' => $data['id'], + 'client_id' => $this->client->getUserId(), 'data' => json_encode($data), ] ); diff --git a/src/User/Service/SocialNetworkAuthenticateService.php b/src/User/Service/SocialNetworkAuthenticateService.php index ded5f47..b990670 100644 --- a/src/User/Service/SocialNetworkAuthenticateService.php +++ b/src/User/Service/SocialNetworkAuthenticateService.php @@ -97,7 +97,7 @@ class SocialNetworkAuthenticateService implements ServiceInterface [], [ 'provider' => $this->client->getId(), - 'client_id' => $data['id'], + 'client_id' => $this->client->getUserId(), 'data' => json_encode($data), 'username' => $this->client->getUserName(), 'email' => $this->client->getEmail(),