From 7889ebcd0b0492cd813ba52160134b93c2ad960d Mon Sep 17 00:00:00 2001 From: Oleg Lobach Date: Sun, 1 Dec 2013 03:45:56 +0400 Subject: [PATCH] Implement Vkontakte support --- autoload_classmap.php | 1 + config/scn-social-auth.global.php.dist | 7 ++ config/scn-social-auth.local.php.dist | 14 ++++ .../Authentication/Adapter/HybridAuth.php | 10 +++ .../HybridAuth/Provider/Vkontakte.php | 7 ++ src/ScnSocialAuth/Options/ModuleOptions.php | 64 +++++++++++++++++++ .../Service/HybridAuthFactory.php | 11 ++++ 7 files changed, 114 insertions(+) create mode 100644 src/ScnSocialAuth/HybridAuth/Provider/Vkontakte.php diff --git a/autoload_classmap.php b/autoload_classmap.php index 96b28fb4..7601eee9 100644 --- a/autoload_classmap.php +++ b/autoload_classmap.php @@ -14,6 +14,7 @@ 'ScnSocialAuth\HybridAuth\Provider\Tumblr' => __DIR__ . '/src/ScnSocialAuth/HybridAuth/Provider/Tumblr.php', 'ScnSocialAuth\HybridAuth\Provider\Mailru' => __DIR__ . '/src/ScnSocialAuth/HybridAuth/Provider/Mailru.php', 'ScnSocialAuth\HybridAuth\Provider\Odnoklassniki' => __DIR__ . '/src/ScnSocialAuth/HybridAuth/Provider/Odnoklassniki.php', + 'ScnSocialAuth\HybridAuth\Provider\Vkontakte' => __DIR__ . '/src/ScnSocialAuth/HybridAuth/Provider/Vkontakte.php', 'ScnSocialAuth\Mapper\Exception\ExceptionInterface' => __DIR__ . '/src/ScnSocialAuth/Mapper/Exception/ExceptionInterface.php', 'ScnSocialAuth\Mapper\Exception\RuntimeException' => __DIR__ . '/src/ScnSocialAuth/Mapper/Exception/RuntimeException.php', 'ScnSocialAuth\Mapper\UserProvider' => __DIR__ . '/src/ScnSocialAuth/Mapper/UserProvider.php', diff --git a/config/scn-social-auth.global.php.dist b/config/scn-social-auth.global.php.dist index 3487e549..52ccc34e 100644 --- a/config/scn-social-auth.global.php.dist +++ b/config/scn-social-auth.global.php.dist @@ -148,6 +148,13 @@ $settings = array( */ //'odnoklassniki_enabled' => true, + /** + * Vkontakte Enabled + * + * Please specify if Vkontakte is enabled + */ + //'vkontakte_enabled' => true, + /** * Set to true if you want to display only the social login buttons without * the username/password etc. from ZfcUser. diff --git a/config/scn-social-auth.local.php.dist b/config/scn-social-auth.local.php.dist index 88bb37de..30ab2d36 100644 --- a/config/scn-social-auth.local.php.dist +++ b/config/scn-social-auth.local.php.dist @@ -139,6 +139,20 @@ $settings = array( */ //'mailru_secret' => 'your-secret', + /** + * Vkontakte Application ID + * + * Please specify a Vkontakte Application ID + */ + //'vkontakte_app_id' => 'your-app-id', + + /** + * Vkontakte Secret + * + * Please specify a Vkontakte Secret + */ + //'vkontakte_secret' => 'your-secret', + /** * Odnoklassniki Client ID * diff --git a/src/ScnSocialAuth/Authentication/Adapter/HybridAuth.php b/src/ScnSocialAuth/Authentication/Adapter/HybridAuth.php index 1535e04e..ec9949a5 100644 --- a/src/ScnSocialAuth/Authentication/Adapter/HybridAuth.php +++ b/src/ScnSocialAuth/Authentication/Adapter/HybridAuth.php @@ -469,6 +469,16 @@ protected function odnoklassnikiToLocalUser($userProfile) return $localUser; } + protected function vkontakteToLocalUser($userProfile) + { + $localUser = $this->instantiateLocalUser(); + $localUser->setDisplayName($userProfile->displayName) + ->setPassword(__FUNCTION__); + $result = $this->insert($localUser, 'vkontakte', $userProfile); + + return $localUser; + } + /** * persists the user in the db, and trigger a pre and post events for it * @param mixed $user diff --git a/src/ScnSocialAuth/HybridAuth/Provider/Vkontakte.php b/src/ScnSocialAuth/HybridAuth/Provider/Vkontakte.php new file mode 100644 index 00000000..aadbb1ac --- /dev/null +++ b/src/ScnSocialAuth/HybridAuth/Provider/Vkontakte.php @@ -0,0 +1,7 @@ +odnoklassnikiSecret; } + /** + * @param string $vkontakteAppId + */ + public function setVkontakteAppId($vkontakteAppId) + { + $this->vkontakteAppId = (string) $vkontakteAppId; + } + + /** + * @return string + */ + public function getVkontakteAppId() + { + return $this->vkontakteAppId; + } + + /** + * @param boolean $vkontakteEnabled + */ + public function setVkontakteEnabled($vkontakteEnabled) + { + $this->vkontakteEnabled = (bool) $vkontakteEnabled; + } + + /** + * @return boolean + */ + public function getVkontakteEnabled() + { + return $this->vkontakteEnabled; + } + + /** + * @param string $vkontakteSecret + */ + public function setVkontakteSecret($vkontakteSecret) + { + $this->vkontakteSecret = (string) $vkontakteSecret; + } + + /** + * @return string + */ + public function getVkontakteSecret() + { + return $this->vkontakteSecret; + } + /** * get social login only * diff --git a/src/ScnSocialAuth/Service/HybridAuthFactory.php b/src/ScnSocialAuth/Service/HybridAuthFactory.php index facaf13b..1dc939b9 100644 --- a/src/ScnSocialAuth/Service/HybridAuthFactory.php +++ b/src/ScnSocialAuth/Service/HybridAuthFactory.php @@ -127,6 +127,17 @@ public function createService(ServiceLocatorInterface $services) 'path' => realpath(__DIR__ . '/../HybridAuth/Provider/Odnoklassniki.php'), ), ), + 'Vkontakte' => array( + 'enabled' => $options->getVkontakteEnabled(), + 'keys' => array( + 'id' => $options->getVkontakteAppId(), + 'secret' => $options->getVkontakteSecret(), + ), + 'wrapper' => array( + 'class' => 'Hybrid_Providers_Vkontakte', + 'path' => realpath(__DIR__ . '/../HybridAuth/Provider/Vkontakte.php'), + ), + ), ), ) );