Skip to content

Commit aecde8f

Browse files
committed
Add basic auth to sessions route
1 parent 66e1aa8 commit aecde8f

File tree

5 files changed

+2058
-14
lines changed

5 files changed

+2058
-14
lines changed

.env.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ CALL_ANNOUCEMENT_VOICE=
55
CALL_ANNOUCEMENT_LANGUAGE=
66
OUT_OF_SESSION_MESSAGE_FOR_CALL=
77
CONNECTING_CALL_ANNOUCEMENT=
8-
DOMAIN=
8+
DOMAIN=
9+
AUTH_USERNAME=
10+
AUTH_PASSWORD=

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ This application supports masking communicaitons between SMS, WhatsApp, and voic
2424
7. Start your npm server
2525
> npm start
2626
27+
# Authorization
28+
This app protects API calls to /sessions with basic auth. You can set your basic auth username and password in the .env file.
29+
2730
# Using
2831
This application provides an endpoint to create a conversation for participants to communicate and a landing page to simplify getting started.
2932

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"cors": "^2.8.5",
66
"dotenv": "^16.0.1",
77
"express": "^4.18.1",
8+
"express-basic-auth": "^1.2.1",
89
"http-errors": "^2.0.0",
910
"morgan": "^1.10.0",
1011
"twilio": "^3.78.0"

src/routes/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import { Router } from "express";
22
import * as controllers from "../controllers";
3+
import basicAuth from 'express-basic-auth'
4+
5+
const { AUTH_USERNAME, AUTH_PASSWORD } = process.env
36

47
const router = Router();
58

69
router.post("/conversations-post-event", controllers.conversationsPostEvent.post);
710

811
router.post("/inbound-call", controllers.inboundCall.post);
9-
router.get("/join-conference", controllers.joinConference.get)
12+
router.post("/join-conference", controllers.joinConference.get)
1013

11-
router.post("/sessions", controllers.session.post);
14+
router.post("/sessions", basicAuth({
15+
users: { [AUTH_USERNAME]:AUTH_PASSWORD}
16+
}), controllers.session.post);
1217

1318
export default router;

0 commit comments

Comments
 (0)