I'am trying to implement basic authorization in Angular 5. I'm using HttpClient and HttpHeaders. I'm trying to connect to a tomcat server with a REST service.
This code is in my login function.
this.storage.set('credentials', credentials);
return new Promise((resolve, reject) => {
let headers = new HttpHeaders();
//btoa permet d'encoder le username et le mot de passe en base64
headers = headers.append("Authorization", "Basic " + btoa(credentials.username + ':' + credentials.password));
headers = headers.append("Content-Type", "application/x-www-form-urlencoded");
//utilisation de stateless pour ne créer qu'une session http et ne pas créer une session par requete
this.http.post(apiUrl+'ADUser', JSON.stringify({l: credentials.username, p: credentials.password}),{ headers:headers })
.subscribe(res => {
resolve((res: Response) => res.json());
}, (err) => {
console.log(err);
reject();
let alert = this.alertCtrl.create({
title: 'L\'authentification a échoué',
subTitle: 'Le nom d\'utilisateur ou le mot de passe est incorrect',
buttons: ['OK']
});
alert.present();
});
});
This is from the Chrome tools Network tab
After looking on the forums and on this site, I have not found a solution to my problem. Could someone please help me with this problem ?
Thank you in advance for your response and the time spent helping me