Skip to content

Instantly share code, notes, and snippets.

View phillipharding's full-sized avatar

Phil Harding phillipharding

View GitHub Profile
@phillipharding
phillipharding / Upgrading a Functions App and Code-base to the v4 Runtime.md
Created November 15, 2023 15:13
Upgrading a Functions App and Code-base to the v4 Runtime
@phillipharding
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})();
@phillipharding
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:
* https://www.npmjs.com/package/azure-ad-verify-token
* https://github.com/justinlettau/azure-ad-verify-token
* https://liangjunjiang.medium.com/verify-and-decode-azure-activity-directory-token-bc72cf7010bc
* https://liangjunjiang.medium.com/azure-active-directory-api-v1-0-vs-v2-0-5c75fb2b1154
* https://www.npmjs.com/package/jwks-rsa
* https://www.npmjs.com/package/jsonwebtoken
* https://www.voitanos.io/blog/validating-azure-ad-generated-oauth-tokens
*
* NOTE:
@phillipharding
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};
@phillipharding
phillipharding / Renew Expired SharePoint ACS ClientSecret.ps1
Last active October 26, 2022 11:04
Renews an Expired ClientSecret for a Sharepoint Addin/ACS App Registration
<#
Renew An Expired Clientsecret For A Sharepoint Addin/ACS App Registration
WHEN A SHAREPOINT ADDIN/ACS APP REGISTRATION IS CREATED THE CLIENTSECRET IS SET TO EXPIRE IN 1 YEAR
THIS SCRIPT WILL RENEW AN EXPIRED CLIENTSECRET WITH A VALUE THAT EXPIRES IN 3 YEARS
.\msol-renewsharepointaddinsecret.ps1 -clientId "" -userName "" -userPassword ""
#>
param (
@phillipharding
phillipharding / camlify-filter-expressions.js
Created September 6, 2021 11:37
Camlify Filter Expressions
console.clear();
const isEmptyString = (s) => { return (typeof s === "undefined") || (s === null) || (s.length < 1); };
camlCompareOp = "Or";
camlPredicate = "Contains";
options = {};
options.queryByUniqueIdentifier = "90911";
//options.queryByPayrollNumber = "90919";
//options.queryByLocation = "01-001";
@phillipharding
phillipharding / spfx-get-delegated-accesstoken.md
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
phillipharding / Azure AD Token using Certificate Secret.md
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
phillipharding / SharePoint PnPJS Parallel ListItem Update with Retry v2
Last active February 14, 2021 14:19
Better version of updating a SharePoint listitem in parallel using PnPJS with retry capability if error 409 (item has been updated by another user or process) occurs
/*
Hit 'ctrl + d' or 'cmd + d' to run the code, view console for results
*/
import { sp } from "@pnp/sp/presets/all";
( async () => {
console.clear();
const itemId = 89;
const RetryHttpCall = async (fnToCall: () => Promise<any>, label: string, maxTryCount: number): Promise<any> => {
@phillipharding
phillipharding / Add and Enumerate List Folder PropertyBag Values.ts
Last active February 18, 2021 16:51
Add/Set and List PropertyBag Values for a List Folder
/*
Hit 'ctrl + d' or 'cmd + d' to run the code, view console for results
*/
import { spPost, SharePointQueryable } from '@pnp/sp';
import { sp } from "@pnp/sp/presets/all";
const getBody = (siteid, webid, listid, folderid, propertyName, propertyValue) => `
<Request AddExpandoFieldTypeSuffix="true" ApplicationName=".NET Library" LibraryVersion="16.0.0.0" SchemaVersion="15.0.0.0" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009">
<Actions>
<Method Id="62" Name="SetFieldValue" ObjectPathId="59">