I am having an issue with my jwt authentication.
I am trying to get a list of templates from my rest api, but when I try to access the header 'Authorization', the value is null. Here is my code:
loadTemplates(): Observable<Template[]> {
const headers = new Headers({'Authorization': this.authService.getPrefix() + this.authService.getLocalToken()})
return this.httpService.post(this.baseURL + 'api/templates/short', {headers: headers})
.map((res: Response) => res.json())
.catch((error: any) => Observable.throw(error.json().error));
}
The Prefix and also the Token is set, I can see them when I log them in the console.
The probem is, when I look in the developer console in Chrome, I can see the Access-Control-Request-Headers: authorization
But it is null in the backend. (Tried to log the value of the header 'Authorization')
When I try to access the backend via Postman it does work. With the same prefix + token.
My guess is, that you forgot to handle so called 'preflight' request on the server side. Try to add something like this this filter .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.