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

Store the URL that the user has come from in the redirect_uri query param #1

Merged
merged 1 commit into from
Apr 23, 2020
Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ To run locally, run `npm run start-dev`. Make sure you have the following enviro

AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
LOGIN_URL
VAULT_FRONTEND_URL
LOGGING_URL
JWT_SECRET

Things to ensure:
- That the JWT secret is the same as the one used in the original backend
- The login url doesn't have to be the precise URL, it can just be vault.gov.sg, which will then trigger another redirect
- logging_url is to note down all the actions done by the user

To deploy, run `npm run build` and manually deploy the zip file to the appropriate env


Original readme follows:

# [![Firefox Send](./assets/icon.svg)](https://send.firefox.com/) Firefox Send

[![CircleCI](https://img.shields.io/circleci/project/github/mozilla/send.svg)](https://circleci.com/gh/mozilla/send)
Expand Down
4 changes: 3 additions & 1 deletion app/ui/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class Header extends Component {
: html`
<a
class="flex flex-row items-center"
href="${this.state.loginUrl || DEFAULTS.LOGIN_URL || '/'}"
href="${this.state.vaultFrontendUrl ||
window.DEFAULTS.VAULT_FRONTEND_URL ||
'/'}"
>
<img
alt="${this.state.translate('title')}"
Expand Down
2 changes: 1 addition & 1 deletion server/clientConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ module.exports = {
DOWNLOAD_COUNTS: config.download_counts,
EXPIRE_TIMES_SECONDS: config.expire_times_seconds,
EXPIRE_SECONDS: config.default_expire_seconds,
LOGIN_URL: config.login_url
VAULT_FRONTEND_URL: config.vault_frontend_url
}
};
6 changes: 3 additions & 3 deletions server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const path = require('path');
const { randomBytes } = require('crypto');

const conf = convict({
login_url: {
vault_frontend_url: {
format: String,
default: 'http://localhost:8082',
env: 'LOGIN_URL'
default: 'http://localhost:1443',
env: 'VAULT_FRONTEND_URL'
},
s3_bucket: {
format: String,
Expand Down
9 changes: 7 additions & 2 deletions server/middleware/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,22 @@ module.exports = {
return next();
},
vault: async function(req, res, next) {
const redirect_uri = `${
config.vault_frontend_url
}/login?redirect_uri=${encodeURIComponent(
req.protocol + '://' + req.get('host') + req.originalUrl
)}`;
const token = req.cookies.authtoken;
if (!token) {
console.log('cookie has no authtoken');
return res.redirect(config.login_url);
return res.redirect(redirect_uri);
}
try {
jwt.verify(token, config.jwt_secret, { algorithms: ['HS256'] });
return next();
} catch (err) {
console.log('Failed jwt verification:', token);
return res.redirect(config.login_url);
return res.redirect(redirect_uri);
}
}
};
2 changes: 1 addition & 1 deletion server/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = async function(req) {
description:
'Encrypt and send files with a link that automatically expires to ensure your important documents don’t stay on our servers forever.',
baseUrl: config.base_url,
loginUrl: config.login_url,
vaultFrontendUrl: config.vault_frontend_url,
ui: {},
storage: {
files: []
Expand Down