-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (36 loc) · 1.04 KB
/
index.js
File metadata and controls
37 lines (36 loc) · 1.04 KB
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
function status(response) {
if (response.status >= 200 && response.status < 300) {
return Promise.resolve(response)
} else {
return Promise.reject(new Error(response.statusText))
}
}
module.exports.templateTags = [{
name: 'brauzie',
displayName: 'Brauzie JWT',
description: 'JWT obtained by brauzie as ENV Var for use in Bearer Authorization',
args: [
{
displayName: 'jwt',
description: 'Where to obtain the jwt obtained by brauzie',
type: 'string',
defaultValue: 'http://localhost:8000/jwt.json'
},
{
displayName: 'prop',
description: 'Most likely `access_token`',
type: 'string',
defaultValue: 'access_token'
},
],
async run(context, jwt, prop) {
const token = await fetch(jwt, {cache: "reload"})
.then(status)
.then(response => response.json().then(data => data[ prop ])
)
.catch(function () {
throw new Error(`Bad response from ${jwt}. A static server is expected to expose brauzies jwt here`)
});
return token;
}
}];