Beksy
Beksy
CC#
Created by Beksy on 2/3/2024 in #help
dotnet 8 redirects [Authorize] Tagged endpoints to /Account/Login
For example request sent in swagger at /Api/Subscription Goes to /Account/Login?ReturnUrl=%2Fapi%2FSubscription And returns 404 since it doesnt exist
c#
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddDbContext<VoithosDbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("Database")));

builder.Services.AddIdentity<User, IdentityRole>()
.AddEntityFrameworkStores<VoithosDbContext>()
.AddApiEndpoints();

builder.Services.AddAuthentication().AddBearerToken(IdentityConstants.BearerScheme);
builder.Services.AddAuthorizationBuilder();

builder.Services.AddHostedService<ProductFetchBackgroundService>();
builder.Services.AddScoped<ProductFetchService>();

builder.Services
.AddAutoMapperProfiles()
.AddServices()
.AddMediatR(typeof(HandlerBase))
.AddCors(options =>
{
options.AddPolicy("CorsPolicy", corsBuilder =>
{
corsBuilder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
})
.AddControllers();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.MapIdentityApi<User>();

app
.UseExceptionHandling()
.UseSwagger()
.UseSwaggerUI()
.UseRouting()
.UseCors("CorsPolicy")
.UseAuthentication()
.UseAuthorization()
.UseEndpoints(endpoints => endpoints.MapControllers());


app.Run();
c#
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddDbContext<VoithosDbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("Database")));

builder.Services.AddIdentity<User, IdentityRole>()
.AddEntityFrameworkStores<VoithosDbContext>()
.AddApiEndpoints();

builder.Services.AddAuthentication().AddBearerToken(IdentityConstants.BearerScheme);
builder.Services.AddAuthorizationBuilder();

builder.Services.AddHostedService<ProductFetchBackgroundService>();
builder.Services.AddScoped<ProductFetchService>();

builder.Services
.AddAutoMapperProfiles()
.AddServices()
.AddMediatR(typeof(HandlerBase))
.AddCors(options =>
{
options.AddPolicy("CorsPolicy", corsBuilder =>
{
corsBuilder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
})
.AddControllers();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.MapIdentityApi<User>();

app
.UseExceptionHandling()
.UseSwagger()
.UseSwaggerUI()
.UseRouting()
.UseCors("CorsPolicy")
.UseAuthentication()
.UseAuthorization()
.UseEndpoints(endpoints => endpoints.MapControllers());


app.Run();
2 replies
CC#
Created by Beksy on 1/14/2024 in #help
How do i add Identity endpoints?
I have been trying to add identity endpoints for past 3 hours 😄 someone help im using .net 8, i can search for lot of stuff for .net 8 preview but cant see if its included in .net 8
39 replies