Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
HypeMC committed Apr 18, 2020
1 parent 2e54c1e commit db6b131
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 41 deletions.
42 changes: 42 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,48 @@ private function createAuthorizationServerNode(): NodeDefinition

$node->append($this->createAuthorizationServerGrantTypesNode());

$node
->validate()
->always(static function ($v): array {
foreach ($v['grant_types'] as $grantType => &$grantTypeConfig) {
$grantTypeConfig['access_token_ttl'] = $grantTypeConfig['access_token_ttl'] ?? $v['access_token_ttl'];

if (\array_key_exists('refresh_token_ttl', $grantTypeConfig)) {
$grantTypeConfig['refresh_token_ttl'] = $grantTypeConfig['refresh_token_ttl'] ?? $v['refresh_token_ttl'];
}

// @TODO Remove in v4 start
$oldGrantType = 'authorization_code' === $grantType ? 'auth_code' : $grantType;

$grantTypeConfig['enable'] = $v[sprintf('enable_%s_grant', $oldGrantType)] ?? $grantTypeConfig['enable'];

if ('authorization_code' === $grantType) {
$grantTypeConfig['auth_code_ttl'] = $v['auth_code_ttl'] ?? $grantTypeConfig['auth_code_ttl'];
$grantTypeConfig['require_code_challenge_for_public_clients'] = $v['require_code_challenge_for_public_clients']
?? $grantTypeConfig['require_code_challenge_for_public_clients'];
}
// @TODO Remove in v4 end
}

unset(
$v['access_token_ttl'],
$v['refresh_token_ttl'],
// @TODO Remove in v4 start
$v['enable_auth_code_grant'],
$v['enable_client_credentials_grant'],
$v['enable_implicit_grant'],
$v['enable_password_grant'],
$v['enable_refresh_token_grant'],
$v['auth_code_ttl'],
$v['require_code_challenge_for_public_clients']
// @TODO Remove in v4 end
);

return $v;
})
->end()
;

return $node;
}

Expand Down
41 changes: 0 additions & 41 deletions DependencyInjection/TrikoderOAuth2Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('services.xml');

$config = $this->processConfiguration(new Configuration(), $configs);
$config = $this->normalizeConfiguration($config);

$this->configurePersistence($loader, $container, $config['persistence']);
$this->configureAuthorizationServer($container, $config['authorization_server']);
Expand Down Expand Up @@ -111,46 +110,6 @@ public function process(ContainerBuilder $container)
$this->assertRequiredBundlesAreEnabled($container);
}

private function normalizeConfiguration(array $config): array
{
foreach ($config['authorization_server']['grant_types'] as $grantType => &$grantTypeConfig) {
$grantTypeConfig['access_token_ttl'] = $grantTypeConfig['access_token_ttl'] ?? $config['authorization_server']['access_token_ttl'];

if (\array_key_exists('refresh_token_ttl', $grantTypeConfig)) {
$grantTypeConfig['refresh_token_ttl'] = $grantTypeConfig['refresh_token_ttl'] ?? $config['authorization_server']['refresh_token_ttl'];
}

// @TODO Remove in v4 start

$oldGrantType = 'authorization_code' === $grantType ? 'auth_code' : $grantType;

$grantTypeConfig['enable'] = $config['authorization_server'][sprintf('enable_%s_grant', $oldGrantType)] ?? $grantTypeConfig['enable'];

if ('authorization_code' === $grantType) {
$grantTypeConfig['auth_code_ttl'] = $config['authorization_server']['auth_code_ttl'] ?? $grantTypeConfig['auth_code_ttl'];
$grantTypeConfig['require_code_challenge_for_public_clients'] = $config['authorization_server']['require_code_challenge_for_public_clients']
?? $grantTypeConfig['require_code_challenge_for_public_clients'];
}

// @TODO Remove in v4 end
}

unset($config['authorization_server']['access_token_ttl'], $config['authorization_server']['refresh_token_ttl']);

// @TODO Remove in v4
unset(
$config['authorization_server']['enable_auth_code_grant'],
$config['authorization_server']['enable_client_credentials_grant'],
$config['authorization_server']['enable_implicit_grant'],
$config['authorization_server']['enable_password_grant'],
$config['authorization_server']['enable_refresh_token_grant'],
$config['authorization_server']['auth_code_ttl'],
$config['authorization_server']['require_code_challenge_for_public_clients']
);

return $config;
}

private function assertRequiredBundlesAreEnabled(ContainerBuilder $container): void
{
$requiredBundles = [
Expand Down

0 comments on commit db6b131

Please sign in to comment.