-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathauthentication.js
51 lines (46 loc) · 1.34 KB
/
authentication.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
'use strict';
const { getBaseUrl } = require('./utils');
const authentication = {
type: 'custom',
// Instead of a static object, we define test as a function so we can
// construct the URL based on the provided instance_url.
test: async (z, bundle) => {
const baseUrl = getBaseUrl(bundle);
const response = await z.request({
method: 'POST',
url: `${baseUrl}/api/auth.info`
});
try {
const data = JSON.parse(response.content);
return data;
} catch (error) {
throw new z.errors.Error(
'Failed to parse authentication response: ' + error.message,
'parse_error'
);
}
},
connectionLabel: (z, bundle) => {
// bundle.inputData contains the data returned from the .test request
const data = bundle.inputData.data;
return `${data.team.name} (${data.user.name})`;
},
fields: [
{
key: 'instance_url',
type: 'string',
required: false,
default: 'https://app.getoutline.com',
helpText:
'The URL for your Outline instance. Leave blank to use cloud hosted Outline (https://app.getoutline.com).'
},
{
key: 'api_token',
type: 'string',
required: true,
helpText:
'Go to "Settings -> API Keys" in your Outline workspace to create a new API key.'
}
]
};
module.exports = authentication;