forked from auth0/node-auth0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sample.js
108 lines (100 loc) · 2.61 KB
/
test.sample.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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();