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

Token for amLoggedInAs should be configurable #165

Closed
codedge opened this issue Jan 2, 2023 · 3 comments · Fixed by #182
Closed

Token for amLoggedInAs should be configurable #165

codedge opened this issue Jan 2, 2023 · 3 comments · Fixed by #182
Labels
enhancement New feature or request

Comments

@codedge
Copy link
Contributor

codedge commented Jan 2, 2023

I am testing some functionality regarding login and logout with an external OpenID provider. For that, I depend on some attributes that are set on the token.
In Symfony Tokens can have so called attributes. See TokenInterface (https://github.com/symfony/security-core/blob/6.2/Authentication/Token/TokenInterface.php#L76).

When using this modules amLoggedInAs method, I cannot modify the returned token,
This token generation should be switched to an approach, where I can control the token, f. ex. setting some attributes on the token.

And so my logic, that depends on attributes for the token fails.

@TavoNiievez
Copy link
Member

TavoNiievez commented Jan 10, 2024

Hi @codedge ,

I understand.

The problem here is that the signature of the amLoggedInAs assertion already includes 3 different parameters. All of them needed to create the token in the first place.

I would agree to create a method that receives as parameter an object of type "Symfony\Component\Security\Core\Authentication\Token\AbstractToken" or of type "Symfony\Component\Security\Core\Authentication\Token\TokenInterface".
and create an auxiliary method that allows to create the token as before, depending on the 3 parameters $user, $firewallName and $firewallContext.
In this way:

$token = $I->createAuthenticationToken($user, $firewallName);
$I->amLoggedInWithToken($token);

This way you can do whatever you want with the $token, including assigning attributes to it before passing it to the amLoggedInWithToken function.

What do you think of this approach?
Are you up for submitting a PR for this?

Thank you!

@TavoNiievez TavoNiievez added the enhancement New feature or request label Jan 10, 2024
@codedge
Copy link
Contributor Author

codedge commented Jan 17, 2024

@TavoNiievez Sounds like a good solution to me. I would take care of this and provide a PR.

codedge added a commit to codedge/module-symfony that referenced this issue Feb 4, 2024
codedge added a commit to codedge/module-symfony that referenced this issue Feb 4, 2024
@codedge
Copy link
Contributor Author

codedge commented Feb 4, 2024

@TavoNiievez See #182

codedge added a commit to codedge/module-symfony that referenced this issue Feb 4, 2024
TavoNiievez pushed a commit to codedge/module-symfony that referenced this issue Mar 12, 2024
TavoNiievez pushed a commit to codedge/module-symfony that referenced this issue Mar 12, 2024
TavoNiievez pushed a commit to codedge/module-symfony that referenced this issue Mar 12, 2024
TavoNiievez pushed a commit to TavoNiievez/module-symfony that referenced this issue May 2, 2024
TavoNiievez pushed a commit to TavoNiievez/module-symfony that referenced this issue May 2, 2024
TavoNiievez pushed a commit to TavoNiievez/module-symfony that referenced this issue May 2, 2024
TavoNiievez added a commit that referenced this issue May 2, 2024
* Login with token
* Update token logic
---------

Co-authored-by: TavoNiievez <ganieves@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants