I encountered a 401 unauthorized error when trying to access my REST endpoint, likely due to the security measures I have implemented. I suspect that there might be an issue with how I am handling the HTTP headers.
The application utilizes a Spring Boot backend REST API, which I know functions correctly. This is evident because when I obtain a token using Postman and then use that same authorization token in Postman to interact with the API, everything works smoothly.
getWeatherByCityAndCountry(city: string, country: string): Promise<Weather> {
let headers = new HttpHeaders();
headers = headers.append('Authorization', 'Bearer '+ this.accessToken);
return this.http.get(this.baseUrl + '/byCity/' + city + '/' + country, {headers: headers})
.toPromise()
.then(response => response as Weather)
.catch(this.handleError)
}
The accessToken has been hardcoded with a token value obtained from Postman.