使用 Azure AD 成功进行身份验证后,Azure OAuth 身份验证无法重定向

时间:2021-06-24 09:58:27

标签: azure asp.net-core azure-active-directory azure-web-app-service azure-application-gateway

我有 .net 核心 mvc 应用程序。我已使用 Azure AD 为我的 Web 应用实施 OAuth 身份验证。

从 localhost 它按预期运行良好,但从 Azure WebApp 成功 OAuth 身份验证后,它无法重定向到路径。

仅供参考,我正在通过 AppGateway 访问该应用程序

我正在使用以下代码块进行 OAuth 身份验证。

Startup.cs:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
            .AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"));

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

appsettings.json:

  "AzureAd": {
    "Instance": "https://login.microsoftonline.com/",
    "Domain": "[Enter the domain of your tenant, e.g. contoso.onmicrosoft.com]",
    "ClientId": "567f20e2-eb4f-4a1b-8fe6-ff1d76be8ec0",
    "TenantId": "ea80952e-xxxx-xxxx-xxxx-5457852b0f7e",
  },

我尝试在 Azure 应用程序注册边栏选项卡中定义重定向 url,但定义的值不是从应用程序中选取的。

Azure App registration redirect url

谁能帮我解决这个问题。

附上截图供您参考。 Screenshot of error response after successful authentication

1 个答案:

答案 0 :(得分:0)

遇到这种问题,可以试试通用的解决方法:

当您访问应用程序 url 时,您将被重定向到登录页面。 解码授权请求url,你会找到redirect_url,复制redirect_url的值粘贴到azure门户,再试一次。

enter image description here