getValidationRules(); // Validate credentials if (! $this->validateData($this->request->getJSON(true), $rules, [], config('Auth')->DBGroup)) { return $this->fail( ['errors' => $this->validator->getErrors()], $this->codes['unauthorized'] ); } // Get the credentials for login $credentials = $this->request->getJsonVar(setting('Auth.validFields')); $credentials = array_filter($credentials); $credentials['password'] = $this->request->getJsonVar('password'); /** @var Session $authenticator */ $authenticator = auth('session')->getAuthenticator(); // Check the credentials $result = $authenticator->check($credentials); // Credentials mismatch. if (! $result->isOK()) { // @TODO Record a failed login attempt return $this->failUnauthorized($result->reason()); } // Credentials match. // @TODO Record a successful login attempt $user = $result->extraInfo(); /** @var JWTManager $manager */ $manager = service('jwtmanager'); // Generate JWT and return to client $jwt = $manager->generateToken($user); return $this->respond([ 'access_token' => $jwt, ]); } /** * Returns the rules that should be used for validation. * * @return array|string>> * @phpstan-return array>> */ protected function getValidationRules(): array { $rules = new ValidationRules(); return $rules->getLoginRules(); } }