Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uniquenterprice #14

Open
wants to merge 16 commits into
base: revert-3-enhancement/phone-verification-authy-client
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ This app uses MongoDB as a data store. You may have to install that as well and
- SMS or Voice Call

### Setup
- NOTE: This demo works for MongoDB v3.6+
- If you're having issues, its probably related to the above.
- Clone this repo
- Run `npm install`
- Register for a [Twilio Account](https://www.twilio.com/).
Expand Down
2 changes: 2 additions & 0 deletions demo.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
SET SIMPLE_DEMO_PORT=1337
SET DEMO_AUTHY_API_KEY='ADD_YOUR_KEY_HERE'
SET DEMO_TWILIO_ACCOUNT_SID=''
SET DEMO_TWILIO_AUTH_TOKEN=''
2 changes: 2 additions & 0 deletions demo.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export SIMPLE_DEMO_PORT=1337
export DEMO_AUTHY_API_KEY='ADD_YOUR_KEY_HERE'
export DEMO_TWILIO_ACCOUNT_SID=''
export DEMO_TWILIO_AUTH_TOKEN=''
38 changes: 22 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
require('./server/model/user_model.js');

var express = require('express');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var expressSession = require('express-session');
var mongoStore = require('connect-mongo')({session: expressSession});
var mongoose = require('mongoose');
const express = require('express');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const expressSession = require('express-session');
const mongoStore = require('connect-mongo')({session: expressSession});
const mongoose = require('mongoose');

var config = require('./server/config.js');

var app = express();
var server = require('http').Server(app);
var io = require('socket.io')(server);
const config = require('./server/config.js');

const app = express();
const server = require('http').Server(app);

if(!config.API_KEY){
console.log("Please set your DEMO_AUTHY_API_KEY environment variable before proceeding.");
Expand All @@ -23,8 +21,12 @@ if(!config.API_KEY){
/**
* Setup MongoDB connection.
*/
mongoose.connect('mongodb://localhost:27017/authydemo');
var db = mongoose.connection;
mongoose.connect('mongodb://localhost:27017/authydemo').then(function(){
console.log(" Connected to Authy Demo ");
}).catch(err => console.error(err));


const db = mongoose.connection;

app.use(cookieParser());
app.use(expressSession({'secret': config.SECRET}));
Expand All @@ -50,16 +52,16 @@ db.once('open', function (err) {
collection: 'sessions'
})
}));
var port = config.PORT || 5151;
const port = config.PORT || 5151;
server.listen(port);
console.log("Magic happening on port " + port);
});

db.on('error', console.error.bind(console, 'Connection Error:'));

var router = express.Router();
const router = express.Router();

var users = require('./server/controllers/users.js');
const users = require('./server/controllers/users.js');

router.route('/user/register').post(users.register);

Expand All @@ -83,6 +85,10 @@ router.route('/loggedIn').post(users.loggedIn);
router.route('/verification/start').post(users.requestPhoneVerification);
router.route('/verification/verify').post(users.verifyPhoneToken);

/**
* Lookups
*/
router.route('/lookup').post(users.lookupNumber);

/**
* Require user to be logged in and authenticated with 2FA
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Simple demo showing how Authy works.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"repository": {
"type": "git",
Expand All @@ -19,19 +20,17 @@
"author": "Josh Staples",
"license": "ISC",
"dependencies": {
"authy-client": "^1.0.7",
"authy": "^1.3.0",
"body-parser": "^1.15.2",
"connect-mongo": "^1.3.2",
"cookie-parser": "^1.4.3",
"crypto": "0.0.3",
"express": "^4.14.0",
"express-session": "^1.14.1",
"mongodb": "^2.2.11",
"mongoose": "^4.6.5",
"mongodb": "^3.0.2",
"mongoose": "^5.0.2",
"nodemon": "^1.11.0",
"qs": "^6.3.0",
"request": "^2.76.0",
"socket-io": "0.0.0",
"socket.io": "^1.5.1"
"request": "^2.83.0"
}
}
4 changes: 2 additions & 2 deletions public/2fa/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>2FA - Super Simple Authy Demo</title>
<title>2FA - Super Simple Account Security Demo</title>
<link rel="icon" type="image/png" href="/assets/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="/assets/favicon-16x16.png" sizes="16x16">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
Expand Down
61 changes: 56 additions & 5 deletions public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,29 @@ app.controller('LoginController', function ($scope, $http, $window) {
app.controller('RegistrationController', function ($scope, $http, $window) {

$scope.setup = {};
$scope.info = false;
$scope.disabledRegister = true;

$scope.lookup = function () {
$http.post('/api/lookup', $scope.setup)
.success(function (data, status, headers, config) {
console.log("Success Lookup: ", data);
$scope.info = data.info.carrier;
if ($scope.info.type === "mobile") {
$scope.disabledRegister = false;
alert("Lookup has determined you are registering a mobile phone number.");
} else {
$scope.disabledRegister = true;
alert("You must register with a mobile number only.");
}
})
.error(function (data, status, headers, config) {
console.error("Failure Lookup: ", data);
});
};

$scope.register = function () {
if ($scope.password1 === $scope.password2) {
if ($scope.password1 === $scope.password2 && $scope.password1 !== "") {

// making sure the passwords are the same and setting it on the
// object we'll pass to the registration endpoint.
Expand Down Expand Up @@ -125,11 +145,11 @@ app.controller('AuthyController', function ($scope, $http, $window, $interval) {
/**
* Request the OneTouch status.
*/
function oneTouchStatus() {
function oneTouchStatus () {
$http.post('/api/authy/onetouchstatus')
.success(function (data, status, headers, config) {
console.log("OneTouch Status: ", data);
if (data.body.approval_request.status === "approved") {
if (data.approval_request.status === "approved") {
$window.location.href = $window.location.origin + "/protected";
$interval.cancel(pollingID);
} else {
Expand All @@ -147,13 +167,40 @@ app.controller('AuthyController', function ($scope, $http, $window, $interval) {
app.controller('PhoneVerificationController', function ($scope, $http, $window, $timeout) {

$scope.setup = {
via: "sms"
via: "sms",
locale: "en"
};

$scope.view = {
start: true
};

$scope.info = false;
$scope.disabled = true;

$scope.lookup = function () {
$scope.info = false;
$http.post('/api/lookup', $scope.setup)
.success(function (data, status, headers, config) {
console.log("Success Lookup: ", data);
$scope.info = data.info.carrier;
if ($scope.info.type === "mobile") {
$scope.disabled = false;
alert("Lookup has determined you are registering a mobile phone number.");
} else if ($scope.info.type === "landline") {
$scope.disabled = false;
$scope.setup.via = "call";
alert("Lookup has determined you are registering with a landline.");
} else {
$scope.disabled = true;
alert("You must register with a mobile or landline number only. No VOIP.");
}
})
.error(function (data, status, headers, config) {
console.error("Failure Lookup: ", data);
});
};

/**
* Initialize Phone Verification
*/
Expand Down Expand Up @@ -182,5 +229,9 @@ app.controller('PhoneVerificationController', function ($scope, $http, $window,
alert("Error verifying the token. Check console for details.");
});
};

$scope.logout = function () {
$window.location.href = $window.location.origin;
};
});

8 changes: 4 additions & 4 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Super Simple Authy Demo</title>
<title>Twilio Account Security Demo</title>
<!--Made by an engineer for engineers-->
<link rel="icon" type="image/png" href="/assets/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="/assets/favicon-16x16.png" sizes="16x16">
Expand All @@ -11,7 +11,7 @@
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
Expand All @@ -30,7 +30,7 @@
<div class="col-xs-12 col-sm-8 col-md-4 col-sm-offset-2 col-md-offset-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Authy Demos</h3>
<h3 class="panel-title">Account Security Demo</h3>
</div>
<div class="panel-body">
<div class="row">
Expand Down Expand Up @@ -67,4 +67,4 @@ <h3 class="panel-title">Authy Demos</h3>
</div>
</div>
</body>
</html>
</html>
5 changes: 2 additions & 3 deletions public/login/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login - Super Simple Authy Demo</title>
<title>Login - Super Simple Account Security Demo</title>
<!--Made by an engineer for engineers-->
<link rel="icon" type="image/png" href="/assets/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="/assets/favicon-16x16.png" sizes="16x16">
Expand All @@ -11,8 +11,7 @@
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
Expand Down
4 changes: 2 additions & 2 deletions public/protected/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Protected Content - Super Simple Authy Demo</title>
<title>Protected Content - Super Simple Account Security Demo</title>
<!--Made by an engineer for engineers-->
<link rel="icon" type="image/png" href="/assets/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="/assets/favicon-16x16.png" sizes="16x16">
Expand All @@ -11,7 +11,7 @@
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
Expand Down
20 changes: 15 additions & 5 deletions public/register/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Register User - Super Simple Authy Demo</title>
<title>Register User - Super Simple Account Security Demo</title>
<!--Made by an engineer for engineers-->
<link rel="icon" type="image/png" href="/assets/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="/assets/favicon-16x16.png" sizes="16x16">
Expand All @@ -11,7 +11,7 @@
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
Expand All @@ -31,7 +31,7 @@
<div class="col-xs-12 col-sm-8 col-md-4 col-sm-offset-2 col-md-offset-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Authy Demo Registration</h3>
<h3 class="panel-title">Account Security Demo Registration</h3>
</div>
<div class="panel-body">
<form role="form">
Expand Down Expand Up @@ -88,9 +88,19 @@ <h3 class="panel-title">Authy Demo Registration</h3>
</div>
</div>
</div>

<input type="submit" value="Register" ng-click="register()" class="btn btn-info btn-block">
<div class="row" ng-show="info !== false">
<div class="col-xs-12 col-sm-12 col-md-12">
<h5>Lookup Information</h5>
<pre>
{{info | json}}
</pre>
<p>Lookup allows you to determine if a user is signing up with a mobile number. You may want to prevent users from registering with a landline or VOIP number.</p>
</div>
</div>
<input type="submit" value="Lookup" ng-click="lookup()" class="btn btn-info btn-block">
<input type="submit" ng-disabled="disabledRegister" value="Register" ng-click="register()" class="btn btn-info btn-block">
<small style="float: right;"><a href="/login">Login</a></small>

</form>
</div>
</div>
Expand Down
Loading
Loading