diff --git a/src/auth/PasswordlessAuthenticator.js b/src/auth/PasswordlessAuthenticator.js index c933f4fe9..f20211e35 100644 --- a/src/auth/PasswordlessAuthenticator.js +++ b/src/auth/PasswordlessAuthenticator.js @@ -8,9 +8,10 @@ function getParamsFromOptions(options) { if (!options || typeof options !== 'object') { return params; } - if (options.forwardedFor) { + if (options.forwardedFor || options.requestLanguage) { params._requestCustomizer = function (req) { - req.set('auth0-forwarded-for', options.forwardedFor); + options.forwardedFor && req.set('auth0-forwarded-for', options.forwardedFor); + options.requestLanguage && req.set('x-request-language', options.requestLanguage); }; } return params; @@ -214,6 +215,7 @@ class PasswordlessAuthenticator { * @param {string} userData.send The type of email to be sent. * @param {object} [options] Additional options. * @param {string} [options.forwardedFor] Value to be used for auth0-forwarded-for header + * @param {string} [options.requestLanguage] Specify a language for the message area. * @param {Function} [cb] Method callback. * @returns {Promise|undefined} */ @@ -270,6 +272,7 @@ class PasswordlessAuthenticator { * @param {string} userData.phone_number User phone number. * @param {object} [options] Additional options. * @param {string} [options.forwardedFor] Value to be used for auth0-forwarded-for header + * @param {string} [options.requestLanguage] Specify a language for the message area. * @param {Function} [cb] Method callback. * @returns {Promise|undefined} */ diff --git a/test/auth/passwordless.tests.js b/test/auth/passwordless.tests.js index 68e44c825..79a88ce1d 100644 --- a/test/auth/passwordless.tests.js +++ b/test/auth/passwordless.tests.js @@ -736,6 +736,25 @@ describe('PasswordlessAuthenticator', () => { .catch(done); }); + it('should make it possible to pass x-request-language header', function (done) { + nock.cleanAll(); + + const request = nock(API_URL) + .post(path, function () { + return this.headers['x-request-language'] === 'fr'; + }) + .reply(200); + + this.authenticator + .sendEmail(userData, { requestLanguage: 'fr' }) + .then(() => { + expect(request.isDone()).to.be.true; + + done(); + }) + .catch(done); + }); + it('should make request with proxy', async () => { nock.cleanAll(); @@ -916,6 +935,25 @@ describe('PasswordlessAuthenticator', () => { .catch(done); }); + it('should make it possible to pass x-request-language header', function (done) { + nock.cleanAll(); + + const request = nock(API_URL) + .post(path, function () { + return this.headers['x-request-language'] === 'fr'; + }) + .reply(200); + + this.authenticator + .sendSMS(userData, { requestLanguage: 'fr' }) + .then(() => { + expect(request.isDone()).to.be.true; + + done(); + }) + .catch(done); + }); + it('should make request with proxy', async () => { nock.cleanAll();