Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
[webportal] Redirect to the source page after login. (#3914)
Browse files Browse the repository at this point in the history
  • Loading branch information
ydye authored and ydye committed Nov 29, 2019
1 parent 9c9039c commit 07372af
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/rest-server/src/controllers/v2/azureAD.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ const requestAuthCode = async (req, res, next) => {
if (authnConfig.groupConfig.groupDataSource === 'ms-graph') {
scope = `${scope} https://${authnConfig.OIDCConfig.msgraph_host}/directory.read.all`;
}
let state = 'http://' + process.env.WEBPORTAL_URL + '/index.html';
let state = {};
state.redirect = 'http://' + process.env.WEBPORTAL_URL + '/index.html';
if (req.query.redirect_uri) {
state = decodeURIComponent(req.query.redirect_uri);
state.redirect = req.query.redirect_uri;
}
if (req.query.from) {
state.from = req.query.from;
}
const requestURL = authnConfig.OIDCConfig.authorization_endpoint;
return res.redirect(`${requestURL}?`+ querystring.stringify({
Expand All @@ -43,7 +47,7 @@ const requestAuthCode = async (req, res, next) => {
redirect_uri: redirectUri,
response_mode: responseMode,
scope: scope,
state: state,
state: JSON.stringify(state),
}));
};

Expand Down Expand Up @@ -74,7 +78,9 @@ const requestTokenWithCode = async (req, res, next) => {
req.accessToken = jwt.decode(response.data.access_token);
req.undecodedRefreshToken = response.data.refresh_token;
req.refreshToken = jwt.decode(response.data.refresh_token);
req.returnBackURI = req.body.state;
const state = JSON.parse(req.body.state);
req.returnBackURI = state.redirect;
req.fromURI = state.from;
next();
} catch (error) {
return next(createError.unknown(error));
Expand Down
2 changes: 2 additions & 0 deletions src/rest-server/src/controllers/v2/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ const getAAD = async (req, res, next) => {
const userInfo = await userModel.getUser(username);
const admin = await userModel.checkAdmin(username);
const token = await tokenModel.create(username);
const fromURI = req.fromURI;
return res.redirect(req.returnBackURI + '?'+ querystring.stringify({
user: userInfo.username,
token: token,
admin: admin,
hasGitHubPAT: userInfo.extension.githubPAT,
from: fromURI,
}));
} catch (error) {
return next(createError.unknown(error));
Expand Down
2 changes: 1 addition & 1 deletion src/webportal/src/app/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const Index = () => {
config.restServerUri +
`/api/v1/authn/oidc/login?${querystring.stringify({
redirect_uri: new URL('/index.html', window.location.href).href,
callback: window.location.href,
from: new URL(loginTarget, window.location.href).href,
})}`;
}
}, []);
Expand Down

0 comments on commit 07372af

Please sign in to comment.