Not able to use Login Service using http Post

1
0
-1

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);

});

}

2 answers

1
+1
-1
This one is the BEST answer!

<p>Thank you for your answer.</p>

<p>I was able to solve my problem.My Modified code is as follows</p>

<p>&nbsp;</p>

<p>&nbsp;private _loginUrl = 'http://localhost:8080/bonita/loginservice';<br />
&nbsp; constructor(private http: HttpClient, private cookie: CookieService){<br />
&nbsp; }<br />
&nbsp; private body = new HttpParams()<br />
&nbsp; &nbsp; .set('username', 'walter.bates')<br />
&nbsp; &nbsp; .set('password', 'bpm');</p>

<p>&nbsp;loginUser(){<br />
&nbsp;return this.http.post(this._loginUrl,this.body.toString(),{ headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')})<br />
&nbsp; .subscribe(res=&gt;{<br />
&nbsp; })<br />
&nbsp; }</p>

1
0
-1

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
Notifications