Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add disable access token saving feature #32

Merged
merged 1 commit into from
Dec 19, 2021

Conversation

Orkin
Copy link
Contributor

@Orkin Orkin commented May 1, 2021

@mtarld @chalasr this is the port of disabled access token saving feature 😉

@@ -44,17 +44,36 @@ private function configureSecurityExtension(ContainerBuilder $container): void
private function configureDoctrineExtension(ContainerBuilder $container): void
{
/** @var string $modelDirectory */
$modelDirectory = realpath(__DIR__ . '/Resources/config/doctrine/model');
$modelCommonDirectory = realpath(__DIR__ . '/Resources/config/doctrine/common');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really comfortable with creating several XML mapping config files.
That's why in another PR I used the "php" approach. Have a look at https://github.com/thephpleague/oauth2-server-bundle/pull/25/files#diff-bbea8ca4dd205bd3df8e9ce6f139afa2852196075bea90a24f320ea3e449ba88R70.

Therefore it could be great if #25 could be merged before that PR (so you can base your mapping configuration on it)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes good point, I will check to do the same

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this point I will do it when #25 will be merged to avoid multiple conflicts

@@ -256,6 +271,7 @@ private function configureDoctrinePersistence(ContainerBuilder $container, array
$container
->findDefinition(AccessTokenManager::class)
->replaceArgument(0, $entityManager)
->replaceArgument('$disableAccessTokenSaving', $disableAccessTokenSaving)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try to use the argument index instead. In that way, renaming the argument won't require any changes elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will change

Comment on lines 300 to 294
if ($disableAccessTokenSaving) {
$container->setParameter('league.oauth2_server.persistence.doctrine.access_token.disabled', true);
} else {
$container->setParameter('league.oauth2_server.persistence.doctrine.access_token.enabled', true);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that parameter needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if you think it's needed, I'd rather did like that:

$container->setParameter('league.oauth2_server.persistence.doctrine.persist_access_token', !$disableAccessTokenSaving);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it's mandatory for configureDoctrineExtension. I need both because I didn't find how to invert boolean value from string parameter. But maybe with php approach I could remove it

{
$container
->findDefinition(InMemoryAccessTokenManager::class)
->replaceArgument('$disableAccessTokenSaving', $disableAccessTokenSaving)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

We try to use the argument index instead. In that way, renaming the argument won't require any changes elsewhere.

docs/index.md Outdated Show resolved Hide resolved
$loader->load('access_token/default.php');
}

$container->setParameter('league.oauth2_server.authorization_server.disable_access_token_saving', $config['disable_access_token_saving']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that parameter needed? Moreover it's kind of redundant with league.oauth2_server.persistence.doctrine.access_token.disabled parameter

src/Resources/config/access_token/null.php Show resolved Hide resolved
/**
* {@inheritdoc}
*/
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add typehints?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I can it was not on the AccessTokenRepository so I did the same 😉

src/League/Repository/NullAccessTokenRepository.php Outdated Show resolved Hide resolved
/** @var bool */
private $disableAccessTokenSaving;

public function __construct(EntityManagerInterface $entityManager, bool $disableAccessTokenSaving)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about a NullAccessTokenManager instead?

@chalasr
Copy link
Member

chalasr commented Jul 12, 2021

@Orkin are you still interested in finishing this PR? If you want someone to take over, just tell us.
Thanks

@Orkin
Copy link
Contributor Author

Orkin commented Jul 12, 2021

Hi, I would like to finish but currently don't have time so if someone want to continue I'll appreciate. Sorry for that.

@chalasr
Copy link
Member

chalasr commented Jul 12, 2021

No worry, thanks for the quick reply. Please keep this open.

@Orkin Orkin force-pushed the disable-access-token-saving branch 6 times, most recently from 172f5f9 to 0a9bded Compare December 12, 2021 00:27
@Orkin
Copy link
Contributor Author

Orkin commented Dec 12, 2021

@mtarld @chalasr I think it's fine and it's working. I don't know if I need to change something so feel free to review and give me some feedback if there is something that is not useful

/** @var bool */
private $persistAccessToken;

public function __construct(bool $persistAccessToken)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a NullAccessTokenManager instead?

@Orkin Orkin force-pushed the disable-access-token-saving branch from e998f57 to 156d13d Compare December 15, 2021 15:35
@chalasr chalasr force-pushed the disable-access-token-saving branch from 156d13d to 03e815d Compare December 19, 2021 18:15
@chalasr
Copy link
Member

chalasr commented Dec 19, 2021

Thank you @Orkin.

@chalasr chalasr merged commit f9f55a9 into thephpleague:master Dec 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants