【问题标题】:Azure AD Authentication redirect access denied to static page (.Net Core + Vue)Azure AD 身份验证重定向访问被拒绝到静态页面(.Net Core + Vue)
【发布时间】:2021-09-17 23:53:39
【问题描述】:

当登录的用户无权访问应用程序时,我无法在 Web 应用程序(.Net Core 和 Vue.js)上设置身份验证以重定向到静态页面。

appsettings.json:

"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "xxx.onmicrosoft.com",
"TenantId": "xxx-c519-4651-b8c4-xxx",
"ClientId": "xxx-a3f5-4e77-9427-xxx",
"CallbackPath": "/signin-oidc"

},

Startup.cs/ConfigureServices

// cookie policy 
        services.Configure<CookiePolicyOptions>(options =>
        {
            // This lambda determines whether user consent for non-essential cookies is needed for a given request.
            options.CheckConsentNeeded = context => true;
            options.MinimumSameSitePolicy = SameSiteMode.None;
        });

        // azure AD auth
        if (applicationFeatures.SsoAuthenticationEnabled ?? false)
        {
            // adding authentication with Azure Ad
            services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
                .AddAzureAD(options => Configuration.Bind("AzureAd", options));

            services.Configure<CookieAuthenticationOptions>(
                AzureADDefaults.CookieScheme,
                options => options.AccessDeniedPath = "/home/AccessDenied");

            // enable cross-origin requests from microsoft login plaftorm
            services.AddCors(options =>
            {
                var azureADOptions = Configuration.GetSection("AzureAd").Get<AzureADOptions>();
                options.AddPolicy("CorsPolicy",
                    builder => builder.WithOrigins(azureADOptions.Instance)
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .AllowCredentials());
                
            });
        }

        // add controllers and vue.js project root
        services.AddControllers().AddNewtonsoftJson();
        services.AddSpaStaticFiles(configuration =>
        {
            configuration.RootPath = applicationFeatures.StaticFilesDirectory;
        });

Startup.cs/Configure

if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseRouting();
        app.UseAuthentication();
        app.UseAuthorization();
        app.UseSpaStaticFiles();
        app.UseStaticFiles();
        app.UseCookiePolicy();
        app.UseCors("CorsPolicy");
        app.UseMiddleware<AuthorizationMiddleware>();           

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });

        app.UseSpa(spa =>
        {
            if (env.IsDevelopment())
                spa.Options.SourcePath = "ClientApp";
            else
                spa.Options.SourcePath = "dist";

            if (env.IsDevelopment())
            {
                spa.UseVueCli(npmScript: "serve");
            }

        });

当我以未分配给 Azure 中已注册应用的用户身份登录时,我看到此错误

【问题讨论】:

    标签: c# vue.js .net-core azure-active-directory


    【解决方案1】:

    解决方法

    1. 通过导航到企业应用程序下的属性,将“需要用户分配”更改为否并保存。
    2. 转到应用注册门户并授予管理员同意。

    Reference 1 , Reference 2

    【讨论】:

      猜你喜欢
      • 2020-12-23
      • 2022-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-15
      • 2015-09-30
      • 2020-03-09
      • 2017-11-28
      相关资源
      最近更新 更多