javascript - react-aad-msal 清除本地存储。传递状态
问题描述
所以在过去的两天里,我一直在碰壁。我已经有将近 2 年没有玩过 ract/前端工作了,所以请多多包涵。
场景:
- 加载页面
- 在 localstorage 中扔东西(查询字符串参数)
- 导航到登录授权页面(为此使用 react-aad-msal)
- 返回主页
- 尝试从 localstorage 和密钥中检索数据我'已添加丢失。存在 msal 令牌等。
环境:
- Chrome
- 用于调试的 React 插件
意外的转折:这是随机发生的。对于昨天最好的部分,它正在工作。而且我添加的钥匙开始失控了。今天早上也是一样。
据我了解-如果我将某些内容放在本地存储中,除非要求以编程方式或其他方式删除,否则它会保留在那里。
那么这里发生了什么?
解决方案
Ok think I got it. It must be behavior of the msal - be it react-aad-msal or actual msal.js it is wrapping around. Anyway, solution proved to be to pass query string in state parameter on AuthenticationParameters
when creating the provider omitting the local storage issue all together.
I just pass the query string from component:
<AzureAD
provider={authProviderWithState(this.props.queryString)}
reduxStore={this.props.reduxStore}
forceLogin={false}>
Which is then glued on the top of defaults
export const authProviderWithState = (state) => {
whichAuthParams.state = state;
return new MsalAuthProvider(whichConfig, whichAuthParams, LoginType.Redirect);
};
State is simply appended to the callback url used by the authorization endpoint so it works as I need it.
推荐阅读
- angular - SwitchMap 在 Angular 中未按预期工作
- python - 如何根据原始数据框组合和过滤最终数据框?
- java - Wiremock - 验证唯一的 JSON 匹配预期?
- android - 请求三星将我的应用从电池优化“让应用进入睡眠状态”中列入白名单
- c++ - 对“”类型的非 const 左值引用不能绑定到“*”类型的临时对象
- javascript - AngularJS 绑定的 Ng-Model 内部指令具有错误的属性名称
- c# - 如何读取标签的内容
- spring - Swagger UI:无法推断基本网址
- django - 通过 React html 表单将 CSV 或 Excel 文件以及 json 数据上传到 Django
- deep-learning - 了解目标检测的未命中率与 FPPI 指标