I am trying to implement the LexikJwt package for my new API: https://github.com/lexik/LexikJWTAuthenticationBundle
I just added my custom command to create a proper JWT token including my default roles for local testing. The next step would be to actually protect my routes. What i can't find however is exactly on how to do that. This is my current controller implementation using annotation
routes
/**
* @Route(
* "/search",
* name="search",
* methods={"GET"},
* )
*/
class Search
{
/**
* @param AddressService $addressService
* @param Request $request
* @return JsonApiResponse
* @throws Exception
*/
public function __invoke(AddressService $addressService, Request $request)
{
$address = $addressService->createFromParams($request->query->all());
try {
$addressCollection = $addressService->search($address);
} catch (AddressNotFoundException $e) {
$addressCollection = [];
}
return new JsonApiResponse($addressCollection);
}
}
However the docs do not say anything about annotation routes and only on yml configs on security firewalls. The main thing i need is the token to be verified:
- Is the token valid (matching the public key)
- Is the token not expired
- Does the route match the given roles
For example, i want the code above, which is an address service to match only if the token matches above and the token holds the role or scope: address:search
.
Hope someone can help,
Pim