No SHA-256 token in the nodejs implementation
arshmakker opened this issue · 4 comments
Hi,
I am trying to connect via nodejs application to kiteconnect.
In the Kite Connect API documentation, the request parameters are as follows:
Parameter | |
---|---|
api_key | The public API key |
request_token | The one-time token obtained after the login flow |
checksum | SHA-256 hash of (api_key + request_token + api_secret) |
Where as in the nodejs version:
kc.requestAccessToken("request_token", "api_secret")
.then(function(response) {
init();
})
.catch(function(err) {
console.log(err.response);
})
The function requestAccessToken does not have the third parameter.
Could you please check if this is by design or a bug?
If it is by design, please do show a working example on how to connect via nodejs(server side).
REgards
Arshdeep
The third param is implicitly set because we already have everything to compute the checksum.
ok, understood.
So how does the nodejs obtain the request_token? via the loginAPI? or does the object KiteConnect already has the request_token?
The documentation does not show what all is included int he response for KC.
the method, requestAccessToken, uses the secret and request-token and obtains the access-token, sets itselfs by invoking self.setAccessToken. Refer to https://github.com/rainmattertech/kiteconnectjs/blob/master/lib/index.js, line 175-190
self.requestAccessToken = function(request_token, secret) {
var checksum = crypto.createHash("sha256")
.update(self.options.api_key + request_token + secret)
.digest("hex");
var p = _post("api.validate", {
"request_token": request_token,
"checksum": checksum
});
p.then(function(response) {
self.setAccessToken(response.data.access_token);
}).catch(function(err) {})
return p;
};
As @sivamgr mentioned requestAccessToken
function takes request_token
and api_secret
as params and when you initialize the KiteConnect
you provide api_key
so we have everything to compute the checksum which is abstracted in requestAccessToken
function.