使用RemoteAuthenticatorView OnLogInSucceeded会提供第二个AzureAD登录对话框 [英] Using RemoteAuthenticatorView OnLogInSucceeded gives a second AzureAD login dialog box

查看:73
本文介绍了使用RemoteAuthenticatorView OnLogInSucceeded会提供第二个AzureAD登录对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

难以理解发生了什么,我真的可以使用一些想法和投入.拜托,我不太擅长用文字描述问题所在,所以请保持谦逊.

Having trouble to understand what going on and I really could use some thoughts and inputs. Please, I am not very good at describing in text what is the problem, so be gentle.

我有一个Blazor wasm前端和一个Azure Function后端.
我做一个标准的,没什么特别的Azure AD登录.在稍后的代码中,我使用承载令牌连接了AzFunction,并且可以正常工作.AzFunction评估令牌并识别用户以进行进一步处理.我应该提到AzFunction连接到Graph和其他API.

I have a Blazor wasm frontend and a Azure Function backend.
I do a standard, nothing special, Azure AD login. Later in code, I connect with the AzFunction using the bearer token, and it works. The AzFunction evaluates the token and identifies the user for further processing. I should mention that the AzFunction connects to Graph and other APIs.

所以一切都很好并且可以正常工作,这是我的问题.
我想在登录时连接到AzFuntion,以获取一些用户配置文件信息.为了调试,我只做了一个按钮,然后一切正常.

So everything is fine and working, here is my problem.
I want to connect to the AzFuntion at login time, to get some user profile information. For debugging I simply made a button, and again, everything works.

然后,我将按钮代码"移到了到Authenticator.razor中的RemoteAuthenticatorView OnLogInSucceeded调用的方法.

Then I moved "the button code" to a method called by RemoteAuthenticatorView OnLogInSucceeded, in Authenticator.razor.

< RemoteAuthenticatorView Action =" @ Action"LogInFailed ="LogInFailedFragment";OnLogInSucceeded ="LoginComplete";/>

这是我的问题:使用OnLogInSucceeded,我必须响应2次Azure AD登录.在第一个之后,它直接转到第二个.全部都是因为我将代码从按钮移到了OnLogInSucceeded.当我调试时,我清楚地看到令牌在连接到AzFunction之前就已经存在.

Here is my problem: Using the OnLogInSucceeded I get 2 Azure AD logins that I have to respond to. After the first one, It goes directly to the second. All simply because I moved the code from a button to OnLogInSucceeded. When I debug, I clearly see that the token is present before it connects to AzFunction.

此外,当我在Visual Studio中从OnLogInSucceeded调用的LoginComplete函数中设置一个断点,并且仅将其保留几秒钟时,便会通过一个登录对话框完成整个登录过程.

Also, when I set a breakpoint in visual studio at the LoginComplete function called from OnLogInSucceeded, and just holds it for a few seconds, it goes throught the login process with just one login dialog.

任何人都可以帮助我理解原因吗?

Could anyone please help me understand why?

任何建议,最好将获取用户个人资料"代码?我需要的是运行的代码,因此在登录完成后,只需一次登录即可检索用户个人资料信息.

Any pointers on a better please to put the "get User profile" code? What I need is the code to run, so when the login is completed, the user profile info is retrived, with just one login.


该代码似乎有更好的解决方案,但是我仍然不明白是什么原因使第二次登录到apper ...这是我的问题的主要反应.


The code seem to have a better solution, however I still do not understand what made the second login to apper... And that was kind of the main reson for my question.

推荐答案

感谢Zack Blazor Webassembly身份验证事件,我得到了很好的指导,并阅读了

Thanks to Zack Blazor Webassembly Authenticated Event, I was sent in a good direction and read Microsoft pages on AuthenticationStateChanged Event. It also simplified my code since I now have the retrival of UserProfile, in the UserProfile component than Authentication.razor.

@inject AuthenticationStateProvider AuthenticationStateProvider

private void OnAuthenticationStateChanged(Task<AuthenticationState> task)
{
    if(task.IsCompletedSuccessfully)
    {
        GetUserProfile();
    }
}

不确定这是否是最终代码",但是它确实有效,在我看来,这似乎是可行的方法.

Not sure if this is "the final code", but it sure works and seems to me like a plausable way to go.

这篇关于使用RemoteAuthenticatorView OnLogInSucceeded会提供第二个AzureAD登录对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆