Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.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
Javascript 如何清除保存在浏览器中的http基本授权凭据_Javascript_Angular_Cross Browser_Http Authentication - Fatal编程技术网

Javascript 如何清除保存在浏览器中的http基本授权凭据

Javascript 如何清除保存在浏览器中的http基本授权凭据,javascript,angular,cross-browser,http-authentication,Javascript,Angular,Cross Browser,Http Authentication,在angular应用程序中,我使用http auth头向无状态rest服务器发送XHR登录请求: http .get(`${site.url}/login`, { headers: { Authorization: `Basic ${btoa(`${username}:${password}`)}`, }, withCredentials: true, })

在angular应用程序中,我使用http auth头向无状态rest服务器发送XHR登录请求:

http
          .get(`${site.url}/login`, {
            headers: {
              Authorization: `Basic ${btoa(`${username}:${password}`)}`,
            },
            withCredentials: true,
          })
无论何时我请求相同的服务器,我都不需要再次发送凭据:它们由浏览器自动保存。这很好,这样我就不必在浏览器上保存凭据(服务器是无状态的,因此没有可用的会话或令牌)

然而,这带来了一个安全问题:当用户注销时(这是浏览器中存储的一个简单布尔值),他的浏览器仍然能够连接到服务器:在XSS的情况下,有人可以再次连接


有没有办法从Javascript中清除这些凭据?我看到了一些黑客行为(使用错误的凭据请求服务器…),但我正在寻找一种一致且安全的方法。

头是不可变的-它们不能更改。但是,您可以使用一种称为JWT(JSON Web令牌)的技术