pptb-standard-sample-tool 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.js +139 -0
- package/dist/index.html +48 -0
- package/package.json +1 -1
package/dist/app.js
CHANGED
|
@@ -269,6 +269,9 @@ function setupEventHandlers() {
|
|
|
269
269
|
document.getElementById("list-flows-btn")?.addEventListener("click", listPowerAutomateFlows);
|
|
270
270
|
document.getElementById("list-environments-btn")?.addEventListener("click", listEnvironments);
|
|
271
271
|
document.getElementById("get-governance-btn")?.addEventListener("click", getGovernanceData);
|
|
272
|
+
document.getElementById("query-role-definitions-btn")?.addEventListener("click", queryRoleDefinitions);
|
|
273
|
+
document.getElementById("assign-role-btn")?.addEventListener("click", assignRole);
|
|
274
|
+
document.getElementById("query-role-assignments-btn")?.addEventListener("click", queryRoleAssignments);
|
|
272
275
|
// Clear log button
|
|
273
276
|
document.getElementById("clear-log-btn")?.addEventListener("click", clearLog);
|
|
274
277
|
// Advanced utilities demos
|
|
@@ -1073,6 +1076,142 @@ async function getGovernanceData() {
|
|
|
1073
1076
|
log(`Error getting governance data: ${error.message}`, "error");
|
|
1074
1077
|
}
|
|
1075
1078
|
}
|
|
1079
|
+
/**
|
|
1080
|
+
* Query role definitions from Power Platform Authorization API
|
|
1081
|
+
* Retrieves all available role definitions with their IDs and names
|
|
1082
|
+
*/
|
|
1083
|
+
async function queryRoleDefinitions() {
|
|
1084
|
+
const output = document.getElementById("role-definitions-output");
|
|
1085
|
+
try {
|
|
1086
|
+
if (output)
|
|
1087
|
+
output.textContent = "Fetching role definitions...\n";
|
|
1088
|
+
// Call the Power Platform Authorization API to get role definitions
|
|
1089
|
+
const result = await powerplatform.Authorization.Get("roleDefinitions?api-version=2024-10-01");
|
|
1090
|
+
if (output) {
|
|
1091
|
+
const roleDefinitions = result.value || [];
|
|
1092
|
+
output.textContent = `Found ${roleDefinitions.length} role definition(s):\n\n`;
|
|
1093
|
+
if (roleDefinitions.length === 0) {
|
|
1094
|
+
output.textContent += "No role definitions found.";
|
|
1095
|
+
}
|
|
1096
|
+
else {
|
|
1097
|
+
// Display role definitions in a formatted table
|
|
1098
|
+
roleDefinitions.forEach((role, index) => {
|
|
1099
|
+
output.textContent += `${index + 1}. ${role.roleDefinitionName}\n`;
|
|
1100
|
+
output.textContent += ` ID: ${role.roleDefinitionId}\n`;
|
|
1101
|
+
if (role.description)
|
|
1102
|
+
output.textContent += ` Description: ${role.description}\n`;
|
|
1103
|
+
output.textContent += "\n";
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
log(`Retrieved ${roleDefinitions.length} role definitions`, "success");
|
|
1107
|
+
await showNotification("Role Definitions Retrieved", `Found ${roleDefinitions.length} role definition(s)`, "success");
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
catch (error) {
|
|
1111
|
+
const errorMessage = error.message;
|
|
1112
|
+
if (output)
|
|
1113
|
+
output.textContent = `Error: ${errorMessage}`;
|
|
1114
|
+
log(`Error querying role definitions: ${errorMessage}`, "error");
|
|
1115
|
+
await showNotification("Error", `Failed to retrieve role definitions: ${errorMessage}`, "error");
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
/**
|
|
1119
|
+
* Assign a role to a principal (user, service principal, or enterprise app)
|
|
1120
|
+
* Creates a role assignment in the Power Platform Authorization API
|
|
1121
|
+
*/
|
|
1122
|
+
async function assignRole() {
|
|
1123
|
+
const output = document.getElementById("role-assignment-output");
|
|
1124
|
+
const tenantId = document.getElementById("role-assign-tenant-id")?.value;
|
|
1125
|
+
const principalObjectId = document.getElementById("role-assign-principal-object-id")?.value;
|
|
1126
|
+
const principalType = document.getElementById("role-assign-principal-type")?.value || "ApplicationUser";
|
|
1127
|
+
const roleDefinitionId = document.getElementById("role-assign-role-definition-id")?.value;
|
|
1128
|
+
if (!tenantId || !principalObjectId || !roleDefinitionId) {
|
|
1129
|
+
await showNotification("Missing Fields", "Please fill in all required fields", "warning");
|
|
1130
|
+
if (output)
|
|
1131
|
+
output.textContent = "Please provide Tenant ID, Principal Object ID, and Role Definition ID.";
|
|
1132
|
+
return;
|
|
1133
|
+
}
|
|
1134
|
+
try {
|
|
1135
|
+
if (output)
|
|
1136
|
+
output.textContent = "Assigning role...\n";
|
|
1137
|
+
// Build the request body
|
|
1138
|
+
const body = {
|
|
1139
|
+
roleDefinitionId,
|
|
1140
|
+
principalObjectId,
|
|
1141
|
+
principalType,
|
|
1142
|
+
scope: `/tenants/${tenantId}`,
|
|
1143
|
+
};
|
|
1144
|
+
// Call the Power Platform Authorization API to assign role
|
|
1145
|
+
const result = await powerplatform.Authorization.Post("roleAssignments?api-version=2024-10-01", body);
|
|
1146
|
+
if (output) {
|
|
1147
|
+
output.textContent = "Role assignment created successfully!\n\n";
|
|
1148
|
+
output.textContent += "Assignment Details:\n";
|
|
1149
|
+
output.textContent += `ID: ${result.id || result.roleAssignmentId}\n`;
|
|
1150
|
+
output.textContent += `Role Definition ID: ${result.roleDefinitionId}\n`;
|
|
1151
|
+
output.textContent += `Principal Object ID: ${result.principalObjectId}\n`;
|
|
1152
|
+
output.textContent += `Principal Type: ${result.principalType}\n`;
|
|
1153
|
+
output.textContent += `Scope: ${result.scope}\n`;
|
|
1154
|
+
}
|
|
1155
|
+
log(`Role assigned successfully to ${principalObjectId}`, "success");
|
|
1156
|
+
await showNotification("Role Assigned", `Role assigned to ${principalObjectId}`, "success");
|
|
1157
|
+
}
|
|
1158
|
+
catch (error) {
|
|
1159
|
+
const errorMessage = error.message;
|
|
1160
|
+
if (output)
|
|
1161
|
+
output.textContent = `Error: ${errorMessage}`;
|
|
1162
|
+
log(`Error assigning role: ${errorMessage}`, "error");
|
|
1163
|
+
await showNotification("Error", `Failed to assign role: ${errorMessage}`, "error");
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* Query existing role assignments from Power Platform Authorization API
|
|
1168
|
+
* Optionally filter by principal object ID
|
|
1169
|
+
*/
|
|
1170
|
+
async function queryRoleAssignments() {
|
|
1171
|
+
const output = document.getElementById("role-assignments-list-output");
|
|
1172
|
+
const filterPrincipalId = document.getElementById("query-role-assign-principal-id")?.value;
|
|
1173
|
+
try {
|
|
1174
|
+
if (output)
|
|
1175
|
+
output.textContent = "Fetching role assignments...\n";
|
|
1176
|
+
// Call the Power Platform Authorization API to get role assignments
|
|
1177
|
+
const result = await powerplatform.Authorization.Get("roleAssignments?api-version=2024-10-01");
|
|
1178
|
+
if (output) {
|
|
1179
|
+
const roleAssignments = result.value || [];
|
|
1180
|
+
// Filter by principal object ID if provided
|
|
1181
|
+
let filteredAssignments = roleAssignments;
|
|
1182
|
+
if (filterPrincipalId && filterPrincipalId.trim()) {
|
|
1183
|
+
filteredAssignments = roleAssignments.filter((assignment) => assignment.principalObjectId === filterPrincipalId);
|
|
1184
|
+
output.textContent = `Found ${filteredAssignments.length} role assignment(s) for principal ${filterPrincipalId}:\n\n`;
|
|
1185
|
+
}
|
|
1186
|
+
else {
|
|
1187
|
+
output.textContent = `Found ${roleAssignments.length} total role assignment(s):\n\n`;
|
|
1188
|
+
}
|
|
1189
|
+
if (filteredAssignments.length === 0) {
|
|
1190
|
+
output.textContent += "No role assignments found.";
|
|
1191
|
+
}
|
|
1192
|
+
else {
|
|
1193
|
+
// Display role assignments in a formatted table
|
|
1194
|
+
filteredAssignments.forEach((assignment, index) => {
|
|
1195
|
+
output.textContent += `${index + 1}. Role Assignment ID: ${assignment.roleAssignmentId || assignment.id}\n`;
|
|
1196
|
+
output.textContent += ` Role Definition ID: ${assignment.roleDefinitionId}\n`;
|
|
1197
|
+
output.textContent += ` Principal Object ID: ${assignment.principalObjectId}\n`;
|
|
1198
|
+
output.textContent += ` Principal Type: ${assignment.principalType}\n`;
|
|
1199
|
+
output.textContent += ` Scope: ${assignment.scope}\n`;
|
|
1200
|
+
output.textContent += "\n";
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
log(`Retrieved ${filteredAssignments.length} role assignment(s)${filterPrincipalId ? ` for ${filterPrincipalId}` : ""}`, "success");
|
|
1204
|
+
await showNotification("Role Assignments Retrieved", `Found ${filteredAssignments.length} role assignment(s)`, "success");
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
catch (error) {
|
|
1208
|
+
const errorMessage = error.message;
|
|
1209
|
+
if (output)
|
|
1210
|
+
output.textContent = `Error: ${errorMessage}`;
|
|
1211
|
+
log(`Error querying role assignments: ${errorMessage}`, "error");
|
|
1212
|
+
await showNotification("Error", `Failed to retrieve role assignments: ${errorMessage}`, "error");
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1076
1215
|
// Initialize when DOM is ready
|
|
1077
1216
|
if (document.readyState === "loading") {
|
|
1078
1217
|
document.addEventListener("DOMContentLoaded", initialize);
|
package/dist/index.html
CHANGED
|
@@ -220,6 +220,54 @@
|
|
|
220
220
|
</div>
|
|
221
221
|
<div id="governance-output" class="output"></div>
|
|
222
222
|
</div>
|
|
223
|
+
|
|
224
|
+
<div class="example-group">
|
|
225
|
+
<h3>Authorization API</h3>
|
|
226
|
+
<div class="button-group">
|
|
227
|
+
<button id="query-role-definitions-btn" class="btn btn-primary">Query Role Definitions</button>
|
|
228
|
+
</div>
|
|
229
|
+
<div id="role-definitions-output" class="output"></div>
|
|
230
|
+
</div>
|
|
231
|
+
|
|
232
|
+
<div class="example-group">
|
|
233
|
+
<h3>Authorization API - Role Assignment</h3>
|
|
234
|
+
<div class="input-group">
|
|
235
|
+
<label for="role-assign-tenant-id">Tenant ID:</label>
|
|
236
|
+
<input type="text" id="role-assign-tenant-id" placeholder="e.g., 15263562-2ed2-4856-8562-42edf998128b" />
|
|
237
|
+
</div>
|
|
238
|
+
<div class="input-group">
|
|
239
|
+
<label for="role-assign-principal-object-id">Principal Object ID:</label>
|
|
240
|
+
<input type="text" id="role-assign-principal-object-id" placeholder="e.g., 78541268-7456-7856-a7ba-04424f177c7c" />
|
|
241
|
+
</div>
|
|
242
|
+
<div class="input-group">
|
|
243
|
+
<label for="role-assign-principal-type">Principal Type:</label>
|
|
244
|
+
<select id="role-assign-principal-type">
|
|
245
|
+
<option value="ApplicationUser">ApplicationUser</option>
|
|
246
|
+
<option value="ServicePrincipal">ServicePrincipal</option>
|
|
247
|
+
<option value="User">User</option>
|
|
248
|
+
</select>
|
|
249
|
+
</div>
|
|
250
|
+
<div class="input-group">
|
|
251
|
+
<label for="role-assign-role-definition-id">Role Definition ID:</label>
|
|
252
|
+
<input type="text" id="role-assign-role-definition-id" placeholder="e.g., ff954d61-a89a-4fbe-ace9-01c367b89f87" />
|
|
253
|
+
</div>
|
|
254
|
+
<div class="button-group">
|
|
255
|
+
<button id="assign-role-btn" class="btn btn-success">Assign Role</button>
|
|
256
|
+
</div>
|
|
257
|
+
<div id="role-assignment-output" class="output"></div>
|
|
258
|
+
</div>
|
|
259
|
+
|
|
260
|
+
<div class="example-group">
|
|
261
|
+
<h3>Authorization API - Query Role Assignments</h3>
|
|
262
|
+
<div class="input-group">
|
|
263
|
+
<label for="query-role-assign-principal-id">Principal Object ID (Optional - filters results):</label>
|
|
264
|
+
<input type="text" id="query-role-assign-principal-id" placeholder="e.g., 78541268-7456-7856-a7ba-04424f177c7c" />
|
|
265
|
+
</div>
|
|
266
|
+
<div class="button-group">
|
|
267
|
+
<button id="query-role-assignments-btn" class="btn">Query Role Assignments</button>
|
|
268
|
+
</div>
|
|
269
|
+
<div id="role-assignments-list-output" class="output"></div>
|
|
270
|
+
</div>
|
|
223
271
|
</section>
|
|
224
272
|
|
|
225
273
|
<!-- Inter-tool Invocation Example -->
|
package/package.json
CHANGED