When I’m making a REST call from my NodeJS Server it’s always making it with the addon user and not with the user logged. Also, I’m trying to make REST calls with the httpClient.asUser('admin') to force if the user of the REST call is correct.
The request context that I’m sending to addon.httpClient it’s like that:
{ http:
HostClient {
addon:
EventEmitter {
app: [Object],
logger: [Object],
config: [Object],
settings: [Object],
schema: [Object],
descriptor: [Object],
key: 'XXXXX',
name: 'XXXXX',
_: [Object],
RSVP: [Object],
_jwt: [Object],
shouldRegister: [Function],
shouldDeregister: [Function],
register: [Function],
deregister: [Function],
watcher: [Object],
_registrations: {} },
context: 'admin',
clientKey: 'XXX',
oauth2: OAuth2 { addon: [Object] } },
title: 'XXXXX',
addonKey: 'XXXXX',
userId: 'admin',
clientKey: 'XXX',
token: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
license: 'none',
timeZone: 'Europe/Madrid',
locale: 'en-US',
localBaseUrl: 'https://XXXXX.ngrok.io',
hostBaseUrl: 'https://davidcloud.atlassian.net',
hostUrl: 'https:',
hostStylesheetUrl: 'https://davidcloud.atlassian.net/atlassian-connect/all-debug.css',
hostScriptUrl: 'https://davidcloud.atlassian.net/atlassian-connect/all-debug.js' }
And the call:
var httpClient = addon.httpClient(req);
httpClient.asUser('admin').get('/rest/api/2/myself', function (err, res, body) {
console.log('err',err); //TODO remove
console.log('body',body); //TODO remove
})
The response of the last example always is
{ error: 'invalid_grant',
error_description: 'The token is expired' }
Anyone has an example of REST authenticate calls from NodeJS in backend?
Any help is very appreciated. Thanks.