Somehow the same project we are working on with my colleague doesn't call the HTTP POST method that retrieves the token on my PC, but works fine on my colleague's PC.
The code is the same, but my output show me this pop-up:
The request works fine in Postman:
Have tested different browsers. We have deployed the package on the server and the token is retrieved correctly. Deploying the package locally shows the same error. Does something on my PC interfere with an HTTP request ?
Here is the code:
services
.AddSwaggerGen(
(c) =>
{
var version = $"v{Assembly.GetEntryAssembly()?.GetVersionInfo()}";
c.OperationFilter<ChorusModeHeaderFilter>();
c.OperationFilter<AuthenticationFilter>();
c.OperationFilter<ErrorFilter>();
c.OperationFilter<MaintenanceFilter>();
c.SwaggerDoc(version, new OpenApiInfo { Title = appName, Version = version });
c.AddSecurityDefinition(
"Bearer",
new OpenApiSecurityScheme
{
Type = SecuritySchemeType.OpenIdConnect,
OpenIdConnectUrl = new Uri($"../../.well-known/openid-configuration", UriKind.Relative)
});
c.AddSecurityRequirement(
new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type=ReferenceType.SecurityScheme,
Id="Bearer"
}
},
Array.Empty<string>()
}
});
xmlDocumentationFiles
.Select((path) => Path.Combine(AppContext.BaseDirectory, path))
.ToList()
.ForEach((path) => c.IncludeXmlComments(path));
});
and also:
public class AuthenticationFilter : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
if (!context.MethodInfo.GetCustomAttributes(true).OfType<AllowAnonymousAttribute>().Any())
{
operation.Responses.Add(
$"{(int)HttpStatusCode.Unauthorized}",
new OpenApiResponse { Description = "Unauthorized" });
}
else
{
// No authentication skip it
}
}
}