mahdi yadi
mahdi yadi

Reputation: 15

Error CS1061 'AuthenticationBuilder' does not contain a definition for 'AddOpenIdConnect

Project on .Net 8

IConfiguration configuration = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json")
    .Build();

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();

builder.Services.AddDbContext<StudentDataContext>(options =>
options.UseSqlServer(configuration.GetConnectionString("SecurityWebAppConnectionStrings")));


builder.Services.AddAuthorization(options =>
{
    options.AddPolicy("FacultyNumber",
        policy => policy.RequireClaim("FacultyNumber")
        );
});

builder.Services.AddAuthentication(options =>
{
    options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    options.DefaultChallengeScheme = "oidc";
})
                .AddCookie(options =>
                {
                    options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
                    options.Cookie.Name = "Cookie";
                })
                .AddOpenIdConnect("oidc", options =>
                {
                    options.Authority = "http://localhost:5000";
                    options.RequireHttpsMetadata = false;
                    options.ClientId = "RouxAcademyMVC";
                    options.SaveTokens = true;
                });


var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthentication();
app.UseAuthorization();

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();

Error Text : Severity Code Description Project File Line Suppression State Error CS1061 'AuthenticationBuilder' does not contain a definition for 'AddOpenIdConnect' and no accessible extension method 'AddOpenIdConnect' accepting a first argument of type 'AuthenticationBuilder' could be found (are you missing a using directive or an assembly reference?) SecurityWebApp.WebClient SecurityWebApp.WebClient\Program.cs 46 Active

No matter how much I searched, I couldn't find anything?

Upvotes: 1

Views: 295

Answers (1)

Mark Seemann
Mark Seemann

Reputation: 233150

The various AddOpenIdConnect methods are extension methods defined in the Microsoft.Extensions.DependencyInjection namespace.

Try adding the appropriate using directive to the top of your code file:

using Microsoft.Extensions.DependencyInjection;

Upvotes: 1

Related Questions