我正在使用VS1017将网络应用从VS2015中的aspnetcore1.0迁移到aspnetcore2.0。
我正在使用azure活动目录和jwt承载身份验证来保护同一项目中angularjs客户端使用的其余端点
在我的机器上调试时一切正常,但是当我将它部署到azure时,我在发出请求时遇到此错误
值不能为空。参数名称:clientSecret
在azure门户网站中查看使用kudu,azuread设置没有环境变量,也没有客户机密的环境变量,因为它们曾经是netcore1.0的情况。在VS2015中,我在发布应用程序时获得了“启用组织身份验证”复选框,但在VS2017中并非如此,我猜这与在azure的部署过程中创建的env变量有关。
我的问题是,使用此类型身份验证从VS2017部署到azure 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部署时缺少这些内容
答案 0 :(得分:1)
在Asp.net Core 1.0中,当开发Web应用程序启用组织身份验证时,Visual Studio将在appsettings.json
"Authentication": {
"AzureAd": {
"AADInstance": "https://login.microsoftonline.com/",
"CallbackPath": "/signin-oidc",
"ClientId": "xxxxxxxxxxxxxxxxxxx",
"Domain": "testnanyu.onmicrosoft.com",
"TenantId": "xxxxxxxxxxxxxxxxxxxxxxxx"
}
},
然后,如果覆盖Azure App Services中的嵌套键(通过环境变量),则可以使用完整路径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 App Services中的嵌套键(通过环境变量),则可以在门户中定义变量,如AzureAd:ClientId
。使用kudu,它将APPSETTING_AzureAd:ClientId
显示为环境变量。