-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit f49847a
Showing
8 changed files
with
491 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Komar Stanislau | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,22 @@ | ||
{ | ||
"name": "micro/plugin-oauth2-client-keycloak", | ||
"description": "Micro Framework: Adapter for using Keycloak as an authorization server based on the OAuth2 protocol.", | ||
"type": "library", | ||
"license": "MIT", | ||
"version": "1.0", | ||
"autoload": { | ||
"psr-4": { | ||
"Micro\\Plugin\\OAuth2\\Client\\Keycloak\\": "src/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Stanislau Komar", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"micro/plugin-oauth2-client": "^1", | ||
"micro/plugin-security": "^1" | ||
} | ||
} |
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,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the Micro framework package. | ||
* | ||
* (c) Stanislau Komar <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Micro\Plugin\OAuth2\Client\Keycloak\Configuration\Provider; | ||
|
||
use Micro\Plugin\OAuth2\Client\Configuration\Provider\OAuth2ClientProviderConfiguration; | ||
use Micro\Plugin\OAuth2\Client\Keycloak\Provider\KeycloakProviderConfigurationInterface; | ||
|
||
/** | ||
* @author Stanislau Komar <[email protected]> | ||
*/ | ||
class ProviderConfiguration extends OAuth2ClientProviderConfiguration implements KeycloakProviderConfigurationInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getRealm(): string | ||
{ | ||
return 'micro'; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getScopesDefault(): array | ||
{ | ||
return ['email', 'profile']; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getScopesSeparator(): string | ||
{ | ||
return ' '; | ||
} | ||
|
||
public function getSecurityProvider(): string|null | ||
{ | ||
return null; | ||
} | ||
} |
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,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the Micro framework package. | ||
* | ||
* (c) Stanislau Komar <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Micro\Plugin\OAuth2\Client\Keycloak; | ||
|
||
use League\OAuth2\Client\Provider\AbstractProvider; | ||
use Micro\Component\DependencyInjection\Container; | ||
use Micro\Framework\Kernel\Plugin\ConfigurableInterface; | ||
use Micro\Framework\Kernel\Plugin\DependencyProviderInterface; | ||
use Micro\Framework\Kernel\Plugin\PluginConfigurationTrait; | ||
use Micro\Plugin\OAuth2\Client\Configuration\OAuth2ClientPluginConfigurationInterface; | ||
use Micro\Plugin\OAuth2\Client\Keycloak\Provider\OAuth2Provider; | ||
use Micro\Plugin\OAuth2\Client\Provider\OAuth2ClientProviderPluginInterface; | ||
use Micro\Plugin\Security\Facade\SecurityFacadeInterface; | ||
|
||
/** | ||
* @author Stanislau Komar <[email protected]> | ||
* | ||
* @method OAuth2ClientPluginConfigurationInterface configuration() | ||
*/ | ||
class OAuth2KeycloakProviderPlugin implements OAuth2ClientProviderPluginInterface, DependencyProviderInterface, ConfigurableInterface | ||
{ | ||
|
||
use PluginConfigurationTrait; | ||
|
||
const PROVIDER_TYPE = 'keycloak'; | ||
|
||
/** | ||
* @var Container | ||
*/ | ||
private readonly Container $container; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function createProvider(string $providerName): AbstractProvider | ||
{ | ||
return new OAuth2Provider( | ||
$this->configuration()->getProviderConfiguration($providerName), | ||
$this->container->get(SecurityFacadeInterface::class), | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getType(): string | ||
{ | ||
return self::PROVIDER_TYPE; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function provideDependencies(Container $container): void | ||
{ | ||
$this->container = $container; | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the Micro framework package. | ||
* | ||
* (c) Stanislau Komar <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Micro\Plugin\OAuth2\Client\Keycloak; | ||
|
||
use Micro\Plugin\OAuth2\Client\Configuration\Provider\OAuth2ClientProviderConfigurationInterface; | ||
use Micro\Plugin\OAuth2\Client\Keycloak\Configuration\Provider\ProviderConfiguration; | ||
use Micro\Plugin\OAuth2\Client\OAuth2ClientPluginConfiguration; | ||
|
||
/** | ||
* @author Stanislau Komar <[email protected]> | ||
*/ | ||
class OAuth2KeycloakProviderPluginConfiguration extends OAuth2ClientPluginConfiguration | ||
{ | ||
/** | ||
* @param string $providerName | ||
* | ||
* @return OAuth2ClientProviderConfigurationInterface | ||
*/ | ||
public function getProviderConfiguration(string $providerName): OAuth2ClientProviderConfigurationInterface | ||
{ | ||
return new ProviderConfiguration($this->configuration, $providerName); | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the Micro framework package. | ||
* | ||
* (c) Stanislau Komar <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Micro\Plugin\OAuth2\Client\Keycloak\Provider; | ||
|
||
use Micro\Plugin\OAuth2\Client\Configuration\Provider\OAuth2ClientProviderConfigurationInterface; | ||
|
||
/** | ||
* @author Stanislau Komar <[email protected]> | ||
*/ | ||
interface KeycloakProviderConfigurationInterface extends OAuth2ClientProviderConfigurationInterface | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getRealm(): string; | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getScopesDefault(): array; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getScopesSeparator(): string; | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getSecurityProvider(): string|null; | ||
} |
Oops, something went wrong.