-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a9d827d
Showing
5 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lib | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |