Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit 5bceb96

Browse files
committed
Merge pull request #388 from cloudspokes/thabo-S-269146-identity-by-auth0-id
Thabo s 269146 identity by auth0
2 parents e098117 + ce95c3f commit 5bceb96

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

actions/user.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,89 @@ exports.getUserIdentity = {
322322
}
323323
}
324324
};
325+
326+
/**
327+
* Get user identity information api.
328+
* @param {Object} api - The api object.
329+
* @param {Object} connection - The database connection map object.
330+
* @param {Function} next - The callback function.
331+
* @since 1.2
332+
*/
333+
function getUserIdentityByAuth0Id(api, connection, next) {
334+
var helper = api.helper,
335+
auth0id = connection.params.id,
336+
userid = 0,
337+
dbConnectionMap = connection.dbConnectionMap,
338+
response;
339+
340+
async.waterfall([
341+
function (cb) {
342+
var splits = auth0id.split('|');
343+
if (splits[0] == 'ad') {
344+
cb(null, [{ user_id: Number(splits[1]) }]);
345+
} else {
346+
api.helper.getProviderId(splits[0], function(err, provider) {
347+
if (err) {
348+
cb(err);
349+
} else {
350+
api.dataAccess.executeQuery("get_user_by_social_login",
351+
{
352+
social_user_id: splits[1],
353+
provider_id: provider
354+
},
355+
dbConnectionMap, cb);
356+
}
357+
});
358+
}
359+
},
360+
function (result, cb) {
361+
userid = result[0].user_id
362+
api.dataAccess.executeQuery('get_user_email_and_handle',
363+
{ userId: userid },
364+
dbConnectionMap, cb);
365+
},
366+
function (rs, cb) {
367+
response = {
368+
uid: userid,
369+
handle: rs[0].handle,
370+
email: rs[0].address
371+
};
372+
cb();
373+
}
374+
], function (err) {
375+
if (err) {
376+
helper.handleError(api, connection, err);
377+
} else {
378+
connection.response = response;
379+
}
380+
next(connection, true);
381+
});
382+
383+
}
384+
385+
/**
386+
* The API for activate user
387+
* @since 1.2
388+
*/
389+
exports.getUserIdentityByAuth0Id = {
390+
name: 'getUserIdentityByAuth0Id',
391+
description: 'Get user identity information',
392+
inputs: {
393+
required: ['id'],
394+
optional: []
395+
},
396+
blockedConnectionTypes: [],
397+
outputExample: {},
398+
version: 'v2',
399+
transaction: 'read',
400+
databases: ['common_oltp'],
401+
cacheEnabled: false,
402+
run: function (api, connection, next) {
403+
if (connection.dbConnectionMap) {
404+
api.log('getUserIdentityByAuth0Id#run', 'debug');
405+
getUserIdentityByAuth0Id(api, connection, next);
406+
} else {
407+
api.helper.handleNoConnection(api, connection, next);
408+
}
409+
}
410+
};

routes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ exports.routes = {
258258

259259
{ path: "/:apiVersion/user/challenges", action: "getMyChallenges" },
260260
{ path: "/:apiVersion/user/activation-email", action: "userActivationEmail" },
261+
{ path: "/:apiVersion/user/identity/:id", action: "getUserIdentityByAuth0Id" },
261262
{ path: "/:apiVersion/user/identity", action: "getUserIdentity" },
262263

263264
{ path: "/:apiVersion/users/tops/:trackType", action: "getTopTrackMembers" },

0 commit comments

Comments
 (0)