Advertisement
Guest User

Untitled

a guest
Sep 7th, 2017
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. ServiceNotFoundException in CheckExceptionOnInvalidReferenceBehaviorPass.php
  2. The service "token_authenticator" has a dependency on a non-existent service "lexik_jwt_authentication.jwt_encoder".
  3.  
  4. lexik_jwt_authentication:
  5. private_key_path: '%kernel.root_dir%/../var/jwt/private.pem'
  6. public_key_path: '%kernel.root_dir%/../var/jwt/public.pem'
  7. pass_phrase: '%jwt_key_pass_phrase%'
  8. token_ttl: 3600
  9.  
  10. firewalls:
  11. main:
  12. pattern: ^/
  13. logout: true
  14. anonymous: true
  15. stateless: true
  16.  
  17. guard:
  18. authenticators:
  19. - 'token_authenticator'
  20.  
  21. services:
  22.  
  23. token_authenticator:
  24. class: AcmeStoreBundleSecurityTokenAuthenticator
  25. arguments: ['@lexik_jwt_authentication.jwt_encoder', '@doctrine_mongodb']
  26.  
  27. public function loginAction(Request $request) {
  28.  
  29. $data = json_decode(file_get_contents('php://input'), true);
  30. $userName = $data['username'];
  31. $password = $data['password'];
  32.  
  33. $user = $this->get('doctrine_mongodb')
  34. ->getRepository('AcmeStoreBundle:User')
  35. ->findOneBy(['username' => $userName]);
  36.  
  37. if (!$user) {
  38. throw $this->createNotFoundException();
  39. }
  40.  
  41. $isValid = $this->get('security.password_encoder')
  42. ->isPasswordValid($user, $password);
  43.  
  44. if (!$isValid) {
  45. throw new BadCredentialsException();
  46. }
  47.  
  48. $response = new Response(Response::HTTP_OK);
  49. $token = $this->getToken($user);
  50.  
  51. $response = new Response($this->serialize(['token' => $token]), Response::HTTP_OK);
  52. return $this->setBaseHeaders($response);
  53. }
  54.  
  55.  
  56. public function serialize($data) {
  57. $context = new SerializationContext();
  58. $context->setSerializeNull(true);
  59.  
  60. return $this->get('jms_serializer')
  61. ->serialize($data, 'json', $context);
  62. }
  63.  
  64. public function getToken(User $user) {
  65.  
  66. return $this->container->get('lexik_jwt_authentication.encoder')
  67. ->encode([
  68. 'username' => $user->getUsername(),
  69. 'exp' => time() + 3600 ,
  70. ]);
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement