Skip to content

Commit 03424c1

Browse files
committed
feat(auth): check tha name of the app on the social authenticating
1 parent 20c1a6b commit 03424c1

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
secret_key: "HUEyqESqgQ1yTwzVlO6wprC9Kf1J1xuA",
88
host: process.env.HOST || "http://localhost",
99
port: process.env.NODE_ENV === "production" ? "" : "8080",
10-
hostUI: process.env.NODE_ENV === "production" ? "https://demo.flatlogic.com/sing-app-react" : "http://localhost",
10+
hostUI: process.env.NODE_ENV === "production" ? "https://demo.flatlogic.com" : "http://localhost",
1111
portUI: process.env.NODE_ENV === "production" ? "" : "3000",
1212
google: {
1313
clientId: "592707349093-3ab6a0seutt1qpiiq8u0k3in5k7f226d.apps.googleusercontent.com",

src/routes/user.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,25 @@ router.post('/signin/local', (req, res) => {
5959
});
6060

6161

62-
router.get('/signin/google', passport.authenticate("google", {scope: ["profile", "email"]}));
62+
router.get('/signin/google', (req, res, next) => {
63+
passport.authenticate("google", {scope: ["profile", "email"], state: req.query.app})(req, res, next);
64+
});
6365

6466
router.get('/signin/google/callback', passport.authenticate("google", {failureRedirect: "/login", session: false}),
6567
function (req, res) {
6668
let token = req.user.token;
67-
res.redirect(config.hostUI + `${config.portUI ? `:${config.portUI}` : ``}` + "/#/login?token=" + token);
69+
res.redirect(config.hostUI + `${config.portUI ? `:${config.portUI}` : ``}` + `${req.query.state ? `/${req.query.state}` : ``}` + "/#/login?token=" + token);
6870
}
6971
);
7072

71-
router.get('/signin/microsoft', passport.authenticate("microsoft", {scope: ["https://graph.microsoft.com/user.read openid"]}));
73+
router.get('/signin/microsoft', (req, res, next) => {
74+
passport.authenticate("microsoft", {scope: ["https://graph.microsoft.com/user.read openid"], state: req.query.app})(req, res, next);
75+
});
7276

7377
router.get('/signin/microsoft/callback', passport.authenticate("microsoft", {failureRedirect: "/login", session: false}),
7478
function (req, res) {
7579
let token = req.user.token;
76-
res.redirect(config.hostUI + `${config.portUI ? `:${config.portUI}` : ``}` + "/#/login?token=" + token);
80+
res.redirect(config.hostUI + `${config.portUI ? `:${config.portUI}` : ``}` + `${req.query.state ? `/${req.query.state}` : ``}` + "/#/login?token=" + token);
7781
}
7882
);
7983

0 commit comments

Comments
 (0)