Skip to content

Commit

Permalink
Implement Yandex support
Browse files Browse the repository at this point in the history
  • Loading branch information
bladeofsteel committed Dec 2, 2013
1 parent 0023cc3 commit e772852
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 0 deletions.
1 change: 1 addition & 0 deletions autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'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\HybridAuth\Provider\Yandex' => __DIR__ . '/src/ScnSocialAuth/HybridAuth/Provider/Yandex.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',
Expand Down
7 changes: 7 additions & 0 deletions config/scn-social-auth.global.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ $settings = array(
*/
//'vkontakte_enabled' => true,

/**
* Yandex Enabled
*
* Please specify if Yandex is enabled
*/
//'yandex_enabled' => true,

/**
* Set to true if you want to display only the social login buttons without
* the username/password etc. from ZfcUser.
Expand Down
14 changes: 14 additions & 0 deletions config/scn-social-auth.local.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ $settings = array(
*/
//'vkontakte_secret' => 'your-secret',

/**
* Yandex Application ID
*
* Please specify a Yandex Application ID
*/
//'yandex_app_id' => 'your-app-id',

/**
* Yandex Secret
*
* Please specify a Yandex Secret
*/
//'yandex_secret' => 'your-secret',

/**
* Odnoklassniki Client ID
*
Expand Down
11 changes: 11 additions & 0 deletions src/ScnSocialAuth/Authentication/Adapter/HybridAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,17 @@ protected function vkontakteToLocalUser($userProfile)
return $localUser;
}

protected function yandexToLocalUser($userProfile)
{
$localUser = $this->instantiateLocalUser();
$localUser->setDisplayName($userProfile->displayName)
->setPassword(__FUNCTION__)
->setEmail($userProfile->email);
$result = $this->insert($localUser, 'yandex', $userProfile);

return $localUser;
}

/**
* persists the user in the db, and trigger a pre and post events for it
* @param mixed $user
Expand Down
7 changes: 7 additions & 0 deletions src/ScnSocialAuth/HybridAuth/Provider/Yandex.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
namespace ScnSocialAuth\HybridAuth\Provider;

/**
* This is simply to trigger autoloading as a hack for poor design in HybridAuth.
*/
class Yandex extends \Hybrid_Providers_Yandex {}
64 changes: 64 additions & 0 deletions src/ScnSocialAuth/Options/ModuleOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ModuleOptions extends AbstractOptions
'mailru',
'odnoklassniki',
'vkontakte',
'yandex',
);

/**
Expand Down Expand Up @@ -205,6 +206,21 @@ class ModuleOptions extends AbstractOptions
*/
protected $vkontakteSecret;

/**
* @var boolean
*/
protected $yandexEnabled = false;

/**
* @var string
*/
protected $yandexAppId;

/**
* @var string
*/
protected $yandexSecret;

/**
* @var boolean
*/
Expand Down Expand Up @@ -1111,6 +1127,54 @@ public function getVkontakteSecret()
return $this->vkontakteSecret;
}

/**
* @param string $yandexAppId
*/
public function setYandexAppId($yandexAppId)
{
$this->yandexAppId = (string) $yandexAppId;
}

/**
* @return string
*/
public function getYandexAppId()
{
return $this->yandexAppId;
}

/**
* @param boolean $yandexEnabled
*/
public function setYandexEnabled($yandexEnabled)
{
$this->yandexEnabled = (bool) $yandexEnabled;
}

/**
* @return boolean
*/
public function getYandexEnabled()
{
return $this->yandexEnabled;
}

/**
* @param string $yandexSecret
*/
public function setYandexSecret($yandexSecret)
{
$this->yandexSecret = (string) $yandexSecret;
}

/**
* @return string
*/
public function getYandexSecret()
{
return $this->yandexSecret;
}

/**
* get social login only
*
Expand Down
11 changes: 11 additions & 0 deletions src/ScnSocialAuth/Service/HybridAuthFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ public function createService(ServiceLocatorInterface $services)
'path' => realpath(__DIR__ . '/../HybridAuth/Provider/Vkontakte.php'),
),
),
'Yandex' => array(
'enabled' => $options->getYandexEnabled(),
'keys' => array(
'id' => $options->getYandexAppId(),
'secret' => $options->getYandexSecret(),
),
'wrapper' => array(
'class' => 'Hybrid_Providers_Yandex',
'path' => realpath(__DIR__ . '/../HybridAuth/Provider/Yandex.php'),
),
),
),
)
);
Expand Down

0 comments on commit e772852

Please sign in to comment.