0.1.6 • Published 9 years ago

api-key-validator v0.1.6

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

API Key Validator   image of lock

Codeship Status for VennHQ/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-validator

Validate (serviceName, keys, callback)

serviceNamekeys
"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 install

Run Examples

node example.js

Run Tests

mocha

Adding a New Service Provider

  1. Write Failing Tests
  2. If new service type, create a new test file of the form test/service_type.js.
  3. Copy test/test_template.js into the newly created file or the file corresponding to the service type of the new provider.
  4. Follow instructions in the template file to create tests for the new service
  5. Create the New Service Provider
  6. Install the service provider's npm package as a dependency, or hit their rest API through npm request package
  7. Create a new file of the form lib/models/services/service_type /provider_name.js
  8. 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.
  9. 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.
  10. Edit lib/index.js
  11. Require the newly created service provider
    var ServiceName = require('./providers/service_type/service_name');
  12. Add the newly created service provider to apiKeyValidator
    		if (service == "service_name") Service_name.validate(keys);