steves / node-jira

A nodejs wrapper for the JIRA REST API
378 stars 169 forks source link

request options should be supported instead of oauth, username, password, & proxy constructor parameters #152

Open llecaroz opened 5 years ago

llecaroz commented 5 years ago

Hi, I am playing with you class & you might not defnitly play with proxy, username, passwords, & others authentication scenarios. Instead of that you should accept a requestOptions parameter in the constructor, allowing the caller to set request options independently/whatever the login scenario to be added (the same for username/password)

For example, by that way, the caller can add extra header request parameters like proxy authentication or whatever.

As example of code from the caller (here the last parameter is the options map you give @ the request method. In that example, I connect to an authenticated proxy & sigin also in jira:

var username = 'username';
var password = 'password';

JiraApi = require('./jira.js').JiraApi;

const HttpProxyAgent = require("http-proxy-agent");
var jira = new JiraApi('https', 'hostname', 443, '2', true, false, null,{
       "agent": new HttpProxyAgent('http://proxyserver'),
        headers: {
            "Proxy-Authorization": 'Bearer myproxycredentialtoken'
            "Authorization": 'Basic ' + Buffer.from(username + ':' + password).toString('base64')
        }
    });
console.log(jira.searchUsers(username, 0, 50, false, false, function(error, string) { console.log(error) }));

Next you will have to concatenate/transfer that map into your own options This will really make your class more opened, extensible & easier to maintain on that point for you. Best regards Louis