Azure 事件目录 : Where can I insert a function to run after a user is signed in?

标签 azure azure-active-directory

我一直在关注这个例子https://azure.microsoft.com/en-us/documentation/articles/active-directory-b2c-devquickstarts-web-dotnet/我非常确定在 SignIn 方法中我可以将我的函数放在那里运行,但我不确定你会如何进行

在 AccountController.cs 示例的顶部部分:

namespace WebApp_OpenIDConnect_DotNet_B2C.Controllers
{
    public class AccountController : Controller
    {
        public void SignIn()
        {
            if (!Request.IsAuthenticated)
            {
                // To execute a policy, you simply need to trigger an OWIN challenge.
                // You can indicate which policy to use by adding it to the AuthenticationProperties using the PolicyKey provided.

                HttpContext.GetOwinContext().Authentication.Challenge(
                    new AuthenticationProperties (
                        new Dictionary<string, string> 
                        { 
                            {Startup.PolicyKey, Startup.SignInPolicyId}
                        })
                    { 
                        RedirectUri = "/", 
                    }, OpenIdConnectAuthenticationDefaults.AuthenticationType);
            }
        } 

在哪里插入 toDoAfterSignedIn();方法 ?或者这是错误的做法,是否有一些监听器或事件发射器会在用户成功登录时通知我?

https://github.com/AzureADQuickStarts/B2C-WebApp-OpenIdConnect-DotNet

最佳答案

正确的插入位置是 Startup.Auth.cs文件。并注册您自己的 OpenIdConnectNotifications 之一。您需要的通知是SecurityTokenValidated。您需要像示例中已有的其他两个通知一样添加它。或者只需在 OpenIdConnectnotifications 初始值设定项中添加以下行:

                SecurityTokenValidated = (notification) => {
                    return Task.Delay(0); 
                }

您获得的通知参数包含您需要了解的有关最终用户及其成功身份验证的所有信息。

关于Azure 事件目录 : Where can I insert a function to run after a user is signed in?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36995367/

相关文章:

c# - Azure Active Directory 不会使用 ASP.NET Core 2.1 MVC 注销

azure - 如何仅将 Azure Active Directory 身份验证添加到 Web 应用程序中的某些 Razor 页面?

azure - 如何从使用 Azure AD 作为身份验证提供程序的应用程序无缝登录 Salesforce

azure - 为什么 Azure 找不到我的 TFS 项目?

javascript - 获取 Azure Active Directory token javascript

azure - 使用哪个 Nuget 来创建 AAD 应用程序?

azure - 为什么 RBAC 服务主体未在 az ad sp 列表中列出?

适用于 UWP 的 Azure AD B2C 需要 API 范围,但我没有

Azure 存储帐户防火墙 AnonymousIpAuthorizationError

ios - PWA 重定向到登录页面并陷入 2FA 循环