首页 > 解决方案 > 当我在 Iframe 中加载应用程序并点击网络服务器 URL(Hapi JS)时,请求对象中缺少 Cookie

问题描述

我有一个使用 Hapi JS 实现的 Web 服务器应用程序,每当我使用浏览器的选项卡打开应用程序时,我都能看到 cookie 被注入到请求标头中。但是如果我通过 iframe 在第三个应用程序中加载我的应用程序。标头中缺少 cookie。你能在这里请一些身体帮助吗?

哈皮JS代码

server.auth.strategy('session', 'cookie', {
  password: 'longpassword-should-be-32-characters-for-pulse',
  cookie: 'my-app-sid',
  redirectTo: '/',
  ttl: 86400000,
  isSecure: false,
  validateFunc: isAuth
});

和我的 API 调用,其中 req 标头中缺少 cookie

  getBookDetails = () => {
    return {
      auth: {
        strategy: 'session'
      },
      handler: {
        proxy: {
          mapUri: (request, callback) => {
            let url = 'https://mydemoapp.com'
            let tokenHeaders =   {   token: request.auth.credentials.token,
                                                  assetid: request.headers['assetid'],
                                                  asseturl:request.headers['asseturl'],
                                                  deviceid: deviceid,
                                                  appversion: request.headers['appversion'],     
                                                  'user-agent': request.headers['user-agent'],
                                                  'accept-language': request.headers['accept-language']
                                                   };
         
            url = url + '/book/' + request.params.bookId;
            callback(null, url, tokenHeaders);
          },
          onResponse: (err, res, request, reply) => {
            wreck.read(res, { json: true, gzip: true }, (err, payload) => {
              reply(payload);
            });
          }
        }
      }
    }
  }

我怀疑因为我的应用程序是在第三方应用程序的 iframe 中加载的。并且在请求上面提到的网络服务器 URL getBookDetails() 时,它无法从父应用程序(第三方应用程序)读取 iframe 的 cookie。

有人可以帮忙吗

标签: node.jsreactjshapijs

解决方案


推荐阅读