getHeaders()->get('Authorization'); if ($authHeader && preg_match('/^Bearer\s+(.*?)$/', $authHeader, $matches)) { $jwt = $matches[1]; try { $decoded = JWT::decode($jwt, new Key(Yii::$app->params['jwtSecret'], 'HS256')); return $user->loginByAccessToken($decoded->sub); } catch (\Exception $e) { throw new UnauthorizedHttpException('Invalid token'); } } return null; } }