-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthentication.js
57 lines (45 loc) · 1.24 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
52
53
54
55
56
57
"use strict";
const { API_BASE_URL } = require("./constants");
const test = (z, bundle) =>
z.request({ url: `${API_BASE_URL}/game/3030-19929` });
const handleBadResponses = (response, z, bundle) => {
if (response.status === 401) {
throw new z.errors.Error(
// This message is surfaced to the user
"The API Key you supplied is incorrect",
"AuthenticationError",
response.status
);
}
return response;
};
const includeApiKey = (request, z, bundle) => {
if (bundle.authData.apiKey) {
// Use these lines to include the API key in the querystring
request.params = request.params || {};
request.params.api_key = bundle.authData.apiKey;
}
return request;
};
const specifyFormat = (request, z, bundle) => {
request.params = request.params || {};
request.params.format = "json";
return request;
};
module.exports = {
config: {
type: "custom",
fields: [
{
key: "apiKey",
label: "Giant Bomb API Key",
required: true,
helpText: "Find your API key here: https://www.giantbomb.com/api/",
},
],
test,
connectionLabel: (z, bundle) => bundle.authData.apiKey,
},
befores: [includeApiKey, specifyFormat],
afters: [handleBadResponses],
};