问题描述
我有现有的Asp.net core 2.0应用程序.我正在尝试向其添加使用Azure Active Directory连接的服务的身份验证.当我尝试右键单击连接的服务并检查与Azure Active Directory连接的服务进行身份验证时,找不到该选项.我在线搜索,发现对于现有的asp.net核心应用程序,没有连接的服务选项.在这种情况下将如何解决?有什么提示吗?
I have existing Asp.net core 2.0 application. I am trying to add Authentication with Azure Active Directory connected service to it. When I tried to right click on connected services and checked for Authentication with Azure Active Directory connected service, I did not find the option. I searched online and found that for existing asp.net core applications there is not connected service option. What will be the work around in this case? any hints?
推荐答案
您可以尝试以下步骤:
-
安装软件包:
Microsoft.AspNetCore.Authentication.AzureAD.UI
修改Startup.cs以启用Azure AD身份验证:
Modify the Startup.cs to enable Azure AD Authentication:
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options => Configuration.Bind("AzureAd", options));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
添加身份验证中间件以配置:
Add the authentication middleware to Configure :
app.UseAuthentication();
修改appsettings.json
以添加Azure AD应用设置
Modify the appsettings.json
to add the Azure AD app settings
{
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "xxxxxxx.onmicrosoft.com",
"TenantId": "xxxxxx-e83b-4099-93c2-8ae86358d05c",
"ClientId": "xxxxxxxx-80c5-4bd4-ad6a-a967ea0066d6",
"CallbackPath": "/signin-oidc"
},
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*"
}
另一种方法是手动配置OpenId Connect中间件,您可以参考以下文章:
Another way is to config the OpenId Connect Middlerware manually , you can refer to below article :
https://joonasw.net/view/aspnet-core -2-azure-ad-authentication
这篇关于现有Asp.Net核心应用程序中缺少与Azure Active Directory连接的服务的身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!