Skip to content

Instantly share code, notes, and snippets.

View phillipharding's full-sized avatar

Phil Harding phillipharding

View GitHub Profile
phillipharding / Azure AD Token using Certificate
Last active January 8, 2024 19:50
Generate an Azure AD Access Token using the Client Credentials flow with a Certificate Secret to use for calling the SharePoint REST API
phillipharding / Upgrading a Functions App and Code-base to the v4
Created November 15, 2023 15:13
Upgrading a Functions App and Code-base to the v4 Runtime
phillipharding / Ensure a SharePoint Folder Path using PnPJS.ts
Last active November 9, 2023 10:38
Create/Ensure a SharePoint folder path with nested folders using PnPJS
Hit 'ctrl + d' or 'cmd + d' to run the code, view console for results
import { IWeb, sp, Web } from "@pnp/sp/presets/all";
import { HttpRequestError } from "./@pnp/odata";
const TranslatePnPError = async (opText: string, e) => {
if (e?.isHttpRequestError) {
const json = await (<HttpRequestError>e).response.json();
const errorObject = typeof json["odata.error"] === "object" ? {...json["odata.error"]} : {...e};
//import { sp, Site, spGet, SharePointQueryable } from "@pnp/sp/presets/all";
import { sp } from "@pnp/sp";
import { Site } from "@pnp/sp/sites";
import "@pnp/sp/sites";
import { IFetchOptions } from "@pnp/common";
(async () => {
// get site using PnPJs
phillipharding / DisplaySharePointGroupMembers.js
Last active July 13, 2023 17:44
Office 365 -- Get all members of a SharePoint group and show their profile information from the site collections User Information List
(function(window, undefined) {
"use strict";
/**** The following HTML (script) template is placed on the page
<script id="po1persontemplate" type="text/x-custom-template">
<div class='people_details'>
<p class='people_job_title'>{1}</p>
<div class='people_description'>{2}</div>
phillipharding /
Last active July 8, 2023 14:05
Use SPFx to get a Delegated Access Token for a Resource to Pass onto Azure Functions

Use SPFx to get a Delegated Access Token

Note the tokenAcquisitionEvent part of the code doesn't seem to work

Using this technique you can acquire a delegated access token for a resource, SharePoint or the Graph API, and pass that token onto a HTTP triggered Azure Functions endpoint for it to use to call the appropriate API.

This is a simple re-imagination of the on-behalf-of flow involving a secured Azure Functions endpoint then executing an OAuth on-behalf-of flow to exchange the received access token for one which can be used to call an API on behalf of the calling user.

Documented originally by Paolo Pialorsi and Joel Rodrigues

phillipharding / Verify AAD Access Token.js
Last active July 8, 2023 14:04
Verifies an access token issued by the Azure AD identity platform
/** References:
phillipharding / CreateListItemInAnotherSite.js
Created May 30, 2019 13:15
Create a ListItem in another site using the REST API
(async function() {
function getFailedResponseData(response) {
return new Promise( async (resolve) => {
const ct = response.headers.get("Content-Type") || "";
let data = {};
if (ct.match("application/json")) {
data = await response.json();
} else {
phillipharding / Add-ValidateUpdateListItems.js
Last active July 7, 2023 13:49
SharePoint REST API Add/ValidateUpdateListItems
FieldValues =
// Text field (single line and note)
{ FieldName: "TextField", FieldValue: "123" },
// Number field
phillipharding / Toggle SharePoint Recycle Bin
Created April 30, 2023 11:17
Browser Book mark hack to toggle the SP recycle bin
javascript:(function(){var a=new URL(window.location.href);"5"===a.searchParams.get("view")&&(a.hash?a.hash="":a.hash="view=13"),document.location=a.href})();