Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ServiceNotFoundException in CheckExceptionOnInvalidReferenceBehaviorPass.php
- The service "token_authenticator" has a dependency on a non-existent service "lexik_jwt_authentication.jwt_encoder".
- lexik_jwt_authentication:
- private_key_path: '%kernel.root_dir%/../var/jwt/private.pem'
- public_key_path: '%kernel.root_dir%/../var/jwt/public.pem'
- pass_phrase: '%jwt_key_pass_phrase%'
- token_ttl: 3600
- firewalls:
- main:
- pattern: ^/
- logout: true
- anonymous: true
- stateless: true
- guard:
- authenticators:
- - 'token_authenticator'
- services:
- token_authenticator:
- class: AcmeStoreBundleSecurityTokenAuthenticator
- arguments: ['@lexik_jwt_authentication.jwt_encoder', '@doctrine_mongodb']
- public function loginAction(Request $request) {
- $data = json_decode(file_get_contents('php://input'), true);
- $userName = $data['username'];
- $password = $data['password'];
- $user = $this->get('doctrine_mongodb')
- ->getRepository('AcmeStoreBundle:User')
- ->findOneBy(['username' => $userName]);
- if (!$user) {
- throw $this->createNotFoundException();
- }
- $isValid = $this->get('security.password_encoder')
- ->isPasswordValid($user, $password);
- if (!$isValid) {
- throw new BadCredentialsException();
- }
- $response = new Response(Response::HTTP_OK);
- $token = $this->getToken($user);
- $response = new Response($this->serialize(['token' => $token]), Response::HTTP_OK);
- return $this->setBaseHeaders($response);
- }
- public function serialize($data) {
- $context = new SerializationContext();
- $context->setSerializeNull(true);
- return $this->get('jms_serializer')
- ->serialize($data, 'json', $context);
- }
- public function getToken(User $user) {
- return $this->container->get('lexik_jwt_authentication.encoder')
- ->encode([
- 'username' => $user->getUsername(),
- 'exp' => time() + 3600 ,
- ]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement