小编Vol*_*der的帖子

重新挑战ASP.NET Core中经过身份验证的用户

我在ASP.NET Core中遇到了一些身份验证管道问题.我的方案是我想向已经使用OpenID Connect和Azure AD进行身份验证的用户发出挑战.您可以在多种情况下执行此操作,例如在AAD v2端点方案中请求其他范围时.

这类似于ASP.NET MVC中的魅力,但在ASP.NET Core MVC中,用户被重定向到cookie身份验证中间件中配置的Access Denied页面.(当用户未登录时,发出挑战按预期工作.)

在网上搜索并为我的中间件选项尝试不同的参数几个小时后,我开始怀疑我要么缺少明显的东西,要么这种行为是设计的,我需要以其他方式解决我的要求.有人对此有任何想法吗?

编辑:我的Startup.cs的相关部分如下所示:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();

        services.AddAuthentication(
            SharedOptions => SharedOptions.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme);
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        // <snip...>

        app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme });

        var options = new OpenIdConnectOptions
        {
            AuthenticationScheme = OpenIdConnectDefaults.AuthenticationScheme,
            ClientId = ClientId,
            Authority = Authority,
            CallbackPath = Configuration["Authentication:AzureAd:CallbackPath"],
            ResponseType = OpenIdConnectResponseType.CodeIdToken,
            PostLogoutRedirectUri = "https://localhost:44374/",
            TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
            {
                ValidateIssuer = false
            }
        };
        options.Scope.Add("email");
        options.Scope.Add("offline_access");

        app.UseOpenIdConnectAuthentication(options); …
Run Code Online (Sandbox Code Playgroud)

azure-active-directory openid-connect asp.net-core

8
推荐指数
1
解决办法
1874
查看次数