Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ecwyne committed Aug 29, 2016
0 parents commit a9d827d
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib
node_modules
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# AuthJet
Dead simple SMS user verification. For more details and to sign up, go to [AuthJet.com](https://authjet.com).

## Installation
```bash
npm install --save authjet
```

## API
```javascript
const AuthJet = require('authjet');
const authjet = AuthJet('USERNAME', 'PASSWORD');

// check if login credentials are valid
authjet.checkAuth()
.then(({authenticated}) => {
// your logic here
});

// get the balance of your account
authjet.balance()
.then(({messagesPaid, messagesSent, messagesAvail}) => {
// your logic here
});


const recipient = '19498675309'; // 10 digit phone number with preceeding "1"
const appId = 'aHc9s'; // unique ID found in your account

// send code to recipient (https://authjet.com/docs/send)
authjet.send(appId, recipient)
.then(({code, expires}) => {
// your logic here
});

// validate challenge code (https://authjet.com/docs/validate)
const challenge = '8865';
authjet.validate(recipient, challenge)
.then(({valid, reason}) => {
//your logic here
});
```
35 changes: 35 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "authjet",
"version": "1.0.0",
"description": "Painless SMS user authentication with AuthJet",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"compile": "babel --presets es2015 -d lib/ src/",
"prepublish": "npm run compile"
},
"repository": {
"type": "git",
"url": "git+https://github.com/AuthJet/authjet-node.git"
},
"keywords": [
"authjet",
"tfa",
"authentication",
"sms",
"otp"
],
"author": "Eric Wyne <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/AuthJet/authjet-node/issues"
},
"homepage": "https://github.com/AuthJet/authjet-node#readme",
"dependencies": {
"bluebird": "^3.4.3"
},
"devDependencies": {
"babel-cli": "^6.14.0",
"babel-preset-es2015": "^6.14.0"
}
}
55 changes: 55 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const https = require('https');
const url = require('url');
const bluebird = require('bluebird');

function API(username, password){
if (!(this instanceof API)){
return new API(username, password);
}
this.baseUrl = `https://${username}:${password}@authjet.com`;

this.checkAuth()
.then(({authenticated}) => {
if (!authenticated){
console.log(`${username} is NOT properly authenticated to AuthJet\nPlease check your username and password.`);
}
})
.error(err => console.log('Error authenticating to AuthJet\n', err));
}

const request = (href, cb) => {
let out = '';
const req = https.get(url.parse(href), res => {
res.on('data', data => out += data);
});
req.on('close', () => {
try {
return cb(null, JSON.parse(out));
} catch (e){
return cb(null, out);
}
});
req.on('error', cb);
};

API.prototype.send = bluebird.promisify(function(appId, recipient, cb){
const sendUrl = `${this.baseUrl}/api/send?appId=${appId}&recipient=${recipient}`;
return request(sendUrl, cb);
});

API.prototype.validate = bluebird.promisify(function(recipient, code, cb){
const sendUrl = `${this.baseUrl}/api/validate?code=${code}&recipient=${recipient}`;
return request(sendUrl, cb);
});

API.prototype.checkAuth = bluebird.promisify(function(cb){
const sendUrl = `${this.baseUrl}/api/check-auth`;
return request(sendUrl, cb);
});

API.prototype.balance = bluebird.promisify(function(cb){
const sendUrl = `${this.baseUrl}/api/balance`;
return request(sendUrl, cb);
});

module.exports = API;

0 comments on commit a9d827d

Please sign in to comment.