繁体   English   中英

Express/Node js api SameSite=None and Secure for cookies,尝试访问 api 时显示警告

[英]Express/Node js api SameSite=None and Secure for cookies ,warning being shown when trying to access the api

我使用 express/node 创建了以下 api,但是当我尝试从浏览器访问它时,“如果 cookie 应该在跨站点请求中发送,请指定 SameSite=None 和 Secure。这允许第三方使用。” 此警告显示在控制台中,没有检索到数据,api 如下

let express = require("express");
let app = express();
let bodyparser = require("body-parser")
let jwt = require("jsonwebtoken");
const student = require('./student')


app.use(bodyparser.json)

//used to authenticate the user and create the token
app.get("/auth",(req,res)=>{
    console.log("sdsdsds")
    var token = jwt.sign({email: user.email}, 'hubDemo', {expiresIn: '1h'});
    res.send({token})
})

//fetches the student data and returns 
app.get("/student",(req,res)=>{
    console.log("tst");
    return res.status(200).json({
        ok: true,
        data: student
    });
});


app.listen(3000,()=>{console.log("listening")})

我应该改变什么才能让它工作?

因此,在您给定的情况下,没有 cookies 与您的快递 api 一起使用。 但是,对于您的令牌,我强烈建议您查看http-only cookies而不是 localStorage。 这可以防止任何客户端调整令牌,而 localStorage 更容易受到攻击。 但是根据您的原始网址,在创建 cookie 时仅指示 SameSite 属性应该可以解决警告。

暂无
暂无

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

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