t2p-clientlib
v1.0.6
Published
Generate header token for request client token for using api service
Downloads
127
Readme
How to use library
T2P Authen Client Lib
How to Generate Toke Type H to use for Host to Host request
//# Example
const t2plib = require('t2p-clientlib');
const fs = require('fs')
try {
//###file client.key contains base64Ecode of Key that is provided to partner
const clientKey = fs.readFileSync('client.key', 'utf8')
//### Generate for using to request to get token Type C only (use by client mobile request header)
var token = t2plib.preapare("requestbodydata",clientKey)
console.log("<<tokenType H>>")
console.log(token)
console.log("\n")
//### Generate for use with specific API URI only (use by Host to Host request header)
var token = t2plib.preapare("requestbodydata",clientKey, '/wallet/some/api/function/')
console.log("<<tokenType H>>")
console.log(token)
console.log("\n")
//### Generate for use with any API (use by Host to Host request header)
var token = t2plib.preapare("requestbodydata",clientKey, '')
console.log("<<tokenType H>>")
console.log(token)
console.log("\n")
/*
// OUTPUT
{
header: 'ZXlKamJHbGxiblJEYjJSbElqb2lRMHhKTVRBd01EQXpJaXdpYTJWNVEyOWtaU0k2SWt0RE1UQXdNREF5TUNJc0luUnBiV1Z6ZEdGdGNDSTZJakl3TWpFd056STBNVGMxTXpJNElpd2lZMnhwWlc1MFRHbGlWbVZ5YzJsdmJpSTZJakV1TUM0d0lpd2lkRzlyWlc1VWVYQmxJam9pU0NJc0luVnlhU0k2SWk5aGRYUm9aVzR2ZGpFdlkyeHBaVzUwVkc5clpXNHZaMlZ1WlhKaGRHVWlMQ0p0WlhSb2IyUWlPaUpRVDFOVUluMD06ZmE5YmJlMGQ1MmMzZDlhODVlMTM5YTEzYmRmZDM5YWJjMGM3ZThiNmY3MmVmZjdhNjQ4MzcwMjMyZmY3ZWE4NDQyOTZmOTNmMDNjZWY1ZTZiZmJlYWE0YTBmMTkwMzM3ZGUzOTMzNGUyZmRhNTNiZTFjNzUxNTZlYjJhZDcxZTk=',
body: 'E94FXKbgTzpyRzFbT5vilXRN9VxvGYrk2m8MlY6FEn1fpSGdEUAY5tgn5EYrK34wVIa2mMN/Uyfle80lozjK1ojyMDmdTRnTFasgvA1Ibj4RPOYc6AI3CvfEQ6guwl7SZQCM4/DoF/ltCO0aZuAkeM1X04xzv7TeZCVN0zRLE/cyd/OZJb31jKVr5uhJ3WE9zkpkCmhQokAnfjReHhWbXfDSmJknSXEst2BIeM1TDCnMQBnB1hp6pwFAw6+68APn6+qki2Pet+9EYJwSIWUAIQ0ITLSyViUTtpk5UBYY/IiFVQYZpHwDwksPdfsoGvIWSAjVsJYjkwJgRY3fE8I7eQ==:KCcLTzjBIDRkt47oJhuhug=='
}
*/
} catch (err) {
console.error(err)
}
How to request for token type C for using on client (Mobile/Web)
1. on the server generate token type H for host to host with fix uri input (/authen/v1/clientToken/generate) of the request token
2. use token that recieve post to request token to url : https://test-api-authen.t2p.co.th/authen/v1/clientToken/generate
(Prod : https://api-authen.t2p.co.th/authen/v1/clientToken/generate )
Decrypt the response from Host to Host request
const t2plib = require('t2p-clientlib');
const fs = require('fs')
try {
//file client.key contains base64Ecode of Key that is provided to partner
const clientKey = fs.readFileSync('client.key', 'utf8')
//Make Request to service then get the response as in API document
decryptedText = t2plib.decryptData(encryptedText, clientKey)
} catch (err) {
console.error(err)
}
Verify HashMac of input data using ClientKey
const t2plib = require('t2p-clientlib');
const fs = require('fs')
try {
//file client.key contains base64Ecode of Key that is provided to partner
const clientKey = fs.readFileSync('client.key', 'utf8')
#hashMac of input data
var hash = '2819f93a1c5ba61028ba3fc01a50b3131e96795e6cb88c552759f4f001a66ee10583f63830774743d4d314d883fcebd2f59ffc6e78361807a0e3c0bfbf693464'
var inputData = "somedata"
var hashVerify = t2plib.verifyHashMac(inputData, hash, clientKey)
console.log(hashVerify)
} catch (err) {
console.error(err)
}
Generate HashMac of input data using ClientKey
const t2plib = require('t2p-clientlib');
const fs = require('fs')
try {
//file client.key contains base64Ecode of Key that is provided to partner
const clientKey = fs.readFileSync('client.key', 'utf8')
#hashMac of input data
var inputData = "somedata"
var hash = t2plib.generateHashMac(inputData, clientKey)
console.log(hash)
} catch (err) {
console.error(err)
}