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

JWT Token not found returned when user doesn't have roles #259

Closed
tarlepp opened this issue Oct 23, 2016 · 4 comments
Closed

JWT Token not found returned when user doesn't have roles #259

tarlepp opened this issue Oct 23, 2016 · 4 comments

Comments

@tarlepp
Copy link

tarlepp commented Oct 23, 2016

With users that have none user roles attached I get 'JWT Token not found' when I'm making any API requests. It seems that

/jwt-authentication-bundle/Security/Guard/JWTTokenAuthenticator.php

$authToken = new JWTUserToken($user->getRoles(), $user, $preAuthToken->getCredentials(), $providerKey);

/jwt-authentication-bundle/Security/Authentication/Token/JWTUserToken.php

/**
 * {@inheritdoc}
 */
public function __construct(array $roles = [], UserInterface $user = null, $rawToken = null, $providerKey = null)
{
    parent::__construct($roles);

    if ($user) {
        $this->setUser($user);
    }

    $this->setRawToken($rawToken);
    $this->setAuthenticated(count($roles) > 0);

    $this->providerKey = $providerKey;
}

Is causing the problem. Why are roles required on this case ?

tarlepp added a commit to tarlepp/symfony-backend that referenced this issue Oct 23, 2016
@chalasr
Copy link
Collaborator

chalasr commented Oct 23, 2016

Hi @tarlepp,

Thank you for opening this issue.
I think there's no need for this check, an user can be authenticated without roles. After all, access controls are responsible for granting access depending on roles.
Let me make some tests and, if confirmed, come back with a fix.

If anyone has an explanation for the presence of this check...

@chalasr
Copy link
Collaborator

chalasr commented Oct 25, 2016

@tarlepp Re-reading your issue, I'm afraid that your problem is not that your user doesn't have roles. In fact, the only way to run into a "JWT Not Found" response is that the token can't be found in the request. By default, we check for a Authorization header with a Bearer prefix, i.e. Authorization: Bearer [YOURJWT].

@tarlepp
Copy link
Author

tarlepp commented Oct 26, 2016

@chalasr actually my tests spotted this one after I update this bundle. And I can easily to demonstrate that behaviour with my repo. If user doesn't have roles this error occurs, if user have at least one role all is ok.

See my "quick" fix for this
tarlepp/symfony-backend@2c2bad7...4c004fd

@chalasr
Copy link
Collaborator

chalasr commented Oct 27, 2016

@tarlepp Sorry for the delay, it is now tagged as v2.0.2. I'll try to understand why the bug leaded to this specific response.

Again, thank you for reporting this bug.

cameronjfergus added a commit to cameronjfergus/symfony-backend that referenced this issue Mar 24, 2022
gzim324 pushed a commit to gzim324/LexikJWTAuthenticationBundle that referenced this issue Jan 10, 2025
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

No branches or pull requests

2 participants