-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthentication.js
53 lines (43 loc) · 1.7 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
"use strict";
const common = require("./common");
const testAuth = (z, bundle) => {
// Normally you want to make a request to an endpoint that is either specifically designed to
// test auth, or one that every user will have access to, such as an account or profile endpoint
// like /me. In this example, we"ll hit httpbin, which validates the Authorization Header
// against the arguments passed in the URL path
// This method can return any truthy value to indicate the credentials are valid.
// Raise an error to show
return z.request({
url: `${common.apiURL(bundle)}/orders?limit=1`,
}).then((response) => {
if(response.status === 401) {
throw new Error("The API Key you supplied is invalid. Please verify and try again.");
}
return response;
});
};
module.exports = {
type: "custom",
// Define any auth fields your app requires here. The user will be prompted to enter this info
// when they connect their account.
fields: [
{
key: "apiKey",
label: "API Key",
helpText: `You can find your API key on the [my settings](${common.baseURL()}/account/users/me) page under your name in the top right menu of Handshake Hub.`,
required: true,
type: "string",
}
],
// The test method allows Zapier to verify that the credentials a user provides are valid. We"ll
// execute this method whenver a user connects their account for the first time.
test: testAuth
};
// const authentication = {
// type: "basic",
// test: {
// url: "https://"
// },
// connectionLabel: "{{bundle.authData.username}}"
// };
//module.exports = authentication;