简体   繁体   English

密钥疯狂时如何从本地存储中获取

[英]How to get from local storage when key is crazy

Problem: Library is giving me tokens with long keys.问题:图书馆给我带有长密钥的令牌。 I need the value of a key(refresh-token) so I can make an api request with this token in the headers我需要一个键值(刷新令牌),这样我就可以在标头中使用此令牌发出 api 请求

Msal is storing tokens to my localstorage with a crazy string, multiple of them. Msal 使用疯狂的字符串将令牌存储到我的本地存储中,其中有多个。 1 accesstoken, 1 refresh token and a tokenId. 1 个访问令牌、1 个刷新令牌和一个令牌 ID。 I just need to get the refresh token value.. but the key is 35eef60c-0000-0000-0000-20cd77000000.bf390000-0000-0000-0000-528094e00000-login.windows.net-refreshtoken-00000000-0000-0000-bf00-000000000003---- How would I attempt to get this value when the key changes its string and is so long?我只需要获取刷新令牌值..但关键是 35eef60c-0000-0000-0000-20cd77000000.bf390000-0000-0000-0000-528094e00000-login.windows.net-refreshtoken-00000000-0000-0000-bf00 -000000000003 ---- 当密钥更改其字符串并且很长时,我将如何尝试获取此值?

You can use Object.keys(localStorage) to get all of the values within localStorage, then proceed to loop over all of them and grab the value for each one.您可以使用Object.keys(localStorage)获取 localStorage 中的所有值,然后继续遍历所有这些值并获取每个值。

const keys = Object.keys(localStorage);

const storageMap = keys.reduce((acc, curr) => {
    acc[curr] = localStorage.getItem(curr);
    return acc;
}, {});

console.log(storageMap)

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

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