Skip to content
This repository has been archived by the owner on Nov 7, 2020. It is now read-only.

add request destination handling for identity login button. #450

Open
wants to merge 1 commit into
base: master
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
13 changes: 12 additions & 1 deletion lib/unhangout-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,20 @@ module.exports = {
});
});

// Middleware to store a destination path.
// If the special _destination query parameter is found, its value
// will be stored in the session.
var requestPathMiddleware = function(req, res, next) {
if (!_.isUndefined(req.query._destination)) {
logger.debug("setting login destination", req.query._destination);
req.session["post-auth-path"] = req.query._destination;
}
next();
}

// the passport middleware (passport.authenticate) should route this request to
// google, and not call the rendering callback below.
app.get("/auth/google", passport.authenticate('google', {
app.get("/auth/google", requestPathMiddleware, passport.authenticate('google', {
scope: [
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email']
Expand Down
12 changes: 12 additions & 0 deletions lib/unhangout-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var logging = require('./logging'),
RedisStore = require('connect-redis')(express),
http = require('http'),
https = require('https'),
querystring = require("querystring"),
nodemailer = require("nodemailer");
passport = require('passport'),
GoogleStrategy = require('passport-google-oauth').OAuth2Strategy,
Expand Down Expand Up @@ -110,6 +111,17 @@ exports.UnhangoutServer.prototype = {
monotonic: monotonic,
NODE_ENV: process.env.NODE_ENV
}
// Exposes URL-encoded _destination query parameter.
// If it is included in the link to the /auth/google/
// path, the user will be redirected to its value.
this.app.use(function(req, res, next) {
var queryParamString = querystring.stringify(req.query);
var queryObj = {
_destination: req.path + '?' + queryParamString,
}
res.locals.requestDestination = querystring.stringify(queryObj);
next();
});

// Much less repetitive to include these here, both for consistency
// and because _header.ejs will only have access to these and
Expand Down
2 changes: 1 addition & 1 deletion views/_identity.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<ul class="navbar-nav nav navbar-right identity">
<li>
<% if(!user) {%>
<a href="/auth/google" class="login-link"><button class="btn btn-primary login-button">Login</button></a>
<a href="/auth/google?<%= requestDestination %>" class="login-link"><button class="btn btn-primary login-button">Login</button></a>
<% } else { %>
<div class="dropdown">
<a class="dropdown-toggle username" data-toggle="dropdown" id='user-menu-label'>
Expand Down