Hi guys, I'm trying to do the login from angular 8 to bonita rest api, but I have un unknow error
this is the code
login (bonitaLoginRequest: IBonitaLoginRequest) {
console.log("login service")
let header = new HttpHeaders()
.append('Accept', '*/*')
.append('Content-Type', 'application/x-www-form-urlencoded')
.append('Access-Control-Allow-Origin', '*')
.append('Set-Cookie', 'SameSite=None')
console.log("start call ", JSON.stringify(bonitaLoginRequest))
this.httpClient.post("http://localhost:44896/bonita/loginservice", JSON.stringify(bonitaLoginRequest), {headers: header}).map(res => console.log("res " , res)).subscribe(
data => {
console.log(data);
},
err => {
console.log("ERROR!: ", err);
}
);
console.log("end call")
}
in the bontaLoginRequest there are only username and password
this is the error:
- status: 0
- statusText: "Unknown Error"
- url: "http://localhost:44896/bonita/loginservice"
- ok: false
- name: "HttpErrorResponse"
- message: "Http failure response for http://localhost:44896/bonita/loginservice: 0 Unknown Error"
Hi,
I am not used to angular 8 so may be I am missing something but where is your login information (username & password)?
May be this AngularJs example can help you:
this.action = function doLogin() {
var req = {
method: 'POST',
url: loginUrl,
data: angular.copy($scope.properties.login),
transformRequest: function(obj) {
var str = [];
for(var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
},
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
};
return $http(req)
.success(function(data, status) {
...
})
.error(function(data, status) {
...
})
.finally(function() {
...
});
}
Also, to make it work, you need to change the cors configuration provided in the bonitra documentation.
( I will update it as soon as possible)
so you need to change:
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>*</param-value>
</init-param>
by replacing the " * " by the origins you want to authorized. without this, the credentials cannot be automatically passed.
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSNotSupportingCredentials
hope this helps,
Julien.
Hello,
first did you enabled cors for your Bonita server? (see https://documentation.bonitasoft.com/bonita/7.10/enable-cors-in-tomcat-bundle)
then, did you try to make the same call using an API Client like "Postman",
to see if you get more information about the error?
or if it work, and maybe we could have a look at the possible issue in your code?
Hi, I tried to enable cors in tomcat bundle but the error is always the CORS,
from postman it works perfectly
hello, i disable cors security in chrome with a cmd command and now it works