I am making um application using angular 5 as front-end and java with jersey as back-end. I have problem with the authentication when I try to consume from my front-end angular. This is code of client app angular:
const headers = {
'Content-Type': 'application/json',
'Authorization': this.auth.token
};
return this.http.get(this.url, { headers: headers, withCredentials: true })
.toPromise()
.then(this.extractData)
.catch(this.handleErrorPromise);
But looking for request generated I am not find the header 'authorization' in my server. There I receive just:
host:100.0.66.160:8092
connection:keep-alive
pragma:no-cache
cache-control:no-cache
access-control-request-method:GET
origin:http://localhost:4200
user-agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36
access-control-request-headers:authorization,content-type
accept:*/*
accept-encoding:gzip, deflate
accept-language:pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7
Then I don't find the "authorization" for validation, someone can say me what is wrong there?
Follow validation code in server-side:
String authorizationHeader = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION);
Autenticador autenticacao = new Autenticador();
String token;
extrairHeader(requestContext);
if (authorizationHeader != null && authorizationHeader.contains("Bearer ")) {
token = authorizationHeader.substring("Bearer ".length()).trim();
Key key = new KeyGenerator().generateKey();
return autenticacao.tokenValido(token, key);
} else {
return false;
}