forked from zapier/zapier-platform-example-app-basic-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthentication.js
More file actions
24 lines (21 loc) · 983 Bytes
/
authentication.js
File metadata and controls
24 lines (21 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const test = (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: 'http://httpbin.org/basic-auth/user/passwd',
}).then((response) => {
if (response.status === 401) {
throw new Error('The username and/or password you supplied is incorrect');
}
return response;
});
};
module.exports = {
type: 'basic',
// 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: test
};