简体   繁体   English

如何为下一个请求检索快速会话cookie(节点脚本)

[英]How to retrieve express session cookie for next request (node script)

I am using angular 1.2.23, and a nodejs server. 我正在使用angular 1.2.23和一个nodejs服务器。

I have an authentification based on express-session 1.9.3. 我有一个基于快速会话1.9.3的身份验证。

Here are my options given to express 这是我表达的选择

return {
    name: 'session',
    secret: signatureKey,
    cookie: {
        httpOnly: true,
        secure: getEnvName() === 'production',
        maxAge: 30 * 60 * 1000
    },
    resave: true,
    saveUninitialized: true
};

I need to do a nodejs script, that will auth and fetch data for each users. 我需要执行一个nodejs脚本,它将对每个用户进行身份验证和获取数据。

Operation should be like this 操作应该是这样的

  • for each users 对于每个用户

    • POST request (Login, it will also create a session) POST请求(登录后,还将创建一个会话)
    • GET request (data) GET请求(数据)
    • GET request (logout) GET请求(注销)

The first request create the session, and returned a user item. 第一个请求创建会话,并返回一个用户项。 The second request has a middleware, which required to have a valid http cookie. 第二个请求具有中间件,该中间件需要具有有效的http cookie。

I am trying to find a way to get and send back the cookie for the second request, I can't find any documentation. 我正在尝试找到一种方法来获取和发送第二个请求的cookie,但找不到任何文档。

I accept any suggestion. 我接受任何建议。

whould you use the express-session? 谁可以使用快速会话?

I had the same problem and have no idea by the document 我遇到了同样的问题,文档却一无所知

only the first request will response cookie 只有第一个请求将响应cookie

when requested the cookie store in mongodb expires modified 当请求mongodb中的cookie存储过期时,修改

but the cookie in Browser(responsed) never change untill it's expired then will get a new cookie 但是浏览器(已响应)中的cookie永远不会更改,直到它过期,然后将获得一个新的cookie

so different to asp.net,jee ... 与asp.net截然不同,jee ...

i edit the express-session code too solve the question 我也编辑快速会话代码来解决问题

"version": "1.11.3" “版本”:“ 1.11.3”

express-session/index.js 快递会话/ index.js

find string "shouldSetCookie" 找到字符串“ shouldSetCookie”

old code 旧代码

 if (!shouldSetCookie(req)) {
    return;
  }
 setcookie(res, name, req.sessionID, secrets[0], cookie.data);

just delete "restun",the every request will get cookie with new expires 只需删除“ restun”,每个请求将获得新的过期cookie

new code if (!shouldSetCookie(req)) { } setcookie(res, name, req.sessionID, secrets[0], cookie.data); 新代码if(!shouldSetCookie(req)){} setcookie(res,name,req.sessionID,secrets [0],cookie.data);

in this way you can edit the cookie and setcookie 通过这种方式,您可以编辑cookie和setcookie

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM