0.1.6 • Published 10 years ago
api-key-validator v0.1.6
API Key Validator 
Validate api keys for major email, sms, or push notification providers quickly and easily. Catch the problem early.
Installation
npm install api-key-validatorValidate (serviceName, keys, callback)
| serviceName | keys |
|---|---|
| "mailgun" | {api_key, domain} |
| "mandrill" | {api_key} |
| "postmark" | {server_key} |
| "sendgrid" | {api_user, api_key} |
| "nexmo" | {api_key, api_secret} |
| "plivo" | {auth_id, auth_token} |
| "sinch" | {application_key, application_secret} |
| "twilio" | {account_sid, auth_token} |
| "onesignal" | {app_id, api_key} |
| "parse" | {app_id, api_key} |
| "pushbots" | {app_id} |
| "zeropush" | {server_token} |
Example
var apiKeyValidator = require('api-key-validator');
var keys = {
api_user: "cx34554cvd234sdfsd34fsdf123123",
api_key: "2342334534fbdf29sdfsbfbdfsd4"
}
apiKeyValidator.validate("sendgrid", keys, function(err, result){
console.log(err, result);
});Development
Want to add a service not currently supported? Feel free to add it yourself and send a pull request!
Install Dependencies
npm installRun Examples
node example.jsRun Tests
mochaAdding a New Service Provider
- Write Failing Tests
- If new service type, create a new test file of the form
test/service_type.js. - Copy
test/test_template.jsinto the newly created file or the file corresponding to the service type of the new provider. - Follow instructions in the template file to create tests for the new service
- Create the New Service Provider
- Install the service provider's npm package as a dependency, or hit their rest API through npm request package
- Create a new file of the form
lib/models/services/service_type /provider_name.js - Decide how you want to test if the provided keys are valid. Refer to the service's api documentation to call a function or hit an end point that will authenticate or result in an error.
- Return a callback making sure that error is null and result is populated if the keys are verified and error is populated and result is null if they are not.
- Edit
lib/index.js - Require the newly created service provider
var ServiceName = require('./providers/service_type/service_name'); - Add the newly created service provider to
apiKeyValidatorif (service == "service_name") Service_name.validate(keys);