Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json parse error while using /login method from WebApiCore Identity provided by [email protected] #34177

Closed
pfigueiredo opened this issue Jul 7, 2024 · 2 comments
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported

Comments

@pfigueiredo
Copy link

pfigueiredo commented Jul 7, 2024

While configuring authentication and autorization with web.api endpoints and using:

\packages\microsoft.aspnetcore.identity.entityframeworkcore\8.0.6
\packages\microsoft.entityframeworkcore.sqlserver\8.0.6
\packages\microsoft.aspnetcore.spaproxy\8.0.6\

I get the following error while trying to call any of the api methods created: (ex. /login ou /register)

Microsoft.AspNetCore.Http.BadHttpRequestException: Failed to read parameter "LoginRequest login" from the request body as JSON. ---> System.Text.Json.JsonException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0. ---> System.Text.Json.JsonReaderException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. LineNumber: 0 | BytePositionInLine: 0.

my configuration is as follows:

`
var myAllowSpecificOrigins = "_myAllowSpecificOrigins";
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddCors(options =>
{
options.AddPolicy(name: myAllowSpecificOrigins,
policy => {
policy.AllowAnyMethod()
.AllowAnyHeader()
.SetIsOriginAllowed(origin => true)
.AllowCredentials();
});
});

// Add services to the container.
builder.Services.AddSingleton<IDictionary<string, UserConnection>>(opts => new Dictionary<string, UserConnection>());
builder.Services.AddSingleton<IDictionary<string, ChatRoom>>(opts => new Dictionary<string, ChatRoom>());

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddSignalR();
builder.Services.AddDbContext(
options => options.UseSqlServer("Server=DESKTOP-EI90NJF\SQLEXPRESS;User Id=WebChatUser;Password=Password123;Database=WebChat")
);

builder.Services.AddIdentityCore()
.AddEntityFrameworkStores()
.AddApiEndpoints();

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

var app = builder.Build();

app.UseDefaultFiles();
app.UseStaticFiles();
app.UseCors(myAllowSpecificOrigins);
app.UseMiddleware();

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

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapHub("/chatHub");

app.MapFallbackToFile("/index.html");

app.MapIdentityApi();

app.MapControllers();

app.Run();
`

@pfigueiredo
Copy link
Author

pfigueiredo commented Jul 7, 2024

the test was done using the swagger UI rendered by the application and configured (builder.Services.AddSwaggerGen(); app.UseSwagger(); app.UseSwaggerUI())
other controllers don't return any error like the /WeatherForecast

@roji
Copy link
Member

roji commented Jul 8, 2024

@pfigueiredo this seems like some sort of network/environmental issue that doesn't have anything to do with EF Core.

@ajcvickers ajcvickers added the closed-no-further-action The issue is closed and no further action is planned. label Jul 11, 2024
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported
Projects
None yet
Development

No branches or pull requests

3 participants