When getting the access_token from the mpesa API using nodejs, you run code like below
var request = require('request'),
consumer_key = "YOUR_APP_CONSUMER_KEY",
consumer_secret = "YOUR_APP_CONSUMER_SECRET",
url = "https://sandbox.safaricom.co.ke/oauth/v1/generate?grant_type=client_credentials"
auth = "Basic " + new Buffer(consumer_key + ":" + consumer_secret).toString("base64");
request(
{
url : url,
headers : {
"Authorization" : auth
}
},
function (error, response, body) {
// TODO: Use the body object to extract OAuth access token
}
)
The Buffer method that is used to generate the auth value used during Authorization is deprecated in Node. What's the alternative?