Skip to content

Commit 6dac6ae

Browse files
authored
fix(api-auth): /preauth and /authenticate endpoints also return the default address of an user ZMS-175 (#738)
* rebase * preauth and authenticate now also return the email address of the user * fix user tests * fix git divergence issues: submit.js
1 parent 8730ed5 commit 6dac6ae

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

lib/api/auth.js

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module.exports = (db, server, userHandler) => {
3737
success: successRes,
3838
id: userId,
3939
username: Joi.string().required().description('Username of authenticated User'),
40+
address: Joi.string().required().description('Default email address of authenticated User'),
4041
scope: Joi.string().required().description('The scope this authentication is valid for'),
4142
require2fa: Joi.array().items(Joi.string()).required().description('List of enabled 2FA mechanisms')
4243
})
@@ -109,6 +110,7 @@ module.exports = (db, server, userHandler) => {
109110
success: true,
110111
id: authData.user.toString(),
111112
username: authData.username,
113+
address: authData.address,
112114
scope: authData.scope,
113115
require2fa: authData.require2fa
114116
};
@@ -158,6 +160,7 @@ module.exports = (db, server, userHandler) => {
158160
success: successRes,
159161
id: userId,
160162
username: Joi.string().required().description('Username of authenticated User'),
163+
address: Joi.string().required().description('Default email address of authenticated User'),
161164
scope: Joi.string().required().description('The scope this authentication is valid for'),
162165
require2fa: Joi.array().items(Joi.string()).required().description('List of enabled 2FA mechanisms'),
163166
requirePasswordChange: booleanSchema.required().description('Indicates if account hassword has been reset and should be replaced'),
@@ -246,6 +249,7 @@ module.exports = (db, server, userHandler) => {
246249
success: true,
247250
id: authData.user.toString(),
248251
username: authData.username,
252+
address: authData.address,
249253
scope: authData.scope,
250254
require2fa: authData.require2fa,
251255
requirePasswordChange: authData.requirePasswordChange

lib/user-handler.js

+2
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@ class UserHandler {
853853
user: userData._id,
854854
username: userData.username,
855855
scope: meta.requiredScope,
856+
address: userData.address,
856857
// if 2FA is enabled then require token validation
857858
require2fa: enabled2fa.length && !usingTemporaryPassword ? enabled2fa : false,
858859
requirePasswordChange // true, if password was reset and using temporary password
@@ -1105,6 +1106,7 @@ class UserHandler {
11051106
let authResponse = {
11061107
user: userData._id,
11071108
username: userData.username,
1109+
address: userData.address,
11081110
scope: requiredScope,
11091111
// if 2FA is enabled then require token validation
11101112
require2fa: requiredScope === 'master' && enabled2fa.length ? enabled2fa : false

test/api/users-test.js

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const config = require('wild-config');
1111

1212
const server = supertest.agent(`http://127.0.0.1:${config.api.port}`);
1313

14+
const os = require('os');
15+
1416
describe('API Users', function () {
1517
this.timeout(10000); // eslint-disable-line no-invalid-this
1618

@@ -81,6 +83,7 @@ describe('API Users', function () {
8183
expect(authResponse.body.success).to.be.true;
8284
expect(authResponse.body).to.deep.equal({
8385
success: true,
86+
address: '[email protected]',
8487
id: user,
8588
username: 'myuser2',
8689
scope: 'master',
@@ -155,6 +158,7 @@ describe('API Users', function () {
155158
expect(authResponse.body.success).to.be.true;
156159
expect(authResponse.body).to.deep.equal({
157160
success: true,
161+
address: `myuser2hash@${os.hostname().toLowerCase()}`,
158162
id: user2,
159163
username: 'myuser2hash',
160164
scope: 'master',
@@ -332,6 +336,7 @@ describe('API Users', function () {
332336
expect(authResponse.body.success).to.be.true;
333337
expect(authResponse.body).to.deep.equal({
334338
success: true,
339+
address: '[email protected]',
335340
id: user,
336341
username: 'myuser2',
337342
scope: 'master',

0 commit comments

Comments
 (0)