本文介绍了Blazor Webassembly身份验证事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Microsoft.AspNetCore.Components.WebAssembly.Authentication对用户进行身份验证时,在ASP.NET Core(最新,blazor)上托管的客户端应用程序的Blazor Webassembly应用程序中,何时/如何调用操作用户已通过身份验证?即使他们回到应用程序并进行了活跃的会话.

When authenticating users with Microsoft.AspNetCore.Components.WebAssembly.Authentication, in a Blazor Webassembly application on the client side app that is hosted on ASP.NET Core (latest, blazor), when/how to call an action every time a user is authenticated? Even if they come back to the app and have an active session.

更新2020-07-15:我要克服的问题是,一旦用户登录(MSAL)以获取其信息和个人资料图片,我们就有一项可用于Graph API的服务.他们登录后,我使用RemoteAuthenticatorView.OnLogInSucceeded事件来知道他们实际登录的时间.麻烦的是,如果他们随后刷新页面(F5),则该服务将丢失Graph信息.我想我实际上要实现的是持久保存会话数据.

Update 2020-07-15:The problem I am trying to overcome is that we have a service that goes to Graph API once a user logs in (MSAL) to get their info and profile image. After they log in, I use the RemoteAuthenticatorView.OnLogInSucceeded event to know when they actually logged in. Trouble is, if they then refresh the page (F5), the service loses the Graph info. I guess what I'm actually trying to achieve is to persist session data.

推荐答案

要解决此问题,到目前为止,我已经解决了使用LoginDisplay组件剃刀中的Authorized部分的变通办法,以触发服务检查服务用户info为空,然后再次转到Graph而不是尝试存储在localstorage或类似的东西中...然后,我让用户信息显示组件订阅了服务中的事件,以了解何时需要更新用户信息以调用StateHasChanged().

To overcome this, I so far settled with the workaround to use the Authorized section in razor of the LoginDisplay component, to trigger the service to check if the service user info is empty and then go to Graph again instead of trying to store in in localstorage or something like that... Then, I have user info displaying components subscribe to an event in the service to know when the user info needed updated to call StateHasChanged().

如果有更好的解决方案在页面刷新之间持久保存服务数据,我全神贯注.

If there is a better solution to persisting service data across page refreshes, I am all eyes.

这篇关于Blazor Webassembly身份验证事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 04:08