Skip to content

Commit

Permalink
added a way to get the service container key
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyWendt committed Jan 18, 2016
1 parent 32eaad3 commit e7d4f0e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/OAuth2/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use GuzzleHttp\ClientInterface;
use Laravel\Socialite\Two\InvalidStateException;
use SocialiteProviders\Manager\SocialiteWasCalled;

abstract class AbstractProvider extends \Laravel\Socialite\Two\AbstractProvider
{
Expand All @@ -11,6 +12,11 @@ abstract class AbstractProvider extends \Laravel\Socialite\Two\AbstractProvider
*/
protected $credentialsResponseBody;

public static function serviceContainerKey($providerName)
{
return SocialiteWasCalled::SERVICE_CONTAINER_PREFIX . $providerName;
}

/**
* @return \SocialiteProviders\Manager\OAuth2\User
*/
Expand Down
4 changes: 3 additions & 1 deletion src/SocialiteWasCalled.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

class SocialiteWasCalled
{
const SERVICE_CONTAINER_PREFIX = 'SocialiteProviders.config.';

/**
* @var LaravelApp
*/
Expand Down Expand Up @@ -105,7 +107,7 @@ protected function getConfig($providerName)
{
try {
/** @var Contracts\ConfigInterface $config */
$config = $this->app->make('SocialiteProviders.config.' . $providerName);
$config = $this->app->make(self::SERVICE_CONTAINER_PREFIX . $providerName);

if (!($config instanceof Contracts\ConfigInterface)) {
throw new InvalidArgumentException('Config class does not implement config contract');
Expand Down
17 changes: 17 additions & 0 deletions tests/OAuthTwoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ public function redirectGeneratesTheProperSymfonyRedirectResponse()
$this->assertEquals('http://auth.url', $response->getTargetUrl());
}

/**
* @test
*/
public function it_can_return_the_service_container_key()
{
$result = OAuthTwoTestProviderStub::serviceContainerKey(OAuthTwoTestProviderStub::PROVIDER_NAME);

$this->assertEquals('SocialiteProviders.config.test', $result);
}

/**
* @test
*/
Expand Down Expand Up @@ -119,8 +129,15 @@ public function exceptionIsThrownIfStateIsNotSet()

class OAuthTwoTestProviderStub extends AbstractProvider
{
const PROVIDER_NAME = 'test';

public $http;

public static function providerName()
{
return 'test';
}

protected function getAuthUrl($state)
{
return 'http://auth.url';
Expand Down

0 comments on commit e7d4f0e

Please sign in to comment.