【问题标题】:.NET Core 3.1 Azure AD Authentication interceptor.NET Core 3.1 Azure AD 身份验证拦截器
【发布时间】:2021-01-03 17:42:50
【问题描述】:

我有一个使用 Azure AD 进行身份验证的 .NET Core 3.1 Web 应用程序,并且它与以下源代码一起正常工作。

        services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
            .AddAzureAD(options => Configuration.Bind("AzureAd", options));

        services.AddControllersWithViews(options =>
        {
            var policy = new AuthorizationPolicyBuilder()
                .RequireAuthenticatedUser()
                .Build();
            options.Filters.Add(new AuthorizeFilter(policy));
        });

现在我想添加一个拦截器,告诉我身份验证是否成功。 我想在文件、数据库或其他任何东西中记录登录。 我该如何执行这个过程?

【问题讨论】:

    标签: .net authentication .net-core azure-active-directory


    【解决方案1】:

    您可以使用eventsOpenIDConnectOptions。当从 UserInfoEndpoint 检索用户信息时调用OnUserInformationReceived。登录成功后执行一次。

    options.Events.OnUserInformationReceived = ctx =>
    {
        // your code here
        return Task.CompletedTask;
    };
    

    【讨论】:

      猜你喜欢
      • 2020-06-16
      • 1970-01-01
      • 2020-05-27
      • 2021-05-16
      • 2021-01-08
      • 2020-03-09
      • 2021-03-16
      • 1970-01-01
      • 2020-05-30
      相关资源
      最近更新 更多