bonita token

the generation of token doesn't work properly

Hello merikawasselin,

Can you clarify your question?

Hello Saidi,  thanks for your reply,

  i try an API rest with postman, when i authenticate, it works fine,  the token is generated, but when i use with another client like angular, the token is not generated

Can you share your Angular code to reproduce the issue? Thanks.

import { Injectable } from '@angular/core';

import { HttpClient, HttpHeaders } from '@angular/common/http';




 

const endpoint  = 'http://localhost:80/bonita/loginservice';

const httpOptions = {

  headers: new HttpHeaders({

      // 'Content-Type':  'application/json',

      'Content-Type':  'application/x-www-form-urlencoded',

      'Access-Control-Allow-Origin':'*',

      // 'X-Bonita-API-Token':''

    })

  };



 

@Injectable({

  providedIn: 'root'

})

export class LoginService {

 

  constructor(private http: HttpClient) { }

 

  login(username,password)

  {

    const data = {

      username  : username,

      password  : password,

      };

 

      console.log("************",data);

 

      return this.http.post<any>(endpoint,data,httpOptions);

  }


 

}

 

I Think the problem is not from my client; but from the API itself

sometimes it works and generates the x-bonita-token, and after it doesn't work anymore

Can you share the HTTP request that failed from your Angular application to Bonita server as an HAR file? Can you also share the Bonita Engine log file? I never faced such issue when the login API alternatively works and failed.

{
“log”: {
“version”: “1.2”,
“creator”: {
“name”: “WebInspector”,
“version”: “537.36”
},
“pages”: ,
“entries”: [
{
“startedDateTime”: “2019-12-19T11:13:05.883Z”,
“time”: 30.05999999850243,
“request”: {
“method”: “OPTIONS”,
“url”: “http://localhost/bonita/loginservice”,
“httpVersion”: “HTTP/1.1”,
“headers”: [
{
“name”: “Host”,
“value”: “localhost”
},
{
“name”: “Connection”,
“value”: “keep-alive”
},
{
“name”: “Access-Control-Request-Method”,
“value”: “POST”
},
{
“name”: “Origin”,
“value”: “http://localhost:4200
},
{
“name”: “User-Agent”,
“value”: “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36”
},
{
“name”: “Access-Control-Request-Headers”,
“value”: “access-control-allow-origin”
},
{
“name”: “Accept”,
“value”: “/
},
{
“name”: “Sec-Fetch-Site”,
“value”: “same-site”
},
{
“name”: “Sec-Fetch-Mode”,
“value”: “cors”
},
{
“name”: “Referer”,
“value”: “http://localhost:4200/
},
{
“name”: “Accept-Encoding”,
“value”: “gzip, deflate, br”
},
{
“name”: “Accept-Language”,
“value”: “fr,en-US;q=0.9,en;q=0.8”
}
],
“queryString”: ,
“cookies”: ,
“headersSize”: 510,
“bodySize”: 0
},
“response”: {
“status”: 200,
“statusText”: “”,
“httpVersion”: “HTTP/1.1”,
“headers”: [
{
“name”: “Cache-Control”,
“value”: “no-store, no-cache, must-revalidate, proxy-revalidate”
},
{
“name”: “Allow”,
“value”: “GET, HEAD, POST, OPTIONS”
},
{
“name”: “Content-Length”,
“value”: “0”
},
{
“name”: “Date”,
“value”: “Thu, 19 Dec 2019 11:13:05 GMT”
}
],
“cookies”: ,
“content”: {
“size”: 0,
“mimeType”: “text/plain”,
“compression”: -1,
“text”: “”
},
“redirectURL”: “”,
“headersSize”: 175,
“bodySize”: 1,
“_transferSize”: 176
},
“cache”: {},
“timings”: {
“blocked”: 7.186999987944961,
“dns”: 0.018000000000000016,
“ssl”: -1,
“connect”: 1.9340000000000002,
“send”: 0.2639999999999998,
“wait”: 20.10299998307973,
“receive”: 0.5540000274777412,
“_blocked_queueing”: 6.755999987944961
},
“serverIPAddress”: “[::1]”,
“_initiator”: {
“type”: “script”,
“stack”: {
“callFrames”: [
{
“functionName”: “scheduleTask”,
“scriptId”: “25”,
“url”: “http://localhost:4200/polyfills.js”,
“lineNumber”: 6186,
“columnNumber”: 23
},
{
“functionName”: “scheduleTask”,
“scriptId”: “25”,
“url”: “http://localhost:4200/polyfills.js”,
“lineNumber”: 3612,
“columnNumber”: 25
},
{
“functionName”: “onScheduleTask”,
“scriptId”: “25”,
“url”: “http://localhost:4200/polyfills.js”,
“lineNumber”: 3506,
“columnNumber”: 64
},
{
“functionName”: “scheduleTask”,
“scriptId”: “25”,
“url”: “http://localhost:4200/polyfills.js”,
“lineNumber”: 3606,
“columnNumber”: 50
},
{
“functionName”: “scheduleTask”,
“scriptId”: “25”,
“url”: “http://localhost:4200/polyfills.js”,
“lineNumber”: 3445,
“columnNumber”: 42
},
{
“functionName”: “scheduleMacroTask”,
“scriptId”: “25”,
“url”: “http://localhost:4200/polyfills.js”,
“lineNumber”: 3468,
“columnNumber”: 24
},
{
“functionName”: “scheduleMacroTaskWithCurrentZone”,
“scriptId”: “25”,
“url”: “http://localhost:4200/polyfills.js”,
“lineNumber”: 4341,
“columnNumber”: 24
},
{
“functionName”: “”,
“scriptId”: “25”,
“url”: “http://localhost:4200/polyfills.js”,
“lineNumber”: 6219,
“columnNumber”: 29
},
{
“functionName”: “proto.”,
“scriptId”: “25”,
“url”: “http://localhost:4200/polyfills.js”,
“lineNumber”: 4662,
“columnNumber”: 23
},
{
“functionName”: “”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 10267,
“columnNumber”: 16
},
{
“functionName”: “_trySubscribe”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 95511,
“columnNumber”: 24
},
{
“functionName”: “subscribe”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 95497,
“columnNumber”: 21
},
{
“functionName”: “”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 105407,
“columnNumber”: 30
},
{
“functionName”: “subscribeToResult”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 105563,
“columnNumber”: 83
},
{
“functionName”: “_innerSub”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 101010,
“columnNumber”: 89
},
{
“functionName”: “_tryNext”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 101004,
“columnNumber”: 13
},
{
“functionName”: “_next”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 100987,
“columnNumber”: 17
},
{
“functionName”: “next”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 96055,
“columnNumber”: 17
},
{
“functionName”: “”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 98026,
“columnNumber”: 19
},
{
“functionName”: “_trySubscribe”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 95511,
“columnNumber”: 24
},
{
“functionName”: “subscribe”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 95497,
“columnNumber”: 21
},
{
“functionName”: “call”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 100972,
“columnNumber”: 22
},
{
“functionName”: “subscribe”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 95492,
“columnNumber”: 30
},
{
“functionName”: “call”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 100277,
“columnNumber”: 22
},
{
“functionName”: “subscribe”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 95492,
“columnNumber”: 30
},
{
“functionName”: “call”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 100765,
“columnNumber”: 22
},
{
“functionName”: “subscribe”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 95492,
“columnNumber”: 30
},
{
“functionName”: “login”,
“scriptId”: “24”,
“url”: “http://localhost:4200/main.js”,
“lineNumber”: 558,
“columnNumber”: 52
},
{
“functionName”: “eval”,
“scriptId”: “37”,
“url”: “ng:///AppModule/LoginComponent.ngfactory.js”,
“lineNumber”: 21,
“columnNumber”: 30
},
{
“functionName”: “handleEvent”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 77276,
“columnNumber”: 121
},
{
“functionName”: “callWithDebugContext”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 78895,
“columnNumber”: 26
},
{
“functionName”: “debugHandleEvent”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 78530,
“columnNumber”: 11
},
{
“functionName”: “dispatchEvent”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 64363,
“columnNumber”: 24
},
{
“functionName”: “”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 76208,
“columnNumber”: 15
},
{
“functionName”: “”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 81954,
“columnNumber”: 37
},
{
“functionName”: “invokeTask”,
“scriptId”: “25”,
“url”: “http://localhost:4200/polyfills.js”,
“lineNumber”: 3625,
“columnNumber”: 30
},
{
“functionName”: “onInvokeTask”,
“scriptId”: “26”,
“url”: “http://localhost:4200/vendor.js”,
“lineNumber”: 73279,
“columnNumber”: 32
},
{
“functionName”: “invokeTask”,
“scriptId”: “25”,
“url”: “http://localhost:4200/polyfills.js”,
“lineNumber”: 3624,
“columnNumber”: 59
},
{
“functionName”: “runTask”,
“scriptId”: “25”,
“url”: “http://localhost:4200/polyfills.js”,
“lineNumber”: 3402,
“columnNumber”: 46
},
{
“functionName”: “invokeTask”,
“scriptId”: “25”,
“url”: “http://localhost:4200/polyfills.js”,
“lineNumber”: 3699,
“columnNumber”: 33
},
{
“functionName”: “invokeTask”,
“scriptId”: “25”,
“url”: “http://localhost:4200/polyfills.js”,
“lineNumber”: 4837,
“columnNumber”: 13
},
{
“functionName”: “globalZoneAwareCallback”,
“scriptId”: “25”,
“url”: “http://localhost:4200/polyfills.js”,
“lineNumber”: 4863,
“columnNumber”: 16
}
]
}
},
“_priority”: “High”,
“_resourceType”: “xhr”,
“connection”: “1582”
}
]
}
}

this is the content of har file

The HTTP request method from the HAR you shared is OPTIONS whereas it should be a POST according to https://documentation.bonitasoft.com/bonita/7.10/rest-api-overview

That might explain why login is failing.

ok; thank you for your replay, i ll check it, and I'd like to take this opportunity to ask you if we can figure out the next possible tasks for a case. 

As this is a different topic, please ask another question. Doing so helps to get the forum easy to browse and read. Thanks.