-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6085d52
commit dac1e4b
Showing
7 changed files
with
321 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Contributte\OAuth2Client\DI; | ||
|
||
use Contributte\OAuth2Client\Flow\Facebook\FacebookAuthCodeFlow; | ||
use Contributte\OAuth2Client\Flow\Facebook\FacebookProvider; | ||
use Nette\DI\CompilerExtension; | ||
use Nette\Schema\Expect; | ||
use Nette\Schema\Schema; | ||
use stdClass; | ||
|
||
/** | ||
* @property-read stdClass $config | ||
*/ | ||
class FacebookAuthExtension extends CompilerExtension | ||
{ | ||
|
||
public function getConfigSchema(): Schema | ||
{ | ||
return Expect::structure([ | ||
'clientId' => Expect::string()->required(), | ||
'clientSecret' => Expect::string()->required(), | ||
'graphApiVersion' => Expect::string()->required(), | ||
'options' => Expect::array(), | ||
]); | ||
} | ||
|
||
public function loadConfiguration(): void | ||
{ | ||
$builder = $this->getContainerBuilder(); | ||
$config = $this->config; | ||
|
||
$providerOptions = [ | ||
'clientId' => $config->clientId, | ||
'clientSecret' => $config->clientSecret, | ||
'graphApiVersion' => $config->graphApiVersion, | ||
]; | ||
|
||
if (isset($config->options)) { | ||
$providerOptions = array_merge($config->options, $providerOptions); | ||
} | ||
|
||
$builder->addDefinition($this->prefix('provider')) | ||
->setFactory(FacebookProvider::class, [$providerOptions]); | ||
|
||
$builder->addDefinition($this->prefix('authCodeFlow')) | ||
->setFactory(FacebookAuthCodeFlow::class, ['@' . $this->prefix('provider')]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Contributte\OAuth2Client\DI; | ||
|
||
use Contributte\OAuth2Client\Flow\Google\GoogleAuthCodeFlow; | ||
use Contributte\OAuth2Client\Flow\Google\GoogleProvider; | ||
use Nette\DI\CompilerExtension; | ||
use Nette\Schema\Expect; | ||
use Nette\Schema\Schema; | ||
use stdClass; | ||
|
||
/** | ||
* @property-read stdClass $config | ||
*/ | ||
class GoogleAuthExtension extends CompilerExtension | ||
{ | ||
|
||
public function getConfigSchema(): Schema | ||
{ | ||
return Expect::structure([ | ||
'clientId' => Expect::string()->required(), | ||
'clientSecret' => Expect::string()->required(), | ||
'options' => Expect::array(), | ||
]); | ||
} | ||
|
||
public function loadConfiguration(): void | ||
{ | ||
$builder = $this->getContainerBuilder(); | ||
$config = $this->config; | ||
|
||
$providerOptions = [ | ||
'clientId' => $config->clientId, | ||
'clientSecret' => $config->clientSecret, | ||
]; | ||
|
||
if (isset($config->options)) { | ||
$providerOptions = array_merge($config->options, $providerOptions); | ||
} | ||
|
||
$builder->addDefinition($this->prefix('provider')) | ||
->setFactory(GoogleProvider::class, [$providerOptions]); | ||
|
||
$builder->addDefinition($this->prefix('authCodeFlow')) | ||
->setFactory(GoogleAuthCodeFlow::class, ['@' . $this->prefix('provider')]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
use Contributte\OAuth2Client\DI\FacebookAuthExtension; | ||
use Contributte\OAuth2Client\Flow\Facebook\FacebookAuthCodeFlow; | ||
use Contributte\OAuth2Client\Flow\Facebook\FacebookProvider; | ||
use Nette\Bridges\HttpDI\HttpExtension; | ||
use Nette\Bridges\HttpDI\SessionExtension; | ||
use Nette\DI\Compiler; | ||
use Nette\DI\Container; | ||
use Nette\DI\ContainerLoader; | ||
use Tester\Assert; | ||
|
||
require_once __DIR__ . '/../../bootstrap.php'; | ||
|
||
test(function (): void { | ||
$loader = new ContainerLoader(TEMP_DIR, true); | ||
$class = $loader->load(function (Compiler $compiler): void { | ||
$compiler->addExtension('http', new HttpExtension()) | ||
->addExtension('session', new SessionExtension()) | ||
->addExtension('facebook', new FacebookAuthExtension()) | ||
->addConfig([ | ||
'facebook' => [ | ||
'clientId' => 'd5sa4d5', | ||
'clientSecret' => 'as5dd4sa6d54a6s5d4', | ||
'graphApiVersion' => 'v11.0', | ||
], | ||
]); | ||
}, uniqid()); | ||
/** @var Container $container */ | ||
$container = new $class(); | ||
|
||
// Services created | ||
Assert::type(FacebookProvider::class, $container->getService('facebook.provider')); | ||
Assert::type(FacebookAuthCodeFlow::class, $container->getService('facebook.authCodeFlow')); | ||
Assert::type(FacebookProvider::class, $container->getService('facebook.authCodeFlow')->getProvider()); | ||
}); | ||
|
||
test(function (): void { | ||
$loader = new ContainerLoader(TEMP_DIR, true); | ||
$class = $loader->load(function (Compiler $compiler): void { | ||
$compiler->addExtension('http', new HttpExtension()) | ||
->addExtension('session', new SessionExtension()) | ||
->addExtension('facebook', new FacebookAuthExtension()) | ||
->addConfig([ | ||
'facebook' => [ | ||
'clientId' => 'd5sa4d5', | ||
'clientSecret' => 'as5dd4sa6d54a6s5d4', | ||
'graphApiVersion' => 'v11.0', | ||
'options' => [ | ||
'redirectUri' => 'https//localhost/redirect', | ||
], | ||
], | ||
]); | ||
}, uniqid()); | ||
/** @var Container $container */ | ||
$container = new $class(); | ||
|
||
// Services created | ||
Assert::contains('redirect_uri=https%2F%2Flocalhost%2Fredirect', $container->getService('facebook.provider')->getAuthorizationUrl()); | ||
}); | ||
|
||
test(function (): void { | ||
$loader = new ContainerLoader(TEMP_DIR, true); | ||
$class = $loader->load(function (Compiler $compiler): void { | ||
$compiler->addExtension('http', new HttpExtension()) | ||
->addExtension('session', new SessionExtension()) | ||
->addExtension('facebook', new FacebookAuthExtension()) | ||
->addExtension('facebook2', new FacebookAuthExtension()) | ||
->addConfig([ | ||
'facebook' => [ | ||
'clientId' => 'd5sa4d5', | ||
'clientSecret' => 'as5dd4sa6d54a6s5d4', | ||
'graphApiVersion' => 'v11.0', | ||
], | ||
'facebook2' => [ | ||
'clientId' => 'd5sa4d5', | ||
'clientSecret' => 'as5dd4sa6d54a6s5d4', | ||
'graphApiVersion' => 'v10.0', | ||
], | ||
]); | ||
}, uniqid()); | ||
/** @var Container $container */ | ||
$container = new $class(); | ||
|
||
// Services created | ||
Assert::type(FacebookProvider::class, $container->getService('facebook.provider')); | ||
Assert::type(FacebookAuthCodeFlow::class, $container->getService('facebook.authCodeFlow')); | ||
Assert::type(FacebookProvider::class, $container->getService('facebook.authCodeFlow')->getProvider()); | ||
Assert::contains('/v11.0/', $container->getService('facebook.authCodeFlow')->getProvider()->getBaseAuthorizationUrl()); | ||
Assert::type(FacebookProvider::class, $container->getService('facebook2.provider')); | ||
Assert::type(FacebookAuthCodeFlow::class, $container->getService('facebook2.authCodeFlow')); | ||
Assert::type(FacebookProvider::class, $container->getService('facebook2.authCodeFlow')->getProvider()); | ||
Assert::contains('/v10.0/', $container->getService('facebook2.authCodeFlow')->getProvider()->getBaseAuthorizationUrl()); | ||
}); |
Oops, something went wrong.