forked from auth0/node-auth0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DXEX-273: Consistent method signatures (#5)
* Made getAll hooks consistent. * Made get single hook signature consistent. * Made update hook signature consistent. * Made update method signature consistent. * Add sample test script. * Rename package to original name and bumped version.
- Loading branch information
1 parent
39d51d9
commit 8cca40b
Showing
3 changed files
with
191 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
const ManagementClient = require('./src/index').ManagementClient; | ||
|
||
process.env.WEBTASK_API_TOKEN = '<webtask_api>'; | ||
process.env.WEBTASK_API_URL = 'https://sandbox8-us.it.auth0.com'; | ||
|
||
var management = new ManagementClient({ | ||
token: '<management api token>', | ||
domain: '<some_domain>' | ||
}); | ||
|
||
const hook_temlate = `/** | ||
@param {object} client - information about the client | ||
@param {string} client.name - name of client | ||
@param {string} client.id - client id | ||
@param {string} client.tenant - Auth0 tenant name | ||
@param {object} client.metadata - client metadata | ||
@param {array|undefined} scope - array of strings representing the scope claim or undefined | ||
@param {string} audience - token's audience claim | ||
@param {object} context - additional authorization context | ||
@param {object} context.webtask - webtask context | ||
@param {function} cb - function (error, accessTokenClaims) | ||
*/ | ||
module.exports = function(client, scope, audience, context, cb) { | ||
var access_token = {}; | ||
access_token.scope = scope; | ||
// Modify scopes or add extra claims | ||
// access_token['https://example.com/claim'] = 'bar'; | ||
// access_token.scope.push('extra'); | ||
cb(null, access_token); | ||
}; | ||
`; | ||
function createHook() { | ||
management.hooks | ||
.create({ | ||
triggerId: 'post-user-registration', | ||
name: 'post-user-reg', // Also testing that kebab casing works | ||
active: true, | ||
code: hook_temlate, | ||
secrets: { | ||
'api-key': 'my custom api key' | ||
}, | ||
dependencies: { | ||
bcrypt: '3.0.6' | ||
} | ||
}) | ||
.then(hook => { | ||
console.log('hook created'); | ||
console.log(hook); | ||
return updateHook(hook.id, hook); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
}); | ||
} | ||
function updateHook(id, hook) { | ||
hook.name = 'new name'; | ||
return management.hooks | ||
.update({ id }, hook) | ||
.then(hook => { | ||
console.log('hook updated'); | ||
console.log(hook); | ||
return getHook(hook.id); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
}); | ||
} | ||
|
||
function getHook(id) { | ||
return management.hooks | ||
.get({ id }) | ||
.then(hook => { | ||
console.log('hook retreived'); | ||
console.log(hook); | ||
return deleteHook(hook.id); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
}); | ||
} | ||
function deleteHook(id) { | ||
console.log('deleting hook'); | ||
return management.hooks | ||
.delete({ id }) | ||
.then(() => { | ||
console.log('hook deleted'); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
}); | ||
} | ||
|
||
function getAllHooks() { | ||
return management.hooks | ||
.getAll({}) | ||
.then(hook => { | ||
console.log('hook retreived'); | ||
console.log(hook); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
}); | ||
} | ||
|
||
createHook(); | ||
//getAllHooks(); |