Логин работает на Chrome и Firefox, но не на Edge - PullRequest
0 голосов
/ 05 июля 2019

У меня есть система аутентификации firebase на моем локальном сервере Node.js.Я настроил систему входа в систему так, чтобы пользователь входил в систему с помощью внешнего интерфейса.отправляет запрос на выборку и получает взамен cookie сеанса.это прекрасно работает на chrome и firefox, но на Edge я получаю сообщение об ошибке как в консоли браузера, так и в консоли сервера.

Я проверил, действительно ли токен отправлен на сервер, и это так.

это обработчик входа в систему с помощью firebase и cookie-парсера


    /** Session login endpoint. */
    app.post("/sessionLogin", function(req, res) {
      // Get ID token and CSRF token.
      var idToken = req.body.idToken.toString();
      var csrfToken = req.body.csrfToken.toString();

      // Guard against CSRF attacks.
      if (!req.cookies || csrfToken !== req.cookies.csrfToken) {
        res.status(401).send("UNAUTHORIZED REQUEST!");
        return;
      }
      // Set session expiration to 5 days.
      var expiresIn = 60 * 60 * 24 * 5 * 1000;
      // Create the session cookie. This will also verify the ID token in the process.
      // The session cookie will have the same claims as the ID token.
      // We could also choose to enforce that the ID token auth_time is recent.
      admin
        .auth()
        .verifyIdToken(idToken)
        .then(function(decodedClaims) {
          // In this case, we are enforcing that the user signed in in the last 5 minutes.
          if (new Date().getTime() / 1000 - decodedClaims.auth_time < 5 * 60) {
            return admin
              .auth()
              .createSessionCookie(idToken, { expiresIn: expiresIn });
          }
          throw new Error("UNAUTHORIZED REQUEST!");
        })
        .then(function(sessionCookie) {
          // Note httpOnly cookie will not be accessible from javascript.
          // secure flag should be set to true in production.
          console.log(sessionCookie);

          var options = {
            maxAge: expiresIn,
            httpOnly: true,
            secure: false /** to test in localhost */
          };
          res.cookie("session", sessionCookie, options);
          res.end(JSON.stringify({ status: "success" }));
        })
        .catch(function(error) {
          res.status(401).send("UNAUTHORIZED REQUEST!");
        });
    });

это обработчик запроса на получение профиля:

//Get profile endpoint. */
app.get("/profile", function(req, res) {
  // Get session cookie.
  var sessionCookie = req.cookies.session || "none";
  // Get the session cookie and verify it. In this case, we are verifying if the
  // Firebase session was revoked, user deleted/disabled, etc.
  admin
    .auth()
    .verifySessionCookie(sessionCookie, true /** check if revoked. */)
    .then(function(decodedClaims) {
      // Serve content for signed in user.
      return serveContentForUser("/profile", req, res, decodedClaims);
    })
    .catch(function(error) {
      console.log("error: ", error);

      // Force user to login.
      res.redirect("/login");
    });
});

ошибка интерфейса:

HTTP401: DENIED - The requested resource requires user authentication.
(Fetch)POST - http://192.168.1.9/sessionLogin

внутренняя ошибка

{ Error: Decoding Firebase session cookie failed. Make sure you passed the entire string JWT which represents a session cookie. See https://firebase.google.com/docs/auth/admin/manage-cookies for details on how to retrieve a session cookie.
    at FirebaseAuthError.FirebaseError [as constructor] (C:\Users\mendi\Desktop\firebase-auth\node_modules\firebase-admin\lib\utils\error.js:42:28)
    at FirebaseAuthError.PrefixedFirebaseError [as constructor] (C:\Users\mendi\Desktop\firebase-auth\node_modules\firebase-admin\lib\utils\error.js:88:28)
    at new FirebaseAuthError (C:\Users\mendi\Desktop\firebase-auth\node_modules\firebase-admin\lib\utils\error.js:146:16)
    at FirebaseTokenVerifier.verifyJWT (C:\Users\mendi\Desktop\firebase-auth\node_modules\firebase-admin\lib\auth\token-verifier.js:158:35)
    at Auth.BaseAuth.verifySessionCookie (C:\Users\mendi\Desktop\firebase-auth\node_modules\firebase-admin\lib\auth\auth.js:318:43)
    at C:\Users\mendi\Desktop\firebase-auth\app.js:179:6
    at Layer.handle [as handle_request] (C:\Users\mendi\Desktop\firebase-auth\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\mendi\Desktop\firebase-auth\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (C:\Users\mendi\Desktop\firebase-auth\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (C:\Users\mendi\Desktop\firebase-auth\node_modules\express\lib\router\layer.js:95:5)
  errorInfo:
   { code: 'auth/argument-error',
     message:
      'Decoding Firebase session cookie failed. Make sure you passed the entire string JWT which represents a session cookie. See https://firebase.google.com/docs/auth/admin/manage-cookies for details on how to retrieve a session cookie.' },
  codePrefix: 'auth' }

Возможно, это моя ошибка или проблема с браузером.но я не думаю, что это связано с моим кодом.

1 Ответ

1 голос
/ 08 июля 2019

Я обнаружил, что Edge 41.16299 имеет похожую проблему, которая исправлена ​​в последних обновлениях. Поэтому я предлагаю вам установить последнее обновление для ваших окон и проверить, помогает ли оно решить проблему или нет. Ссылка: developer.microsoft.com / ru-ru / microsoft-edge / платформа / проблемы

...