I have successfully integrated JWT login into my Angular app with ASP.NET Core 2.0 back-end. Now, I am facing an issue when trying to fetch data for resources requiring authorization via JWT, following a tutorial. The HTTP get works fine in Postman using the token, but in my Angular app I receive a 401 error.
The server API call is defined within the SampleDataController class:
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[Route("api/[controller]")]
public class SampleDataController : Controller
{
// Code for WeatherForecasts method here...
}
My Angular component code looks like this:
// Angular code for FetchDataComponent here...
interface WeatherForecast {
dateFormatted: string;
temperatureC: number;
temperatureF: number;
summary: string;
}
Additionally, below is the code snippet responsible for adding the authorization header:
// TokenInterceptor class implementation here...
Any assistance on resolving the authorization issue would be greatly appreciated.