Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
added 'resume' optional parameter for email sending endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
dannycoates committed Sep 4, 2014
1 parent 2b992ff commit 696b43f
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 45 deletions.
5 changes: 4 additions & 1 deletion docs/api.md
Expand Up @@ -152,6 +152,7 @@ ___Parameters___
* authPW - the PBKDF2/HKDF stretched password as a hex string
* service - (optional) opaque alphanumeric token to be included in verification links
* redirectTo - (optional) a URL that the client should be redirected to after handling the request
* resume - (optional) opaque url-encoded string that will be included in the verification link as a querystring parameter, useful for continuing an OAuth flow for example.
* preVerifyToken - (optional) see below

### Request
Expand Down Expand Up @@ -636,7 +637,7 @@ ___Parameters___

* service - (optional) opaque alphanumeric token to be included in verification links
* redirectTo - (optional) a URL that the client should be redirected to after handling the request

* resume - (optional) opaque url-encoded string that will be included in the verification link as a querystring parameter, useful for continuing an OAuth flow for example.

___Headers___

Expand Down Expand Up @@ -898,6 +899,7 @@ ___Parameters___
* email - the recovery email for this account
* service - (optional) indicates the relying service that the user was interacting with that triggered the password reset
* redirectTo - (optional) a URL that the client should be redirected to after handling the request
* resume - (optional) opaque url-encoded string that will be included in the verification link as a querystring parameter, useful for continuing an OAuth flow for example.

### Request
```sh
Expand Down Expand Up @@ -948,6 +950,7 @@ ___Parameters___
* email - the recovery email for this account
* service - (optional) indicates the relying service that the user was interacting with that triggered the password reset
* redirectTo - (optional) a URL that the client should be redirected to after handling the request
* resume - (optional) opaque url-encoded string that will be included in the verification link as a querystring parameter, useful for continuing an OAuth flow for example.

### Request

Expand Down
2 changes: 2 additions & 0 deletions mailer.js
Expand Up @@ -25,6 +25,7 @@ module.exports = function (config, log) {
code: code.toString('hex'),
service: opts.service,
redirectTo: opts.redirectTo,
resume: opts.resume,
acceptLanguage: opts.acceptLanguage || defaultLanguage
}
))
Expand All @@ -37,6 +38,7 @@ module.exports = function (config, log) {
code: code.toString('hex'),
service: opts.service,
redirectTo: opts.redirectTo,
resume: opts.resume,
acceptLanguage: opts.acceptLanguage || defaultLanguage
}
))
Expand Down
18 changes: 9 additions & 9 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -34,7 +34,7 @@
"bunyan": "1.0.0",
"compute-cluster": "0.0.9",
"convict": "0.4.2",
"fxa-auth-mailer": "0.0.5",
"fxa-auth-mailer": "1.0.6",
"hapi": "6.5.1",
"hapi-auth-hawk": "1.1.1",
"hkdf": "0.0.2",
Expand Down
6 changes: 5 additions & 1 deletion routes/account.js
Expand Up @@ -39,6 +39,7 @@ module.exports = function (
preVerified: isA.boolean(),
service: isA.string().max(16).alphanum().optional(),
redirectTo: validators.redirectTo(redirectDomain).optional(),
resume: isA.string().max(2048).optional(),
preVerifyToken: isA.string().max(2048).regex(BASE64_JWT).optional()
}
}
Expand Down Expand Up @@ -150,6 +151,7 @@ module.exports = function (
mailer.sendVerifyCode(response.account, response.account.emailCode, {
service: form.service,
redirectTo: form.redirectTo,
resume: form.resume,
acceptLanguage: request.app.acceptLanguage
})
.fail(
Expand Down Expand Up @@ -423,7 +425,8 @@ module.exports = function (
validate: {
payload: {
service: isA.string().max(16).alphanum().optional(),
redirectTo: validators.redirectTo(redirectDomain).optional()
redirectTo: validators.redirectTo(redirectDomain).optional(),
resume: isA.string().max(2048).optional()
}
}
},
Expand All @@ -447,6 +450,7 @@ module.exports = function (
{
service: request.payload.service,
redirectTo: request.payload.redirectTo,
resume: request.payload.resume,
acceptLanguage: request.app.acceptLanguage
}
)
Expand Down
8 changes: 6 additions & 2 deletions routes/password.js
Expand Up @@ -170,7 +170,8 @@ module.exports = function (
payload: {
email: validators.email().required(),
service: isA.string().max(16).alphanum().optional(),
redirectTo: validators.redirectTo(redirectDomain).optional()
redirectTo: validators.redirectTo(redirectDomain).optional(),
resume: isA.string().max(2048).optional()
}
},
response: {
Expand Down Expand Up @@ -204,6 +205,7 @@ module.exports = function (
{
service: request.payload.service,
redirectTo: request.payload.redirectTo,
resume: request.payload.resume,
acceptLanguage: request.app.acceptLanguage
}
)
Expand Down Expand Up @@ -240,7 +242,8 @@ module.exports = function (
payload: {
email: validators.email().required(),
service: isA.string().max(16).alphanum().optional(),
redirectTo: validators.redirectTo(redirectDomain).optional()
redirectTo: validators.redirectTo(redirectDomain).optional(),
resume: isA.string().max(2048).optional()
}
},
response: {
Expand Down Expand Up @@ -268,6 +271,7 @@ module.exports = function (
{
service: request.payload.service,
redirectTo: request.payload.redirectTo,
resume: request.payload.resume,
acceptLanguage: request.app.acceptLanguage
}
)
Expand Down
10 changes: 7 additions & 3 deletions test/client/api.js
Expand Up @@ -101,6 +101,7 @@ ClientApi.prototype.accountCreate = function (email, authPW, options) {
preVerified: options.preVerified || undefined,
service: options.service || undefined,
redirectTo: options.redirectTo || undefined,
resume: options.resume || undefined,
preVerifyToken: options.preVerifyToken || undefined
},
{
Expand Down Expand Up @@ -227,7 +228,8 @@ ClientApi.prototype.recoveryEmailResendCode = function (sessionTokenHex, options
token,
{
service: options.service || undefined,
redirectTo: options.redirectTo || undefined
redirectTo: options.redirectTo || undefined,
resume: options.resume || undefined
}
)
}.bind(this)
Expand Down Expand Up @@ -312,7 +314,8 @@ ClientApi.prototype.passwordForgotSendCode = function (email, options) {
{
email: email,
service: options.service || undefined,
redirectTo: options.redirectTo || undefined
redirectTo: options.redirectTo || undefined,
resume: options.resume || undefined
}
)
}
Expand All @@ -329,7 +332,8 @@ ClientApi.prototype.passwordForgotResendCode = function (passwordForgotTokenHex,
{
email: email,
service: options.service || undefined,
redirectTo: options.redirectTo || undefined
redirectTo: options.redirectTo || undefined,
resume: options.resume || undefined
}
)
}.bind(this)
Expand Down
33 changes: 5 additions & 28 deletions test/remote/account_create_tests.js
Expand Up @@ -82,14 +82,14 @@ TestServer.start(config)
}
)

/*/ TODO: revisit after the "dumb" resend logic is updated

test(
'create account with service identifier',
'create account with service identifier and resume',
function (t) {
var email = server.uniqueEmail()
var password = 'allyourbasearebelongtous'
var client = null
var options = { service: 'abcdef' }
var options = { service: 'abcdef', resume: 'foo' }
return Client.create(config.publicUrl, email, password, options)
.then(
function (x) {
Expand All @@ -104,35 +104,12 @@ TestServer.start(config)
.then(
function (emailData) {
t.equal(emailData.headers['x-service-id'], 'abcdef')
client.options.service = '123456'
return client.requestVerifyEmail()
}
)
.then(
function () {
return server.mailbox.waitForEmail(email)
}
)
.then(
function (emailData) {
t.equal(emailData.headers['x-service-id'], '123456')
client.options.service = null
return client.requestVerifyEmail()
}
)
.then(
function () {
return server.mailbox.waitForEmail(email)
}
)
.then(
function (emailData) {
t.equal(emailData.headers['x-service-id'], undefined)
t.ok(emailData.headers['x-link'].indexOf('resume=foo') > -1)
}
)
}
)
/*/

test(
'create account allows localization of emails',
function (t) {
Expand Down

0 comments on commit 696b43f

Please sign in to comment.