Mesmo registrando um usuário e logando com ele, ao testar o get artista ele volta 401.
Login:
Método:
Mesmo registrando um usuário e logando com ele, ao testar o get artista ele volta 401.
Login:
Método:
program.cs
using Microsoft.EntityFrameworkCore;
using ScreenSound.API.Endpoints;
using ScreenSound.Data;
using ScreenSound.Modelos;
using ScreenSound.Shared.Dados.Modelos;
using ScreenSound.Shared.Models.Models;
using System.Text.Json.Serialization;
var builder = WebApplication.CreateBuilder(args);
uilder.Services.AddCors(
options => options.AddPolicy(
"wasm",
policy => policy.WithOrigins(
[builder.Configuration["BackendUrl"] ?? "https://localhost:7122/",
builder.Configuration["FrontendUrl"] ?? "https://localhost:7199/"]
).AllowAnyMethod()
.SetIsOriginAllowed(pol => true)
.AllowAnyHeader()
.AllowCredentials()
)
);
builder.Services.AddDbContext<ScreenSoundContext>((options) =>
{
options.UseSqlServer(builder.Configuration["ConnectionStrings:ScreenSoundDB"]).UseLazyLoadingProxies(false);
});
builder.Services.AddIdentityApiEndpoints<PessoaComAcesso>().AddEntityFrameworkStores<ScreenSoundContext>();
builder.Services.AddAuthorization();
builder.Services.AddTransient<DAL<Artista>>();
builder.Services.AddTransient<DAL<Musica>>();
builder.Services.AddTransient<DAL<Genero>>();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.Configure<Microsoft.AspNetCore.Http.Json.JsonOptions>
(
options => options.SerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles
);
var app = builder.Build();
app.UseAuthentication();
app.UseCors("wasm");
app.AddEndPointArtistas();
app.AddEndPointMusicas();
app.AddEndPointGenero();
app.MapGroup("auth").MapIdentityApi<PessoaComAcesso>().WithTags("Autorizar");
app.UseSwagger();
app.UseSwaggerUI();
app.UseCors(x => x.AllowAnyMethod()
.AllowAnyHeader()
.SetIsOriginAllowed(origin => true)
.AllowCredentials()
);
app.UseStaticFiles();
app.Run();
Ainda não consegui encontrar o bug.