-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathverifyCredentials.js
More file actions
31 lines (26 loc) · 876 Bytes
/
verifyCredentials.js
File metadata and controls
31 lines (26 loc) · 876 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
25
26
27
28
29
30
31
const MagentoClient = require('./lib/petstoreClient');
/**
* Executes the verification logic by sending a simple to the
* Petstore API using the provided apiKey.
* If the request succeeds, we can assume that the apiKey is valid. Otherwise it is not valid.
*
* @param credentials object to retrieve apiKey from
*
* @returns boolean of whether or not the request was successful
*/
module.exports = async function verify(credentials) {
const { apiKey } = credentials;
if (!apiKey) throw new Error('API key is missing');
const client = new MagentoClient(this, credentials);
try {
// sending a request to the most simple endpoint of the target API
await client.makeRequest({
url: '/user/me',
method: 'GET',
});
// if the request succeeds, we can assume the api key is valid
return true;
} catch (e) {
return false;
}
};