简体   繁体   English

使用 AAD 身份验证将 Blazor 应用程序部署到 Azure

[英]Deploying Blazor app to Azure using AAD Authentication

I've created a default Blazor App (Server-side) in Visual Studio 2019 with Azure AD authentication.我已经在 Visual Studio 2019 中使用 Azure AD 身份验证创建了一个默认的 Blazor 应用程序(服务器端)。 Running the app locally it authenticates against AAD as expected.在本地运行应用程序,它按预期对 AAD 进行身份验证。 However, when deployed to an App Service in Azure the app won't run.但是,当部署到 Azure 中的应用服务时,该应用将不会运行。 The deployment process works fine, Deployment Mode is Self-Contained and App Service is Windows (Linux works the same way).部署过程工作正常,部署模式是自包含的,应用服务是 Windows(Linux 的工作方式相同)。 All files and settings are made appropriately, but the below error is displayed when navigating to the site.所有文件和设置都已正确进行,但导航到该站点时会显示以下错误。

This page isn't working blazorappxxxxxxx.azurewebsites.net is currently unable to handle this request.此页面不工作 blazorappxxxxxxx.azurewebsites.net 当前无法处理此请求。

HTTP ERROR 500 HTTP 错误 500

Disable the authentication code in startup.cs and redeploy, now the app works.禁用 startup.cs 中的身份验证代码并重新部署,现在应用程序可以运行了。

        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));
        });

The App is registered in AAD and Redirect URIs are set, implicit grant is configured for Access Token and ID Token.应用在 AAD 中注册并设置了重定向 URI,为 Access Token 和 ID Token 配置了隐式授权。

Try to use the code as below:尝试使用如下代码:

public void ConfigureServices(IServiceCollection services)  
{  
    services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
         .AddAzureAD(options => Configuration.Bind("AzureAd", options)); 
    services.AddControllers();  
}  

Behind the scenes, Visual Studio automatically registers our ASP.NET Core app in Azure AD App Registration.在幕后,Visual Studio 会在 Azure AD 应用注册中自动注册我们的 ASP.NET Core 应用。 For more details, you could refer to this tutorial .更多细节,你可以参考这个教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Azure AAD进行身份验证 - Authentication using Azure AAD 使用 AAD 进行身份验证的 Azure App 在一段时间后返回 401 - Azure App using AAD for authentication returns 401 after period of time Azure Web App从AAD身份验证注销 - Azure Web App logout from AAD Authentication Azure 订阅:在 PowerShell 上使用证书或 AAD 身份验证? - Azure Subscription: using Certificate or AAD authentication on PowerShell? 在 Azure AAD oauth 身份验证中使用 saml 令牌 - Using saml tokens in Azure AAD oauth authentication 在 Azure 应用服务身份验证与身份验证(经典)中重定向以使用 AAD 登录 - Redirect to login with AAD in Azure App Service Authentication vs Authentication (Classic) 在Azure Web App中针对AAD使用Active Directory密码时,“不支持关键字:身份验证” - “Keyword not supported: authentication” when using Active Directory Password against AAD in Azure Web App 通过 REST 对 AAD 企业应用程序进行 Azure AD 身份验证 - Azure AD authentication via REST to an AAD enterprise App Dockerized Azure Function 应用程序的 AAD B2C 身份验证 - AAD B2C Authentication for Dockerized Azure Function App 如何调用 Azure CosmosDB REST API 在 powershell 使用 AAD 身份验证 - How to Invoke Azure CosmosDB REST API In powershell using AAD authentication
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM