Skip to content

Commit

Permalink
Merge pull request #44 from DraperStudio/master
Browse files Browse the repository at this point in the history
Properly set and get configuration, Style fixes
  • Loading branch information
AndyWendt committed Apr 12, 2016
2 parents f986090 + 731d1cb commit 8770267
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 87 deletions.
4 changes: 2 additions & 2 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class Config implements Contracts\ConfigInterface
public function __construct($key, $secret, $callbackUri, array $additionalProviderConfig = [])
{
$this->config = array_merge([
'client_id' => $key,
'client_id' => $key,
'client_secret' => $secret,
'redirect' => $callbackUri,
'redirect' => $callbackUri,
], $additionalProviderConfig);
}

Expand Down
32 changes: 32 additions & 0 deletions src/ConfigTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace SocialiteProviders\Manager;

use SocialiteProviders\Manager\Contracts\ConfigInterface as Config;

trait ConfigTrait
{
protected $config;

public function setConfig(Config $config)
{
$config = $config->get();

$this->config = $config;
$this->clientId = $config['client_id'];
$this->clientSecret = $config['client_secret'];
$this->redirectUrl = $config['redirect'];

return $this;
}

protected function getConfig($key = null, $default = null)
{
return $key ? array_get($this->config, $key, $default) : $this->config;
}

public static function additionalConfigKeys()
{
return [];
}
}
4 changes: 2 additions & 2 deletions src/Contracts/Helpers/ConfigRetrieverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ interface ConfigRetrieverInterface
* @param string $providerIdentifier
* @param array $additionalConfigKeys
*
* @throws MissingConfigException
* @return ConfigInterface
*
* @throws MissingConfigException
*/
public function fromEnv($providerIdentifier, array $additionalConfigKeys = []);

/**
* @param string $providerName
* @param array $additionalConfigKeys
*
* @throws MissingConfigException
* @return ConfigInterface
*
* @throws MissingConfigException
*/
public function fromServices($providerName, array $additionalConfigKeys = []);
}
2 changes: 1 addition & 1 deletion src/Contracts/OAuth1/ProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ interface ProviderInterface
*
* @return $this
*/
public function config(Config $config);
public function setConfig(Config $config);
}
2 changes: 1 addition & 1 deletion src/Contracts/OAuth2/ProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ interface ProviderInterface extends SocialiteOauth2ProviderInterface
*
* @return $this
*/
public function config(Config $config);
public function setConfig(Config $config);
}
16 changes: 8 additions & 8 deletions src/Helpers/ConfigRetriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class ConfigRetriever implements \SocialiteProviders\Manager\Contracts\Helpers\C
* @param string $providerIdentifier
* @param array $additionalConfigKeys
*
* @throws MissingConfigException
* @return ConfigInterface
*
* @throws MissingConfigException
*/
public function fromEnv($providerIdentifier, array $additionalConfigKeys = [])
{
Expand All @@ -48,9 +48,9 @@ public function fromEnv($providerIdentifier, array $additionalConfigKeys = [])
* @param string $providerName
* @param array $additionalConfigKeys
*
* @throws MissingConfigException
* @return ConfigInterface
*
* @throws MissingConfigException
*/
public function fromServices($providerName, array $additionalConfigKeys = [])
{
Expand Down Expand Up @@ -101,9 +101,9 @@ private function retrieveItemsFromConfig(array $keys, \Closure $keyRetrievalClos
/**
* @param string $key
*
* @throws MissingConfigException
* @return string
*
* @throws MissingConfigException
*/
private function getFromServices($key)
{
Expand All @@ -117,9 +117,9 @@ private function getFromServices($key)
/**
* @param string $key
*
* @throws MissingConfigException
* @return string
*
* @throws MissingConfigException
*/
private function getFromEnv($key)
{
Expand All @@ -136,21 +136,21 @@ private function getFromEnv($key)
/**
* @param string $providerName
*
* @throws MissingConfigException
* @return array
*
* @throws MissingConfigException
*/
protected function getConfigFromServicesArray($providerName)
{
/** @var array $configArray */
$configArray = config('services.'.$providerName);

if (empty($configArray)) {
throw new MissingConfigException("There is no services entry for $providerName");
}

$this->servicesArray = $configArray;

return $this->servicesArray;
}
}
38 changes: 7 additions & 31 deletions src/OAuth1/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace SocialiteProviders\Manager\OAuth1;

use SocialiteProviders\Manager\Config;
use SocialiteProviders\Manager\SocialiteWasCalled;
use Symfony\Component\HttpFoundation\RedirectResponse;
use SocialiteProviders\Manager\ConfigTrait;

abstract class AbstractProvider extends \Laravel\Socialite\One\AbstractProvider
{
use ConfigTrait;

/**
* Indicates if the session state should be utilized.
*
Expand All @@ -25,21 +27,6 @@ public static function serviceContainerKey($providerName)
return SocialiteWasCalled::SERVICE_CONTAINER_PREFIX.$providerName;
}

/**
* @param Config $config
*
* @return $this
*/
public function config(Config $config)
{
$config = $config->get();
$this->clientId = $config['client_id'];
$this->redirectUrl = $config['redirect'];
$this->clientSecret = $config['client_secret'];

return $this;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -136,23 +123,11 @@ protected function isStateless()
return $this->stateless;
}

public static function additionalConfigKeys()
{
return [];
}

/**
* Map the raw user array to a Socialite User instance.
*
* @param array $user
* @return \Laravel\Socialite\Two\User
*/
abstract protected function mapUserToObject(array $user);

/**
* Set the scopes of the requested access.
*
* @param array $scopes
* @param array $scopes
*
* @return $this
*/
public function scopes(array $scopes)
Expand All @@ -165,7 +140,8 @@ public function scopes(array $scopes)
/**
* Set the custom parameters of the request.
*
* @param array $parameters
* @param array $parameters
*
* @return $this
*/
public function with(array $parameters)
Expand Down
17 changes: 10 additions & 7 deletions src/OAuth1/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getTokenCredentials(TemporaryCredentials $temporaryCredentials,
}

$uri = $this->urlTokenCredentials();
$bodyParameters = array('oauth_verifier' => $verifier);
$bodyParameters = ['oauth_verifier' => $verifier];

$client = $this->createHttpClient();

Expand All @@ -63,15 +63,16 @@ public function getTokenCredentials(TemporaryCredentials $temporaryCredentials,
}

return [
'tokenCredentials' => $this->createTokenCredentials($response->getBody()),
'tokenCredentials' => $this->createTokenCredentials($response->getBody()),
'credentialsResponseBody' => $response->getBody(),
];
}

/**
* Set the scopes of the requested access.
*
* @param array $scopes
* @param array $scopes
*
* @return $this
*/
public function scopes(array $scopes)
Expand All @@ -84,7 +85,8 @@ public function scopes(array $scopes)
/**
* Set the custom parameters of the request.
*
* @param array $parameters
* @param array $parameters
*
* @return $this
*/
public function with(array $parameters)
Expand All @@ -93,12 +95,13 @@ public function with(array $parameters)

return $this;
}

/**
* Format the given scopes.
*
* @param array $scopes
* @param string $scopeSeparator
* @param array $scopes
* @param string $scopeSeparator
*
* @return string
*/
protected function formatScopes(array $scopes, $scopeSeparator)
Expand Down
26 changes: 4 additions & 22 deletions src/OAuth2/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
use Laravel\Socialite\Two\InvalidStateException;
use SocialiteProviders\Manager\Contracts\OAuth2\ProviderInterface;
use SocialiteProviders\Manager\SocialiteWasCalled;
use SocialiteProviders\Manager\Contracts\ConfigInterface as Config;
use SocialiteProviders\Manager\ConfigTrait;

abstract class AbstractProvider extends \Laravel\Socialite\Two\AbstractProvider implements ProviderInterface
{
use ConfigTrait;

/**
* @var array
*/
Expand All @@ -20,26 +22,6 @@ public static function serviceContainerKey($providerName)
return SocialiteWasCalled::SERVICE_CONTAINER_PREFIX.$providerName;
}

public static function additionalConfigKeys()
{
return [];
}

/**
* @param Config $config
*
* @return $this
*/
public function config(Config $config)
{
$config = $config->get();
$this->clientId = $config['client_id'];
$this->redirectUrl = $config['redirect'];
$this->clientSecret = $config['client_secret'];

return $this;
}

/**
* @return \SocialiteProviders\Manager\OAuth2\User
*/
Expand Down Expand Up @@ -75,7 +57,7 @@ public function getAccessToken($code)

$response = $this->getHttpClient()->post($this->getTokenUrl(), [
'headers' => ['Accept' => 'application/json'],
$postKey => $this->getTokenFields($code),
$postKey => $this->getTokenFields($code),
]);

$this->credentialsResponseBody = json_decode($response->getBody(), true);
Expand Down
Loading

0 comments on commit 8770267

Please sign in to comment.