Skip to content

Commit 924bda3

Browse files
committed
2 parents c20eb6d + 36ec66c commit 924bda3

File tree

15 files changed

+563
-71
lines changed

15 files changed

+563
-71
lines changed

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ const {
4747
} = require("./lib/monitor/controllers/index");
4848

4949
const {
50-
eg001admin, eg002admin, eg003admin, eg004admin, eg005admin
50+
eg001admin, eg002admin, eg003admin,
51+
eg004admin, eg005admin, eg006admin,
52+
eg007admin
5153
} = require("./lib/admin/controllers");
5254

5355
const PORT = process.env.PORT || 3000;
@@ -155,6 +157,10 @@ if (examplesApi.examplesApi.isRoomsApi) {
155157
.get('/eg004status', eg004admin.checkStatus)
156158
.get('/eg005', eg005admin.getController)
157159
.post('/eg005', eg005admin.createController)
160+
.get('/eg006', eg006admin.getController)
161+
.post('/eg006', eg006admin.createController)
162+
.get('/eg007', eg007admin.getController)
163+
.post('/eg007', eg007admin.createController)
158164
} else {
159165
app.get('/eg001', eg001.getController)
160166
.post('/eg001', eg001.createController)

jwt_console_project/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/**
2+
* @file
3+
* Example 006: Get user profile data by email
4+
* @author DocuSign
5+
*/
6+
7+
const path = require('path');
8+
const { getUserProfileByEmail } = require('../examples/getUserProfileByEmail');
9+
const dsConfig = require('../../../config/index.js').config;
10+
const validator = require('validator');
11+
const { getOrganizationId } = require("../getOrganizationId.js");
12+
13+
const eg006GetUserProfileByEmail = exports;
14+
const eg = 'eg006' // This example reference.;
15+
const mustAuthenticate = '/ds/mustAuthenticate';
16+
const minimumBufferMin = 3;
17+
18+
/**
19+
* Getting user profile by email
20+
* @param {object} req Request obj
21+
* @param {object} res Response obj
22+
*/
23+
eg006GetUserProfileByEmail.createController = async(req, res) => {
24+
// Step 1. Check the token
25+
// At this point we should have a good token. But we
26+
// double-check here to enable a better UX to the user.
27+
const isTokenOK = req.dsAuth.checkToken(minimumBufferMin);
28+
if (!isTokenOK) {
29+
req.flash('info', 'Sorry, you need to re-authenticate.');
30+
// Save the current operation so it will be resumed after authentication
31+
req.dsAuth.setEg(req, eg);
32+
res.redirect(mustAuthenticate);
33+
}
34+
35+
const { body } = req;
36+
const args = {
37+
accessToken: req.user.accessToken,
38+
email: validator.escape(body.email),
39+
accountId: req.session.accountId,
40+
organizationId: req.session.organizationId,
41+
basePath: dsConfig.adminAPIUrl
42+
};
43+
44+
let results = null;
45+
46+
try {
47+
results = await getUserProfileByEmail(args)
48+
} catch (error) {
49+
// we can pull the DocuSign error code and message from the response body
50+
const errorBody = error && error.response && error.response.body;
51+
const errorCode = errorBody && errorBody.errorCode;
52+
const errorMessage = errorBody && errorBody.message;
53+
54+
// In production, may want to provide customized error messages and
55+
// remediation advice to the user.
56+
res.render('pages/error', { err: error, errorCode, errorMessage });
57+
}
58+
if (results) {
59+
res.render('pages/example_done', {
60+
title: "Retrieve the user's DocuSign profile using an email address",
61+
h1: "Retrieve the user's DocuSign profile using an email address",
62+
message: "Results from MultiProductUserManagement:getUserDSProfilesByEmail method:",
63+
json: JSON.stringify(results)
64+
});
65+
}
66+
}
67+
68+
/**
69+
* Form page for this application
70+
*/
71+
eg006GetUserProfileByEmail.getController = async (req, res) => {
72+
// Check that the authentication token is ok with a long buffer time.
73+
// If needed, now is the best time to ask the user to authenticate
74+
// since they have not yet entered any information into the form.
75+
76+
let isTokenOK = req.dsAuth.checkToken();
77+
if (isTokenOK) {
78+
try {
79+
await getOrganizationId(req);
80+
81+
const args = {
82+
accessToken: req.user.accessToken,
83+
accountId: req.session.accountId,
84+
basePath: req.session.basePath,
85+
organizationId: req.session.organizationId
86+
};
87+
88+
sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
89+
res.render('pages/admin-examples/eg006GetUserProfileByEmail', {
90+
eg: eg,
91+
csrfToken: req.csrfToken(),
92+
title: "Get user profile by email",
93+
sourceFile: sourceFile,
94+
sourceUrl: dsConfig.githubExampleUrl + "admin/examples/" + sourceFile,
95+
documentation: dsConfig.documentation + eg,
96+
showDoc: dsConfig.documentation
97+
});
98+
}
99+
catch (error) {
100+
const errorBody = error && error.response && error.response.body;
101+
const errorCode = errorBody && errorBody.errorCode;
102+
const errorMessage = errorBody && errorBody.message;
103+
104+
// In production, may want to provide customized error messages and
105+
// remediation advice to the user.
106+
res.render('pages/error', { err: error, errorCode, errorMessage });
107+
}
108+
109+
} else {
110+
// Save the current operation so it will be resumed after authentication
111+
req.dsAuth.setEg(req, eg);
112+
res.redirect(mustAuthenticate);
113+
}
114+
}
115+
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/**
2+
* @file
3+
* Example 007: Get user profile by user ID
4+
* @author DocuSign
5+
*/
6+
7+
const path = require('path');
8+
const { getUserProfileByUserId } = require('../examples/getUserProfileByUserId');
9+
const dsConfig = require('../../../config/index.js').config;
10+
const validator = require('validator');
11+
const { getOrganizationId } = require("../getOrganizationId.js");
12+
13+
const eg007GetUserProfileByUserId = exports;
14+
const eg = 'eg007' // This example reference.;
15+
const mustAuthenticate = '/ds/mustAuthenticate';
16+
const minimumBufferMin = 3;
17+
18+
/**
19+
* Getting user profile by user ID
20+
* @param {object} req Request obj
21+
* @param {object} res Response obj
22+
*/
23+
eg007GetUserProfileByUserId.createController = async(req, res) => {
24+
// Step 1. Check the token
25+
// At this point we should have a good token. But we
26+
// double-check here to enable a better UX to the user.
27+
const isTokenOK = req.dsAuth.checkToken(minimumBufferMin);
28+
if (!isTokenOK) {
29+
req.flash('info', 'Sorry, you need to re-authenticate.');
30+
// Save the current operation so it will be resumed after authentication
31+
req.dsAuth.setEg(req, eg);
32+
res.redirect(mustAuthenticate);
33+
}
34+
35+
const { body } = req;
36+
const args = {
37+
accessToken: req.user.accessToken,
38+
userId: validator.escape(body.userId),
39+
accountId: req.session.accountId,
40+
organizationId: req.session.organizationId,
41+
basePath: dsConfig.adminAPIUrl
42+
};
43+
44+
let results = null;
45+
46+
try {
47+
results = await getUserProfileByUserId(args)
48+
} catch (error) {
49+
// we can pull the DocuSign error code and message from the response body
50+
const errorBody = error && error.response && error.response.body;
51+
const errorCode = errorBody && errorBody.errorCode;
52+
const errorMessage = errorBody && errorBody.message;
53+
54+
// In production, may want to provide customized error messages and
55+
// remediation advice to the user.
56+
res.render('pages/error', { err: error, errorCode, errorMessage });
57+
}
58+
if (results) {
59+
res.render('pages/example_done', {
60+
title: "Retrieve the user's DocuSign profile using a User ID",
61+
h1: "Retrieve the user's DocuSign profile using a User ID",
62+
message: "Results from MultiProductUserManagement:getUserDSProfile method:",
63+
json: JSON.stringify(results)
64+
});
65+
}
66+
}
67+
68+
/**
69+
* Form page for this application
70+
*/
71+
eg007GetUserProfileByUserId.getController = async (req, res) => {
72+
// Check that the authentication token is ok with a long buffer time.
73+
// If needed, now is the best time to ask the user to authenticate
74+
// since they have not yet entered any information into the form.
75+
76+
let isTokenOK = req.dsAuth.checkToken();
77+
if (isTokenOK) {
78+
try {
79+
await getOrganizationId(req);
80+
81+
const args = {
82+
accessToken: req.user.accessToken,
83+
accountId: req.session.accountId,
84+
basePath: req.session.basePath,
85+
organizationId: req.session.organizationId
86+
};
87+
88+
sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
89+
res.render('pages/admin-examples/eg007GetUserProfileByUserId', {
90+
eg: eg,
91+
csrfToken: req.csrfToken(),
92+
title: "Get user profile by user ID",
93+
sourceFile: sourceFile,
94+
sourceUrl: dsConfig.githubExampleUrl + "admin/examples/" + sourceFile,
95+
documentation: dsConfig.documentation + eg,
96+
showDoc: dsConfig.documentation
97+
});
98+
}
99+
catch (error) {
100+
const errorBody = error && error.response && error.response.body;
101+
const errorCode = errorBody && errorBody.errorCode;
102+
const errorMessage = errorBody && errorBody.message;
103+
104+
// In production, may want to provide customized error messages and
105+
// remediation advice to the user.
106+
res.render('pages/error', { err: error, errorCode, errorMessage });
107+
}
108+
109+
} else {
110+
// Save the current operation so it will be resumed after authentication
111+
req.dsAuth.setEg(req, eg);
112+
res.redirect(mustAuthenticate);
113+
}
114+
}
115+

lib/admin/controllers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ module.exports.eg002admin = require('./eg002CreateCLMESignUser');
33
module.exports.eg003admin = require('./eg003BulkExportUserData');
44
module.exports.eg004admin = require('./eg004ImportUser');
55
module.exports.eg005admin = require('./eg005AuditUsers');
6+
module.exports.eg006admin = require('./eg006GetUserProfileByEmail');
7+
module.exports.eg007admin = require('./eg007GetUserProfileByUserId');
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const docusignAdmin = require('docusign-admin');
2+
3+
/**
4+
* This function gets a user profile by email
5+
*/
6+
const getUserProfileByEmail = async(args) => {
7+
// Data for this method
8+
// args.basePath
9+
// args.accessToken
10+
// args.email
11+
12+
// Step 2 start
13+
const apiClient = new docusignAdmin.ApiClient();
14+
apiClient.setBasePath(args.basePath);
15+
apiClient.addDefaultHeader("Authorization", "Bearer " + args.accessToken);
16+
// Step 2 end
17+
18+
// Step 3 start
19+
const usersApi = new docusignAdmin.UsersApi(apiClient);
20+
return usersApi.getUserDSProfilesByEmail(args.organizationId, { email: args.email });
21+
// Step 3 end
22+
}
23+
24+
module.exports = { getUserProfileByEmail };
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const docusignAdmin = require('docusign-admin');
2+
3+
/**
4+
* This function gets a user profile by user ID
5+
*/
6+
const getUserProfileByUserId = async(args) => {
7+
// Data for this method
8+
// args.basePath
9+
// args.accessToken
10+
// args.userId
11+
12+
// Step 2 start
13+
const apiClient = new docusignAdmin.ApiClient();
14+
apiClient.setBasePath(args.basePath);
15+
apiClient.addDefaultHeader("Authorization", "Bearer " + args.accessToken);
16+
// Step 2 end
17+
18+
// Step 3 start
19+
const usersApi = new docusignAdmin.UsersApi(apiClient);
20+
return usersApi.getUserDSProfile(args.organizationId, args.userId);
21+
// Step 3 end
22+
}
23+
24+
module.exports = { getUserProfileByUserId };

0 commit comments

Comments
 (0)