Skip to content

Add parseFrameURL for masking user-facing pages #3267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jan 8, 2017
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ The client keys used with Parse are no longer necessary with Parse Server. If yo
* `revokeSessionOnPasswordReset` - When a user changes their password, either through the reset password email or while logged in, all sessions are revoked if this is true. Set to false if you don't want to revoke sessions.
* `accountLockout` - Lock account when a malicious user is attempting to determine an account password by trial and error.
* `passwordPolicy` - Optional password policy rules to enforce.
* `customPages` - A hash with urls to override email verification links, password reset links and specify frame url for masking user-facing pages. Available keys: `parseFrameURL`, `invalidLink`, `choosePassword`, `passwordResetSuccess`, `verifyEmailSuccess`.

##### Logging

Expand Down
59 changes: 59 additions & 0 deletions spec/UserController.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
var UserController = require('../src/Controllers/UserController').UserController;
var emailAdapter = require('./MockEmailAdapter')
var AppCache = require('../src/cache').AppCache;

describe('UserController', () => {
var user = {
_email_verify_token: 'testToken',
username: 'testUser',
email: '[email protected]'
}

describe('sendVerificationEmail', () => {
describe('parseFrameURL not provided', () => {
it('uses publicServerURL', (done) => {

AppCache.put(defaultConfiguration.appId, Object.assign({}, defaultConfiguration, {
publicServerURL: 'http://www.example.com',
customPages: {
parseFrameURL: undefined
}
}))

emailAdapter.sendVerificationEmail = (options) => {
expect(options.link).toEqual('http://www.example.com/apps/test/verify_email?token=testToken&username=testUser')
done()
}

var userController = new UserController(emailAdapter, 'test', {
verifyUserEmails: true
})

userController.sendVerificationEmail(user)
})
})

describe('parseFrameURL provided', () => {
it('uses parseFrameURL and includes the destination in the link parameter', (done) => {

AppCache.put(defaultConfiguration.appId, Object.assign({}, defaultConfiguration, {
publicServerURL: 'http://www.example.com',
customPages: {
parseFrameURL: 'http://someother.example.com/handle-parse-iframe'
}
}))

emailAdapter.sendVerificationEmail = (options) => {
expect(options.link).toEqual('http://someother.example.com/handle-parse-iframe?link=%2Fapps%2Ftest%2Fverify_email&token=testToken&username=testUser')
done()
}

var userController = new UserController(emailAdapter, 'test', {
verifyUserEmails: true
})

userController.sendVerificationEmail(user)
})
})
})
});
4 changes: 3 additions & 1 deletion spec/ValidationAndPasswordsReset.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ describe("Custom Pages, Email Verification, Password Reset", () => {
invalidLink: "myInvalidLink",
verifyEmailSuccess: "myVerifyEmailSuccess",
choosePassword: "myChoosePassword",
passwordResetSuccess: "myPasswordResetSuccess"
passwordResetSuccess: "myPasswordResetSuccess",
parseFrameURL: "http://example.com/handle-parse-iframe"
},
publicServerURL: "https://my.public.server.com/1"
})
Expand All @@ -22,6 +23,7 @@ describe("Custom Pages, Email Verification, Password Reset", () => {
expect(config.verifyEmailSuccessURL).toEqual("myVerifyEmailSuccess");
expect(config.choosePasswordURL).toEqual("myChoosePassword");
expect(config.passwordResetSuccessURL).toEqual("myPasswordResetSuccess");
expect(config.parseFrameURL).toEqual("http://example.com/handle-parse-iframe");
expect(config.verifyEmailURL).toEqual("https://my.public.server.com/1/apps/test/verify_email");
expect(config.requestResetPasswordURL).toEqual("https://my.public.server.com/1/apps/test/request_password_reset");
done();
Expand Down
4 changes: 4 additions & 0 deletions src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ export class Config {
return this.customPages.passwordResetSuccess || `${this.publicServerURL}/apps/password_reset_success.html`;
}

get parseFrameURL() {
return this.customPages.parseFrameURL;
}

get verifyEmailURL() {
return `${this.publicServerURL}/apps/${this.applicationId}/verify_email`;
}
Expand Down
17 changes: 15 additions & 2 deletions src/Controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ export class UserController extends AdaptableController {
// We may need to fetch the user in case of update email
this.getUserIfNeeded(user).then((user) => {
const username = encodeURIComponent(user.username);
const link = `${this.config.verifyEmailURL}?token=${token}&username=${username}`;

const link = buildEmailLink(this.config.verifyEmailURL, username, token, this.config);
const options = {
appName: this.config.appName,
link: link,
Expand Down Expand Up @@ -153,8 +154,8 @@ export class UserController extends AdaptableController {
.then(user => {
const token = encodeURIComponent(user._perishable_token);
const username = encodeURIComponent(user.username);
const link = `${this.config.requestResetPasswordURL}?token=${token}&username=${username}`

const link = buildEmailLink(this.config.requestResetPasswordURL, username, token, this.config);
const options = {
appName: this.config.appName,
link: link,
Expand Down Expand Up @@ -215,4 +216,16 @@ function updateUserPassword(userId, password, config) {
});
}

function buildEmailLink(destination, username, token, config) {
const usernameAndToken = `token=${token}&username=${username}`

if (config.parseFrameURL) {
const destinationWithoutHost = destination.replace(config.publicServerURL, '');

return `${config.parseFrameURL}?link=${encodeURIComponent(destinationWithoutHost)}&${usernameAndToken}`;
} else {
return `${destination}?${usernameAndToken}`;
}
}

export default UserController;