简体   繁体   English

react-aad-msal 清除本地存储。 传递状态

[英]react-aad-msal clearing localstorage. passing state around

So I've been hitting a wall over this last 2 days.所以在过去的两天里,我一直在碰壁。 I haven't play around with ract/front end work for close to 2 years so please bear with me.我已经将近 2 年没有玩过 ract/前端工作了,所以请耐心等待。

Scenario:设想:
- load page - 加载页面
- throw stuff in localstorage (query string params) - 在本地存储中扔东西(查询字符串参数)
- navigate to login authorization page (using react-aad-msal for this) - 导航到登录授权页面(为此使用 react-aad-msal)
- get back to the main page - 回到主页面
- try to retrieve data from localstorage and the keys I've added are missing. - 尝试从 localstorage 检索数据,但我添加的密钥丢失了。 There are msal tokens etc present.存在 msal 令牌等。

Enviroment:环境:
- Chrome - 铬合金
- React plugin for debug - 用于调试的 React 插件

Unexpected twist: this happens at random.意外的转折:这是随机发生的。 For the best part of yesterday it was working.在昨天的大部分时间里,它都在工作。 and than the keys I've added started to go awol.然后我添加的键开始失控。 Same thing this morning.今天早上也是一样。

To my understanding - if I put something in localstorage, it stays there unless requested to be removed, programmatically or other way.据我所知 - 如果我将某些东西放在 localstorage 中,它会留在那里,除非要求以编程方式或其他方式删除。

So what is going on here?那么这里发生了什么?

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.它必须是 msal 的行为 - 无论是 react-aad-msal 还是它所环绕的实际 msal.js。 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.无论如何,解决方案被证明是在创建提供程序时在AuthenticationParameters state 参数中传递查询字符串,同时忽略本地存储问题。

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.状态只是附加到授权端点使用的回调 url 中,因此它可以按我的需要工作。

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

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