【问题标题】:aspnetcore2.0 azure web app deployment enable organizational authenticationaspnetcore2.0 azure web 应用部署启用组织身份验证
【发布时间】:2018-02-12 23:33:54
【问题描述】:

我正在使用 VS1017 将 Web 应用程序从 VS2015 中的 aspnetcore1.0 迁移到 aspnetcore2.0。

我正在使用 azure 活动目录和 jwt 不记名身份验证来保护同一项目中的 angularjs 客户端使用的我的其余端点

在我的机器上调试时一切正常,但是当我将它部署到天蓝色时,我在发出请求时收到此错误

值不能为空。参数名称:clientSecret

在 azure 门户中使用 kudu 进行查看,没有用于 azuread 设置的环境变量,也没有用于客户端机密的环境变量,因为它们曾经在 netcore1.0 案例中。在 VS2015 中,我在发布应用程序时选中了“启用组织身份验证”复选框,但在 VS2017 中并非如此,我猜这与部署过程中创建的 env 变量有关。

我的问题是,使用这种类型身份验证从 VS2017 部署到天蓝色的 aspnetcoreapp2.0 时,最佳实践是什么,以及如何在生产环境中管理应用程序设置和客户端机密以进行 aad 身份验证?

aspnetcore2.0 VS1017项目中用到的库:

"Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.1.0-preview1-26771"
"Microsoft.Azure.ActiveDirectory.GraphClient" Version="2.1.1"
"Microsoft.IdentityModel.Clients.ActiveDirectory" Version="3.16.0"

aspnetcore1.0 VS105 环境变量:

从 VS2017 部署时缺少这些

【问题讨论】:

    标签: azure authentication asp.net-core adal


    【解决方案1】:

    在 Asp.net Core 1.0 中,当开发 Web 应用启用组织身份验证时,Visual Studio 将在appsettings.json 中创建 Azure AD 配置

      "Authentication": {
        "AzureAd": {
          "AADInstance": "https://login.microsoftonline.com/",
          "CallbackPath": "/signin-oidc",
          "ClientId": "xxxxxxxxxxxxxxxxxxx",
          "Domain": "testnanyu.onmicrosoft.com",
          "TenantId": "xxxxxxxxxxxxxxxxxxxxxxxx"
        }
      },
    

    然后,如果覆盖 Azure 应用服务中的嵌套键(通过环境变量),您可以使用完整路径 Authentication:AzureAd:ClientId 作为名称来定义变量。

    但在 Asp.net Core 2.0 中,Visual Studio 将创建 Azure AD 配置,例如:

      "AzureAd": {
        "Instance": "https://login.microsoftonline.com/",
        "Domain": "testnanyu.onmicrosoft.com",
        "TenantId": "xxxxxxxxxxxxxxxxxxxxxxxxx",
        "ClientId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "CallbackPath": "/signin-oidc"
      },
    

    结构改变了。因此,如果覆盖 Azure 应用服务中的嵌套键(通过环境变量),您可以在门户中定义一个变量,例如 AzureAd:ClientId 。使用 kudu ,它将APPSETTING_AzureAd:ClientId 显示为环境变量。

    【讨论】:

    • 最终按照您的建议覆盖了 Azure 应用服务中的嵌套键,并且效果很好,顺便感谢您。无论如何,在从 Visual Studio 部署期间,它不会像以前的 aspnetcore 版本那样自动完成,这感觉像是退了一步,可能会在进一步的更新中。
    • 他们将配置代码从 startup.cs 中移出的事实让我有点困惑,因为我认为这个问题的原因是我在这件事上遗漏了一些东西。这里有一篇关于 aspnetcore2.0 结构变化的好文章,供有兴趣的人参考stevejgordon.co.uk/…
    猜你喜欢
    • 2019-02-27
    • 2015-07-29
    • 1970-01-01
    • 1970-01-01
    • 2018-08-11
    • 1970-01-01
    • 2021-12-12
    • 2015-10-14
    • 1970-01-01
    相关资源
    最近更新 更多