Nodejs: Authentification with Jazz RTC failed
I'm trying to sign in with jazz rtc api but I always get
Acually I'm converting a java project to Nodejs. On java the authentification works great with this:
Now in Nodejs I'm trying this:
These two pieces of code seems to do the same thing but only the java one works. |
3 answers
Ralph Schoon (63.1k●3●36●45)
| answered Nov 30 '18, 10:23 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER You should ask questions like this on stackoverflow. This is a programming question and does not have anything to do with the tools as far as I know.
Your nodeJS does at least not properly encode the URL and data. See the Java code:
|
Were you able to solve this issue? I am having the same problem with node js, I am able to login using curl commands , but nodejs is getting authentication fail
Comments
Amadou Beye
commented Oct 13 '20, 4:32 p.m.
Hi Leonardo,
please check my new answer. I solve it
|
I finally found a solution:
let identityOptions = {
url: rtcHost + '/authenticated/identity',
jar: request.jar()
}
const authentificationOptions = {
form = formurlencoded({ j_username: login, j_password: password }, 'utf8'),
followAllRedirects: true, // for FORM based authentication
strictSSL: false,
url: rtcHost + '/jts/j_security_check',
jar: request.jar(),
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
'X-Requested-With': 'XMLHttpRequest'
}
};
return new Promise(function (resolve, reject) {
request.post(identityOptions, function (error, response, body) {
// User is authenticated, then return OK
if (body && JSON.stringify(body).includes(login)) return resolve(200);
// User should authenticate
request.post(authentificationOptions, function (error, response, body) {
if (body && JSON.stringify(body).includes(login.toUpperCase())) {
return resolve(200);
}
return reject(response ? response.statusCode : 400);
});
});
});
|