Azure应用程序服务容器是否支持具有Open ID Connect的Blazor应用程序?

时间:2020-06-04 20:39:55

标签: azure docker blazor asp.net-blazor

问题 将Blazor Webassembly应用程序部署为App Service容器后,在浏览器中出现以下错误:

AuthenticationService.js:1 Mixed Content: The page at 'https://YYY.azurewebsites.net/authentication/login?returnUrl=https%3A%2F%2FYYY.azurewebsites.net%2Ffetchdata' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://YYY.azurewebsites.net/.well-known/openid-configuration'. This request has been blocked; the content must be served over HTTPS.

想知道现在Blazor是否支持docker部署,如果可以,我们如何解决?

重新进行认证的步骤: 1.在VS 2019 Professional预览版16.7.0预览版2.0中:创建具有托管选项的Blazor应用程序(标准“ Blazor WebAssembly应用程序”模板),并使用Identity Server进行应用程序内身份验证 2.将linux docker容器部署到Azure Web App以获得容器服务(B1) 3. App Service的“仅HTTPS”设置为开

我们正在使用以下简单的docker文件:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS runtime
WORKDIR /app
EXPOSE 80
COPY . .
ENTRYPOINT ["dotnet", "AppNameHere.Server.dll"]

Blazor使用的OIDC JS库以某种方式没有发现我们通过HTTPS运行的事实(尽管在容器实例和App服务负载平衡器之间使用了HTTP)。

1 个答案:

答案 0 :(得分:1)

您应该:

  • 为端点安装HTTPS证书并运行完整的端到端HTTPS(推荐)
    要在docker上为红est设置证书,请阅读this doc
  • 覆盖您的应用使用的OIDC配置:

创建metadata.json文件

{
    "issuer": "http://YYY.azurewebsites.net",
    "jwks_uri": "https://YYY.azurewebsites.net/.well-known/openid-configuration/jwks",
    "authorization_endpoint": "https://YYY.azurewebsites.net/connect/authorize",
    "token_endpoint": "https://YYY.azurewebsites.net/connect/token",
    "userinfo_endpoint": "https://YYY.azurewebsites.net/connect/userinfo",
    "end_session_endpoint": "https://YYY.azurewebsites.net/connect/endsession",
    "check_session_iframe": "https://YYY.azurewebsites.net/connect/checksession"
}

“发出者”:“ http://YYY.azurewebsites.net”是HTTP网址,而不是HTTPS

配置应用程序以从您的自定义文件获取元数据

public class Program
{
    public static async Task Main(string[] args)
    {
        var builder = WebAssemblyHostBuilder.CreateDefault(args);
        builder.RootComponents.Add<App>("app");
        builder.Services.AddOidcAuthentication<RemoteAuthenticationState, RemoteUserAccount>(options =>
                {
                    var providerOptions = options.ProviderOptions;
                    providerOptions.Authority = "https://YYY.azurewebsites.net";
                    providerOptions.MetadataUrl = "https://YYY.azurewebsites.net/metadata.json";
                    providerOptions.PostLogoutRedirectUri = "https://YYY.azurewebsites.net/authentication/logout-callback";
                    providerOptions.RedirectUri = "https://YYY.azurewebsites.net/login-callback";
                });
        await builder.Build().RunAsync();
    }
}
相关问题