php - JWT And Routes Symfony3 -


i have 2 firewalls in security.yml file:

security:     encoders:         fos\userbundle\model\userinterface: bcrypt     providers:         fos_userbundle:             id: fos_user.user_provider.username_email      firewalls:         login:             pattern:  ^/api/v1/auth$             stateless: true             anonymous: true             provider: fos_userbundle             form_login:                 check_path:               /api/v1/auth                 success_handler:          lexik_jwt_authentication.handler.authentication_success                 failure_handler:          lexik_jwt_authentication.handler.authentication_failure                 require_previous_session: false          api:             pattern:   ^/api/v1             stateless: true             provider: fos_userbundle             guard:                 authenticators:                     - lexik_jwt_authentication.jwt_token_authenticator 

and 2 routes in authcontroller:

/**  * @param paramfetcherinterface $paramfetcher  *  * @rest\post("/auth")  * @rest\requestparam(name="email", strict=true)  * @rest\requestparam(name="password", strict=true)  *  * @return array  */ public function posttokenauthaction (paramfetcherinterface $paramfetcher) {     if($user = $this->getuser()) {         return $user->getroles();     }      $email = $paramfetcher->get('email');     $password = $paramfetcher->get('password');      /** @var user|null $user */     $user = $this->getdoctrine()->getrepository('appbundle:user')->findonebyemail($email);      if(!$user || !$this->get('security.password_encoder')->ispasswordvalid($user, $password)) {         throw new httpexception(403, $this->get('translator')->trans('auth.error'));     }      $token = $this->get('lexik_jwt_authentication.encoder')->encode([         'email' => $user->getemail()     ]);      return ['access_token' => $token];  }  /**  * @param paramfetcherinterface $paramfetcher  *  * @rest\post("/auth/check")  *  * @return array  */ public function postcheckloginaction (paramfetcherinterface $paramfetcher) {     /** @var user $user */     $user = $this->getuser();              if (!$user) {         throw $this->createaccessdeniedexception();     }      return $user->getroles();  } 

i sent post request in /api/v1/auth post email=&password= parameters access_token. got 401 error "bad credentials".

ok. next i'm changed parameter patternin login firewall ^/api/v1/auth , form_login.check_path /api/v1/auth/check , it's works fine. can login email , password , access_token.

but route /api/v1/auth/check returns bad credentials. it's trying authorize me email , password in route, want try authorize authorization header.

why works wrong?

eventually, want send email , password /api/v1/auth getting access token, , next send access_token /api/v1/auth/check , user roles.

do try _username , _password (with low-dash) instead ones use?, default fields stores values.

i hope works you


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -