-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #418 from malteschlueter/feature/add-passage-provider
Add new provider Passage
- Loading branch information
Showing
7 changed files
with
143 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/* | ||
* OAuth2 Client Bundle | ||
* Copyright (c) KnpUniversity <http://knpuniversity.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace KnpU\OAuth2ClientBundle\Client\Provider; | ||
|
||
use KnpU\OAuth2ClientBundle\Client\OAuth2Client; | ||
use League\OAuth2\Client\Provider\Passage; | ||
use League\OAuth2\Client\Provider\PassageUser; | ||
use League\OAuth2\Client\Provider\ResourceOwnerInterface; | ||
use League\OAuth2\Client\Token\AccessToken; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
|
||
class PassageClient extends OAuth2Client | ||
{ | ||
/** | ||
* @return PassageUser|ResourceOwnerInterface | ||
*/ | ||
public function fetchUserFromToken(AccessToken $accessToken) | ||
{ | ||
return parent::fetchUserFromToken($accessToken); | ||
} | ||
|
||
/** | ||
* @return PassageUser|ResourceOwnerInterface | ||
*/ | ||
public function fetchUser() | ||
{ | ||
return parent::fetchUser(); | ||
} | ||
|
||
public function logout(): RedirectResponse | ||
{ | ||
$provider = $this->getOAuth2Provider(); | ||
|
||
if (!($provider instanceof Passage)) { | ||
throw new \RuntimeException('Invalid provider "'.\get_class($provider).'", expected provider "'.Passage::class.'"'); | ||
} | ||
|
||
return new RedirectResponse($provider->getLogoutUrl()); | ||
} | ||
} |
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
66 changes: 66 additions & 0 deletions
66
src/DependencyInjection/Providers/PassageProviderConfiguration.php
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,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* OAuth2 Client Bundle | ||
* Copyright (c) KnpUniversity <http://knpuniversity.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace KnpU\OAuth2ClientBundle\DependencyInjection\Providers; | ||
|
||
use KnpU\OAuth2ClientBundle\Client\Provider\PassageClient; | ||
use League\OAuth2\Client\Provider\Passage; | ||
use Symfony\Component\Config\Definition\Builder\NodeBuilder; | ||
|
||
class PassageProviderConfiguration implements ProviderConfiguratorInterface | ||
{ | ||
public function buildConfiguration(NodeBuilder $node): void | ||
{ | ||
$node | ||
->scalarNode('sub_domain') | ||
->isRequired() | ||
->info('Passage sub domain. For example, from passage url "https://example.withpassage.com" only "example" is required.') | ||
->example('sub_domain: \'%env(OAUTH_PASSAGE_SUB_DOMAIN)%\'') | ||
->example('sub_domain: \'example\'') | ||
->end() | ||
; | ||
} | ||
|
||
public function getProviderClass(array $configuration): string | ||
{ | ||
return Passage::class; | ||
} | ||
|
||
public function getClientClass(array $config): string | ||
{ | ||
return PassageClient::class; | ||
} | ||
|
||
public function getProviderOptions(array $configuration): array | ||
{ | ||
return [ | ||
'clientId' => $configuration['client_id'], | ||
'clientSecret' => $configuration['client_secret'], | ||
'subDomain' => $configuration['sub_domain'], | ||
]; | ||
} | ||
|
||
public function getPackagistName(): string | ||
{ | ||
return 'malteschlueter/oauth2-passage'; | ||
} | ||
|
||
public function getLibraryHomepage(): string | ||
{ | ||
return 'https://github.com/malteschlueter/oauth2-passage'; | ||
} | ||
|
||
public function getProviderDisplayName(): string | ||
{ | ||
return 'Passage'; | ||
} | ||
} |
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