Authenticating url on server side

Hi @hariprasath.

I saw your posts here and here.

In your server side code (router), to have your calls authenticated with jwt, if you’re using ACE, what I do is have the addon.authenticate() as part of the dependency as such:

If you’re using your add-on user to invoke REST APIs:

app.get('/hello-world', addon.authenticate(), function (req, res) {
    let httpClient = addon.httpClient(req);

    httpClient.get({
                url: `rest/api/<version>/<endpoint>`,
                contentType: 'application/json',
                json: true
            }, (error, res, body) => {
                //do something about the body
            });
});

If you’re acting as a user:

httpClient.asUser('admin').get({
                url: `rest/api/<version>/<endpoint>`,
                contentType: 'application/json',
                json: true
            }, (error, res, body) => {
                //do something about the body
            });

Cheers,
Anne Calantog

1 Like