-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
Please accept this modest contribution to make your library support Promise format.
This is what I add after the lib import to be able to use it in async/await
const duo_api = require('@duosecurity/duo_api')
duo_api.Client.prototype.asyncApiCall = async function(method, path, params) {
return new Promise( (resolve, reject)=>{
try {
this.jsonApiCall(method, path, params, resolve)
} catch (error) {
resolve({
stat: 'ERROR',
message: error.message ? error.message : error
})
}
})
}
duo_api.Client.prototype.get = async function (path, params) {
return this.asyncApiCall('GET', path, params)
}
duo_api.Client.prototype.post = async function (path, params) {
return this.asyncApiCall('POST', path, params)
}That can then be used nicely as follow
const request = new duo_api.Client(integrationKey, secretKey, duoHost);
const auth = await request.post('/auth/v2/auth', {
user_id: user_id,
factor: 'push',
async: true,
device: 'auto',
type: 'Test'
})
console.log('AUTH:', auth)
const status = await request.get('/auth/v2/auth_status', {txid: auth.response.txid})
console.log('STATUS:', auth)odedpeer, CalebAlbers, driverjb, joecullin and soonoo
Metadata
Metadata
Assignees
Labels
No labels