liip / liip/LiipFunctionalTestBundle
Allow creation of token without user
- Dominant language
- PHP
- Stars
- 648
- Forks
- 179
- PR merge metrics
- No merged PRs in 30d
Description
Currently, the `WebTestCase` class demands that a user is present when creating a token. However, the presence of a user is not always required; specifically, in my case, when creating an OAuth2 token for an OAuth2 client (i.e. via the client_credentials grant type). At the moment, I have to hack around this restriction by passing in a dummy user object and then not adding it to the token, i.e.:
```
$this->loginAs(new User(), 'main');
$client = $this->makeClient();
protected function createUserToken(UserInterface $user, $firewallName)
{
$token = new OAuthToken();
// We assume client_credentials if the User isn't assigned roles
// so in this scenario we don't add the user to the token
if (!empty($user->getRoles())) {
$token->setUser($user);
}
return $token;
}
```
Can we add support for token creation in the absence of a user?
I'm not sure the best way of achieving this, since the tokens are created when iterating over the `$firewallLogins` array in `WebTestCase::makeClient()`. An easy, but inelegant, solution would be to allow creation of an empty element in that array. A better solution would be to factor out the internals of that loop to a separate method, so we can create a token in isolation of `$firewallLogins`. Either way, we'll need to make the arguments for `WebTestCase::createUserToken()` optional, or probably more sensibly (given that method name), introduce a separate token creation method which doesn't require a user object.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading WebTestCase::makeClient(), especially how it iterates over the $firewallLogins array and calls createUserToken(). Compare the proposed optional arguments or separate token-creation method, then verify that client_credentials tokens can be created without a user while existing user-token behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, symfony
- Domain
- authentication, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100