Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AuthenticationBuilder does not contain a definition for AddAzureAd

Im following a tutorial from here and trying to enable OpenId Connect using Azure Ad and here's the code that I am trying to add to the Startup.cs file.

    services.AddAuthentication(sharedOptions =>
        {
            sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
        })
        .AddAzureAd(options => Configuration.Bind("AzureAd", options))
        .AddCookie();

But it has red underline for AddAzureAd and shows this error message:

'AuthenticationBuilder' does not contain a definition for 'AddAzureAd' and no accessible extension method 'AddAzureAd' accepting a first argument of type 'AuthenticationBuilder' could be found (are you missing a using directive or an assembly reference?)

Steps I have tried:

  1. Clean and rebuild the solution
  2. restart visual studio

But it doesnt fix the issue. Anyone knows what's the other reason that causes this?

like image 863
superninja Avatar asked Feb 19 '19 23:02

superninja


2 Answers

I had the exact same loss of time with something as stupid as not adding the reference. The answer to this question would be along the lines of:

 dotnet add package Microsoft.AspNetCore.Authentication.AzureAD.UI --version 2.2.0

Notice that you may have added another reference related to authentication but not the one you are having the problem about.

like image 117
Paulo Neves Avatar answered Nov 02 '22 09:11

Paulo Neves


I had to add a using statement to my Startup file.

using Microsoft.AspNetCore.Authentication;
like image 45
Dave Avatar answered Nov 02 '22 10:11

Dave