問題描述
我有現有的 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 Middlerware,您可以參考以下文章:
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 連接服務的身份驗證的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!