feat: update ProductController route and enhance authentication configuration
This commit is contained in:
@@ -19,6 +19,7 @@ namespace Api.Controllers
|
||||
|
||||
// GET: api/Product
|
||||
[HttpGet]
|
||||
[Route("api/product")]
|
||||
public async Task<ActionResult<IEnumerable<Product>>> GetProducts([FromQuery] int? id = null)
|
||||
{
|
||||
if (id.HasValue)
|
||||
|
||||
@@ -22,17 +22,17 @@ namespace Api
|
||||
})
|
||||
.AddJwtBearer(options =>
|
||||
{
|
||||
options.Events = new JwtBearerEvents
|
||||
{
|
||||
OnTokenValidated = context => Task.CompletedTask,
|
||||
OnChallenge = context => Task.CompletedTask
|
||||
};
|
||||
// options.Events = new JwtBearerEvents
|
||||
// {
|
||||
// OnTokenValidated = context => Task.CompletedTask,
|
||||
// OnChallenge = context => Task.CompletedTask
|
||||
// };
|
||||
|
||||
options.Authority = builder.Configuration.GetConnectionString("Authentication:PocketId:Authority");
|
||||
options.Authority = builder.Configuration["Authentication:PocketId:Authority"];
|
||||
options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
|
||||
{
|
||||
// ValidAudiences = builder.Configuration.GetSection("Authentication:PocketId:Audiences").Get<string[]>(),
|
||||
ValidIssuers = builder.Configuration.GetSection("Authentication:PocketId:Authority").Get<string[]>()
|
||||
ValidAudiences = builder.Configuration["Authentication:PocketId:ClientId"].Split(';').Select(i => i.Trim()).ToArray(),
|
||||
ValidIssuers = builder.Configuration["Authentication:PocketId:Authority"].Split(';').Select(i => i.Trim()).ToArray()
|
||||
};
|
||||
});
|
||||
|
||||
@@ -65,19 +65,19 @@ namespace Api
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
|
||||
app.Use(async (context, next) =>
|
||||
{
|
||||
if (context.Request.Method == HttpMethods.Options)
|
||||
{
|
||||
context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
|
||||
context.Response.Headers.Add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
||||
context.Response.Headers.Add("Access-Control-Allow-Headers", "Content-Type");
|
||||
context.Response.StatusCode = StatusCodes.Status204NoContent;
|
||||
return;
|
||||
}
|
||||
// app.Use(async (context, next) =>
|
||||
// {
|
||||
// if (context.Request.Method == HttpMethods.Options)
|
||||
// {
|
||||
// context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
|
||||
// context.Response.Headers.Add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
||||
// context.Response.Headers.Add("Access-Control-Allow-Headers", "Content-Type");
|
||||
// context.Response.StatusCode = StatusCodes.Status204NoContent;
|
||||
// return;
|
||||
// }
|
||||
|
||||
await next();
|
||||
});
|
||||
// await next();
|
||||
// });
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
@@ -14,5 +14,5 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "http://localhost:4200"
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Reference in New Issue
Block a user