Skip to content

Commit

Permalink
v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Asisyas committed Dec 25, 2022
0 parents commit f49847a
Show file tree
Hide file tree
Showing 8 changed files with 491 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
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.
22 changes: 22 additions & 0 deletions composer.json
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"
}
}
52 changes: 52 additions & 0 deletions src/Configuration/Provider/ProviderConfiguration.php
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;
}
}
69 changes: 69 additions & 0 deletions src/OAuth2KeycloakProviderPlugin.php
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;
}
}
34 changes: 34 additions & 0 deletions src/OAuth2KeycloakProviderPluginConfiguration.php
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);
}
}
42 changes: 42 additions & 0 deletions src/Provider/KeycloakProviderConfigurationInterface.php
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;
}
Loading

0 comments on commit f49847a

Please sign in to comment.