Cors::class, 'cors' => [ 'Origin' => ['https://botondfitness.hu'], 'Access-Control-Request-Method' => ['POST', 'GET', 'OPTIONS'], 'Access-Control-Allow-Headers' => ['*'], 'Access-Control-Expose-Headers' => ['*'] ], ]; // $behaviors['authenticator'] = $auth; $behaviors['authenticator'] = [ 'class' => JwtHttpBearerAuth::class, 'auth' => [$this, 'auth'], 'optional' => $this->getOptionalActions(), ]; $behaviors['authenticator']['except'] = ['options']; return $behaviors; } /** * This method will check the token * @param Token $token * @return Customer|null */ public function auth($token) { if ( !isset($token ) ) { return null; } try { $uid = (string) $token->getClaim('uid'); $customer = Customer::findOne(['id_customer' => $uid]); if (isset($customer)) { \Yii::$app->user->setIdentity($customer); return $customer; } } catch (Exception $e) { Yii::error('Failed to load customer: ' . $e->getMessage()); } return null; } /** * @see AuthMethod::$optional * @return array */ protected function getOptionalActions(){ return []; } }