Skip to content

Commit

Permalink
feat(auth): check tha name of the app on the social authenticating
Browse files Browse the repository at this point in the history
  • Loading branch information
shoudaos committed Jun 11, 2019
1 parent 20c1a6b commit 03424c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
secret_key: "HUEyqESqgQ1yTwzVlO6wprC9Kf1J1xuA",
host: process.env.HOST || "http://localhost",
port: process.env.NODE_ENV === "production" ? "" : "8080",
hostUI: process.env.NODE_ENV === "production" ? "https://demo.flatlogic.com/sing-app-react" : "http://localhost",
hostUI: process.env.NODE_ENV === "production" ? "https://demo.flatlogic.com" : "http://localhost",
portUI: process.env.NODE_ENV === "production" ? "" : "3000",
google: {
clientId: "592707349093-3ab6a0seutt1qpiiq8u0k3in5k7f226d.apps.googleusercontent.com",
Expand Down
12 changes: 8 additions & 4 deletions src/routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,25 @@ router.post('/signin/local', (req, res) => {
});


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

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

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

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

Expand Down

0 comments on commit 03424c1

Please sign in to comment.