75d7ce7f7475e957f2e8020d2943c476c130878a
4 * This renders the interface for submitting a ticket proffer to a third-party.
7 const th
= require('./template-helper');
8 const { sessionNavLinks
} = require('@squeep/authentication-module');
13 * @param {string} profile profile
14 * @returns {string} option
16 function renderProfileOption(profile
) {
17 return `<option value="${profile}">${profile}</option>`;
22 * @param {string} scope scope
23 * @returns {string} tr
25 function renderScopeCheckboxTR(scope
) {
26 const defaultChecked
= ['read'];
27 const checked
= defaultChecked
.includes(scope
) ? ' checked' : '';
28 return `<tr class="scope">
29 \t<td><input type="checkbox" id="scopes-${scope}" name="scopes[]" value="${scope}"${checked}></td>
36 * @param {object} ctx context
37 * @returns {string} section
39 function mainContent(ctx
) {
40 const profileOptions
= th
.indented(4, (ctx
?.profilesScopes
?.profiles
|| []).map((profile
) => renderProfileOption(profile
)))
42 const elideScopes
= ['profile', 'email'];
43 const allScopes
= Object
.keys(ctx
?.profilesScopes
?.scopeIndex
|| {});
44 const displayScopes
= (allScopes
).filter((scope
) => !elideScopes
.includes(scope
));
45 const scopesCheckboxRows
= th
.indented(5, displayScopes
.map((scope
) => renderScopeCheckboxTR(scope
)))
48 \t<form method="POST">
50 \t\t\tYou may proactively send a ticket to a third-party site,
51 \t\t\twhich they may redeem for an access token which grants additional
52 \t\t\taccess to the specified resource.
56 \t\t\t<legend>Proffer A Ticket</legend>
57 \t\t\t<label for="profile-select">Profile Granting this Ticket</label>
58 \t\t\t<select id="profile-select" name="profile">
62 \t\t\t<label for="resource-url">Resource URL:</label>
63 \t\t\t<input type="url" id="resource-url" name="resource" size="96">
65 \t\t\t<label for="recipient-url">Recipient URL:</label>
66 \t\t\t<input type="url" id="recipient-url" name="subject" size="96">
69 <legend>Scopes</legend>
77 \t\t\t<label for="scopes-adhoc">Additional Scopes (space separated):</label>
78 \t\t\t<input type="text" id="scopes-adhoc" name="adhoc" size="96">
80 \t\t\t<button type="submit" name="action" value="proffer-ticket">Send Ticket</button>
89 * @param {object} ctx context
90 * @param {object} ctx.profilesScopes.scopeIndex scopes structure
91 * @param {string[]} ctx.profileScopes.profiles profile
92 * @param {object} options options
93 * @param {object} options.manager manager options
94 * @param {string} options.manager.pageTitle page title
95 * @param {string} options.manager.logoUrl logo url
96 * @param {string[]} options.manager.footerEntries footer entries
97 * @returns {string} page
99 module
.exports
= (ctx
, options
) => {
100 const pagePathLevel
= 1;
101 const htmlOptions
= {
102 pageIdentifier: 'ticketProffer',
103 pageTitle: options
.manager
.pageTitle
+ ' - Ticket Proffer',
104 logoUrl: options
.manager
.logoUrl
,
105 footerEntries: options
.manager
.footerEntries
,
106 errorContent: ['Unable to send ticket.'],
108 th
.navLinks(pagePathLevel
, ctx
, htmlOptions
);
109 sessionNavLinks(pagePathLevel
, ctx
, htmlOptions
);
113 return th
.htmlPage(pagePathLevel
, ctx
, htmlOptions
, content
);