Skip to content

Commit

Permalink
Add new provider Passage
Browse files Browse the repository at this point in the history
  • Loading branch information
malteschlueter committed Oct 19, 2023
1 parent c26a792 commit c302397
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 5 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ via Composer:
| [Mollie](https://github.com/mollie/oauth2-mollie-php) | composer require mollie/oauth2-mollie-php |
| [Odnoklassniki](https://github.com/rakeev/oauth2-odnoklassniki) | composer require aego/oauth2-odnoklassniki |
| [Okta](https://github.com/foxworth42/oauth2-okta) | composer require foxworth42/oauth2-okta |
| [Passage](https://github.com/malteschlueter/oauth2-passage) | composer require malteschlueter/oauth2-passage |
| [Paypal](https://github.com/stevenmaguire/oauth2-paypal) | composer require stevenmaguire/oauth2-paypal |
| [PSN](https://github.com/larabros/oauth2-psn) | composer require larabros/oauth2-psn |
| [Salesforce](https://github.com/stevenmaguire/oauth2-salesforce) | composer require stevenmaguire/oauth2-salesforce |
Expand Down Expand Up @@ -1313,6 +1314,23 @@ knpu_oauth2_client:
# whether to check OAuth2 "state": defaults to true
# use_state: true

# will create service: "knpu.oauth2.client.passage"
# an instance of: KnpU\OAuth2ClientBundle\Client\Provider\PassageClient
# composer require malteschlueter/oauth2-passage
passage:
# must be "passage" - it activates that type!
type: passage
# add and set these environment variables in your .env files
client_id: '%env(OAUTH_PASSAGE_CLIENT_ID)%'
client_secret: '%env(OAUTH_PASSAGE_CLIENT_SECRET)%'
# a route name you'll create
redirect_route: connect_passage_check
redirect_params: {}
# Passage sub domain. For example, from passage url "https://example.withpassage.com" only "example" is required.
sub_domain: 'example'
# whether to check OAuth2 "state": defaults to true
# use_state: true

# will create service: "knpu.oauth2.client.paypal"
# an instance of: KnpU\OAuth2ClientBundle\Client\Provider\PaypalClient
# composer require stevenmaguire/oauth2-paypal
Expand Down
6 changes: 6 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ parameters:
-
message: '#Return typehint of method KnpU\\OAuth2ClientBundle\\Client\\Provider\\[a-zA-Z0-9\\_]+::fetchUser\(\) has invalid type [a-zA-Z0-9\\_]#'
path: ./src/Client/Provider
-
message: '#Class League\\OAuth2\\Client\\Provider\\[a-zA-Z0-9\\_]+ not found\.#'
path: ./src/Client/Provider
-
message: '#Call to method [a-zA-Z0-9\\_]+\(\) on an unknown class League\\OAuth2\\Client\\Provider\\[a-zA-Z0-9\\_]+\.#'
path: ./src/Client/Provider
# False positive: using `::class` is not an error for those providers `::getProviderClass()` method.
-
message: '#Class [a-zA-Z0-9\\_]+ not found#'
Expand Down
48 changes: 48 additions & 0 deletions src/Client/Provider/PassageClient.php
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());
}
}
2 changes: 2 additions & 0 deletions src/DependencyInjection/KnpUOAuth2ClientExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\MollieProviderConfigurator;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\OdnoklassnikiProviderConfigurator;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\OktaProviderConfigurator;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\PassageProviderConfiguration;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\PaypalProviderConfigurator;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\ProviderConfiguratorInterface;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\ProviderWithoutClientSecretConfiguratorInterface;
Expand Down Expand Up @@ -133,6 +134,7 @@ class KnpUOAuth2ClientExtension extends Extension
'mollie' => MollieProviderConfigurator::class,
'odnoklassniki' => OdnoklassnikiProviderConfigurator::class,
'okta' => OktaProviderConfigurator::class,
'passage' => PassageProviderConfiguration::class,
'paypal' => PaypalProviderConfigurator::class,
'psn' => PsnProviderConfigurator::class,
'salesforce' => SalesforceProviderConfigurator::class,
Expand Down
1 change: 0 additions & 1 deletion src/DependencyInjection/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function __construct(UrlGeneratorInterface $generator)
* Creates a provider of the given class.
*
* @param string $class
* @param string $redirectUri
*/
public function createProvider($class, array $options, string $redirectUri = null, array $redirectParams = [], array $collaborators = [])
{
Expand Down
66 changes: 66 additions & 0 deletions src/DependencyInjection/Providers/PassageProviderConfiguration.php
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';
}
}
7 changes: 3 additions & 4 deletions src/Security/Exception/FinishRegistrationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ class FinishRegistrationException extends AuthenticationException
private $userInformation;

/**
* @param mixed $userInfo Any info to be used to help registration
* @param string $message
* @param int $code
* @param \Exception $previous
* @param mixed $userInfo Any info to be used to help registration
* @param string $message
* @param int $code
*/
public function __construct($userInfo, $message = '', $code = 0, \Exception $previous = null)
{
Expand Down

0 comments on commit c302397

Please sign in to comment.