Skip to content

Commit 06784fb

Browse files
committed
first commit
0 parents  commit 06784fb

File tree

12 files changed

+953
-0
lines changed

12 files changed

+953
-0
lines changed

.firebaserc.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"projects": {
3+
"default": "PROJECT_ID"
4+
}
5+
}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.env
2+
node_modules
3+
private.key
4+
.firebaserc

README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Multifactor Security Authentication Using Vonage APIs and Firebase Services
2+
3+
## Overview
4+
5+
This project is a web application demonstrating how to strengthen multifactor security authentication using the Vonage SIM Swap API and Verify v2 API, integrated with Firebase Hosting, Functions, and Firestore. The application includes a simple bank dashboard and a login form. If the SIM Swap API detects that a phone number was swapped recently, the verification code will not be sent, and additional security measures will be applied. A verification code will be sent via the Verify v2 API to authenticate the user if no recent swap is detected.
6+
7+
## Features
8+
9+
- A login form to enter and verify a phone number
10+
- Secure multifactor authentication using Vonage Verify v2
11+
- SIM Swap detection to prevent compromised logins
12+
- Simple bank dashboard after successful login
13+
- Firebase Hosting for serving the application
14+
- Firebase Functions for server-side logic
15+
- Firestore for storing user data and verification status
16+
17+
## Prerequisites
18+
19+
- A [Vonage Developer Account](https://developer.vonage.com).
20+
- A Firebase project set up in the [Firebase Console](https://console.firebase.google.com).
21+
- Node.js and npm installed.
22+
23+
## Getting Started
24+
25+
1. Clone the repository and change directories
26+
```bash
27+
git clone https://github.com/Vonage-Community/demo-sim-swap_verifyv2-javascript-multifactor_authentication-firebase.git
28+
cd https://github.com/Vonage-Community/demo-sim-swap_verifyv2-javascript-multifactor_authentication-firebase.git
29+
```
30+
2. Install the required packages:
31+
```bash
32+
npm install
33+
```
34+
35+
3. Move the `.env.example` file to `.env` file in the project root and include the following environment variables:
36+
```bash
37+
mv .env.example .env
38+
```
39+
```bash
40+
VONAGE_APPLICATION_ID=your_application_id
41+
VONAGE_APPLICATION_PRIVATE_KEY_PATH=/path/to/your/private.key
42+
JWT=your_jwt_token
43+
```
44+
45+
4. You have the choice to set these variables:
46+
```bash
47+
MAX_AGE=your_max_age
48+
RECIPIENT_NUMBER=your_recipient_number
49+
```
50+
51+
5. Set up Firebase:
52+
- Install Firebase CLI:
53+
```bash
54+
npm install -g firebase-tools
55+
```
56+
- Log in to Firebase:
57+
```bash
58+
firebase login
59+
```
60+
- Initialize Firebase in your project:
61+
```bash
62+
firebase init
63+
```
64+
Select `Hosting`, `Functions`, and `Firestore` when prompted.
65+
66+
6. Deploy Firebase Functions and Hosting:
67+
```bash
68+
firebase deploy
69+
```
70+
71+
7. Run the application locally:
72+
```bash
73+
firebase emulators:start
74+
```
75+
76+
8. Launch your web browser and enter the URL:
77+
```bash
78+
http://localhost:5000/
79+
```
80+
81+
## How It Works
82+
83+
### SIM Swap API
84+
85+
The application uses the Vonage SIM Swap API to check whether a given phone number has been swapped in the last few days. This protects users from attacks that exploit SIM swaps.
86+
87+
### Verify v2 API
88+
89+
The Verify v2 API sends a one-time code to the user's phone number for authentication. This verification code will be sent if the SIM Swap API determines that the number has not been recently swapped.
90+
91+
### Firebase Integration
92+
93+
- **Firebase Hosting:** Serves the web application.
94+
- **Firebase Functions:** Handles the server-side logic for verifying the SIM swap and sending verification codes.
95+
- **Firestore:** Stores user data and verification status, ensuring that passwords and other sensitive information are securely managed.
96+
97+
### Application Flow
98+
99+
1. The user enters their phone number on the login page.
100+
2. The SIM Swap API checks whether the number was swapped recently.
101+
3. A verification code is sent via the Verify v2 API if no swap is detected.
102+
4. After successful verification, the user can access the bank dashboard.
103+
104+
This setup provides a robust and scalable architecture, combining Vonage's security APIs with Firebase's comprehensive backend services.

firebase.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"hosting": {
3+
"public": "public",
4+
"ignore": [
5+
"firebase.json",
6+
"**/.*",
7+
"**/node_modules/**"
8+
],
9+
"rewrites": [
10+
{
11+
"source": "/sendcode",
12+
"function": "sendCode"
13+
},
14+
{
15+
"source": "/simswap",
16+
"function": "simSwap"
17+
},
18+
{
19+
"source": "/verify",
20+
"function": "verify"
21+
},
22+
{
23+
"source": "/update",
24+
"function": "update"
25+
},
26+
{
27+
"source": "/login",
28+
"function": "login"
29+
},
30+
{
31+
"source": "/main",
32+
"destination": "/main.html"
33+
},
34+
{
35+
"source": "**",
36+
"destination": "/index.html"
37+
}
38+
]
39+
},
40+
"functions": {
41+
"runtime": "nodejs18",
42+
"source": "functions"
43+
},
44+
"emulators": {
45+
"functions": {
46+
"port": 5001
47+
},
48+
"firestore": {
49+
"port": 8080
50+
},
51+
"hosting": {
52+
"port": 5000
53+
},
54+
"ui": {
55+
"enabled": true
56+
},
57+
"singleProjectMode": true
58+
}
59+
}

functions/.env.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
VONAGE_API_SECRET=your_api_secret
2+
VONAGE_APPLICATION_ID=your_application_id
3+
VONAGE_APPLICATION_PRIVATE_KEY=/path/to/your/private.key
4+
BRAND_NAME=your_brand_name
5+
FROM_NUMBER=your_sender_number
6+
MSISDN=your_phone_number_for_sim_swap_check
7+
JWT=your_jwt_token
8+
MAX_AGE=72

functions/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
.env
3+
node_modules
4+
private.key

0 commit comments

Comments
 (0)