Skip to content

Commit

Permalink
Merge pull request #118 from bladeofsteel/add-vkontakte-support
Browse files Browse the repository at this point in the history
Implement Vkontakte support
  • Loading branch information
SocalNick committed Dec 2, 2013
2 parents 394865f + 7889ebc commit 82b296d
Show file tree
Hide file tree
Showing 7 changed files with 114 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 @@ -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',
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 @@ -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.
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 @@ -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
*
Expand Down
10 changes: 10 additions & 0 deletions src/ScnSocialAuth/Authentication/Adapter/HybridAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/ScnSocialAuth/HybridAuth/Provider/Vkontakte.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 Vkontakte extends \Hybrid_Providers_Vkontakte {}
64 changes: 64 additions & 0 deletions src/ScnSocialAuth/Options/ModuleOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ModuleOptions extends AbstractOptions
'tumblr',
'mailru',
'odnoklassniki',
'vkontakte',
);

/**
Expand Down Expand Up @@ -189,6 +190,21 @@ class ModuleOptions extends AbstractOptions
*/
protected $mailruSecret;

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

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

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

/**
* @var boolean
*/
Expand Down Expand Up @@ -1047,6 +1063,54 @@ public function getOdnoklassnikiSecret()
return $this->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
*
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 @@ -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'),
),
),
),
)
);
Expand Down

0 comments on commit 82b296d

Please sign in to comment.