【发布时间】:2018-02-17 19:54:01
【问题描述】:
我已将 OAuth2 添加到我的 spring-boot 应用程序中,到目前为止我只使用 google 作为登录名。登录部分工作正常,但当我发送 POST 请求时,我收到以下错误
{
"timestamp": 1504901957320,
"status": 403,
"error": "Forbidden",
"message": "Could not verify the provided CSRF token because your session was not found.",
"path": "/compute"
}
现在我知道我可以在春季禁用 CSRF,但这不是最佳做法。 spring-boot 是自动设置 CSRF 令牌还是我必须添加一些东西才能使其工作。现在我不知道问题是否出在我没有添加令牌的角度代码发出请求时
let headers = new Headers();
headers.append("Content-Type", "application/json");
this.http.post("/compute", JSON.stringify(source), { headers }).subscribe((response: Response) => {
if (response.ok) {
this.mainpage.terminalComponent.logToTerminal(new Date(), response.text());
}
});
或者我没有创建令牌并从后端设置它?
【问题讨论】:
-
headers没有附加CSRF令牌 -
好吧!我刚开始使用 Angular,所以一切对我来说都是新的。如何获取令牌并将其附加到
headers?顺便说一句,感谢您的快速回答! @Aravind
标签: spring angular rest spring-boot spring-security