Not able to use Login Service using http Post
Hi community
I am using the below code. But I am getting 401 error.
Please help me to understand what is going wrong.
Also getting CORS error , but my angular app is running in localhost:4200 and bonita is running in localhost:8080.
ngOnInit() {
const headers = { 'Content-Type': 'application/x-www-form-urlencoded' };
const body = { username: 'walter.bates',password: 'bpm', redirect: false };
this.http.post('http://localhost:8080/bonita/loginservice', body, { headers })
.subscribe(data => {
alert(data);
});
}
<p>Thank you for your answer.</p>
<p>I was able to solve my problem.My Modified code is as follows</p>
<p> </p>
<p> private _loginUrl = 'http://localhost:8080/bonita/loginservice';<br />
constructor(private http: HttpClient, private cookie: CookieService){<br />
}<br />
private body = new HttpParams()<br />
.set('username', 'walter.bates')<br />
.set('password', 'bpm');</p>
<p> loginUser(){<br />
return this.http.post(this._loginUrl,this.body.toString(),{ headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')})<br />
.subscribe(res=>{<br />
})<br />
}</p>
Hello,
I am not using angular, so can't help with that. But it looks fine. You get an unauthorized error which is strange.
Are you using the default installation especially for the users ? You get that error when the credentials are wrong.
Hereunder is my test with a default installation under Linux (which works as expected). I took the log with wireshark
curl -v -c saved_cookies.txt -X POST --url 'http://localhost:8080/bonita/loginservice' --header 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' -O /dev/null -d 'username=walter.bates&password=bpm'
POST /bonita/loginservice HTTP/1.1 Host: localhost:8080 User-Agent: curl/7.68.0 Accept: */* Content-Type: application/x-www-form-urlencoded; charset=utf-8 Content-Length: 34 username=walter.bates&password=bpm HTTP/1.1 204 Set-Cookie: bonita.tenant=1; SameSite=Lax Set-Cookie: JSESSIONID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX; Path=/; HttpOnly; SameSite=Lax Set-Cookie: X-Bonita-API-Token=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx; Path=/; SameSite=Lax Set-Cookie: BOS_Locale=en; Path=/; SameSite=Lax Date: Mon, 10 Jan 2022 19:45:46 GMT