简体   繁体   English

Blazor OIDC 刷新令牌

[英]Blazor OIDC Refresh Token

I have a Blazor WASM app that uses OIDC authenication.我有一个使用 OIDC 身份验证的 Blazor WASM 应用程序。 I have the OIDC working.我有 OIDC 工作。

            builder.Services.AddOidcAuthentication(options =>
            {
                options.ProviderOptions.ResponseType = "code";
                options.ProviderOptions.DefaultScopes.Add("offline_access");
                options.ProviderOptions.Authority = "Oauth URL";
                options.ProviderOptions.ClientId = "client ID";
            });

I have the offline_access scope defined so that a refresh token is generated.我定义了offline_access scope,以便生成刷新令牌。

Once the user logins, the response from the token end point gets stored in session storage.用户登录后,来自令牌端点的响应将存储在 session 存储中。 This works great as long as the user doesn't exit the app.只要用户不退出应用程序,这就会很好。 However, once the user closes the browser and then opens the browser again they have to log back into the site, even it the refresh token has not expired.但是,一旦用户关闭浏览器然后再次打开浏览器,他们就必须重新登录该站点,即使刷新令牌尚未过期。

How can an Blazor WASM app using OIDC make use of the refresh token?使用 OIDC 的 Blazor WASM 应用程序如何使用刷新令牌?

Thank you, Travis谢谢你,特拉维斯

I think in your case since you are storing the data in the session storage, the data is lost as soon as the browser is closed.我认为在您的情况下,由于您将数据存储在 session 存储中,因此一旦关闭浏览器,数据就会丢失。 The sessionStorage is scoped to the browser's tab If the user reloads the tab, the state persists. sessionStorage的范围仅限于浏览器的选项卡如果用户重新加载选项卡,state 仍然存在。 If the user closes the tab or the browser, the state is lost.如果用户关闭选项卡或浏览器,state 将丢失。 If the user opens multiple browser tabs, each tab has its own independent version of the data.如果用户打开多个浏览器选项卡,每个选项卡都有自己独立的数据版本。

To address the issue you should use the localStorage in which case the if the user reloads the page or closes and re-opens the browser, the state persists.要解决此问题,您应该使用localStorage在这种情况下,如果用户重新加载页面或关闭并重新打开浏览器,state 仍然存在。

Though from the security perspective sessionStorage is the preferred choice.虽然从安全角度来看sessionStorage是首选。

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

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