Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何使用基于cookie的会话和CSRF头配置JSData?_Angular_Csrf_Jsdata - Fatal编程技术网

Angular 如何使用基于cookie的会话和CSRF头配置JSData?

Angular 如何使用基于cookie的会话和CSRF头配置JSData?,angular,csrf,jsdata,Angular,Csrf,Jsdata,我需要设置我的JSData配置,以便为基于cookie的会话身份验证以及CSRF头传递信息。当实例化HttpAdapter时,使用以下命令设置withCredentials()和CSRF头(下面的示例设置了X-CSRFToken头,但这是特定于服务器端框架的;在其他情况下可能是其他内容) 可以通过不同的方式获取标记的值,例如,等等 const adapter = new HttpAdapter({ ... httpConfig: { withCredentials

我需要设置我的JSData配置,以便为基于cookie的会话身份验证以及CSRF头传递信息。

当实例化
HttpAdapter
时,使用以下命令设置
withCredentials
()和CSRF头(下面的示例设置了
X-CSRFToken
头,但这是特定于服务器端框架的;在其他情况下可能是其他内容)

可以通过不同的方式获取
标记的值,例如,等等

const adapter = new HttpAdapter({
    ...
    httpConfig: {
        withCredentials: true // send cookie-based session credentials
    },
    ...
    beforeHTTP: function(config, opts) {
        ...
        config.headers || (config.headers = {});
        config.headers['X-CSRFToken'] = token;
        ...
        return HttpAdapter.prototype.beforeHTTP.call(this, config, opts);
    }
})