Esempio n. 1
0
 /**
  * Authenticate a user via a token.
  *
  * @param mixed $token
  *
  * @return mixed
  */
 public function authenticate($token = false)
 {
     $id = $this->getPayload($token)->get('sub');
     if (!$this->auth->byId($id)) {
         return false;
     }
     return $this->auth->user();
 }
Esempio n. 2
0
 /**
  * Authenticate a user via a token.
  *
  * @param mixed $token
  * @param Array $custom custom claims that must be equals (all custom fields indicated must be equals in token, this doesn't entail that the token must have only these claims)
  * @return mixed
  */
 public function authenticate($token = false, $custom = [])
 {
     $payload = $this->getPayload($token);
     $id = $payload->get('sub');
     foreach ($custom as $customK => $customV) {
         if (!isset($payload[$customK]) || $customV != $payload[$customK]) {
             return new InvalidClaimException('custom fields are wrong');
         }
     }
     if (!$this->auth->byId($id)) {
         return false;
     }
     $user = $this->auth->user();
     $this->setUserModelAsObject($user);
     return $user;
 }