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?
Asked
Active
Viewed 1,762 times
1 Answers
3
You can try below steps :
Install the package :
Microsoft.AspNetCore.Authentication.AzureAD.UI
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();
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": "*" }
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

Nan Yu
- 26,101
- 9
- 68
- 148
-
do we need to install any nuget package with above changes? – Kurkula Feb 08 '19 at 21:45
-
1@Kurkula ,just need to install `Microsoft.AspNetCore.Authentication.AzureAD.UI` if choosing solution 1 – Nan Yu Feb 11 '19 at 01:40
-
do we need clientsecret also in appsettings file? – Kurkula Mar 08 '19 at 04:54
-
1if you want to call api /resource, yes , you need client secret in web application . If just sign-in , no, you needn't – Nan Yu Mar 08 '19 at 05:12