Skip to content

Instantly share code, notes, and snippets.

Avatar

Phil Harding phillipharding

View GitHub Profile
@phillipharding
phillipharding / Toggle SharePoint Recycle Bin
Created April 30, 2023 11:17
Browser Book mark hack to toggle the SP recycle bin
View Toggle SharePoint 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 April 21, 2022 15:52
Verifies an access token issued by the Azure AD identity platform
View Verify AAD Access Token.js
/** 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 12, 2021 14:45
Create/Ensure a SharePoint folder path with nested folders using PnPJS
View Ensure a SharePoint Folder Path using PnPJS.ts
/*
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
View Renew Expired SharePoint ACS ClientSecret.ps1
<#
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
View camlify-filter-expressions.js
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 22, 2021 14:20
Use SPFx to get a Delegated Access Token for a Resource to Pass onto Azure Functions
View spfx-get-delegated-accesstoken.md

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 May 8, 2023 13:25
Generate an Azure AD Access Token using the Client Credentials flow with a Certificate Secret to use for calling the SharePoint REST API
View Azure AD Token using Certificate Secret.md
@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
View SharePoint PnPJS Parallel ListItem Update with Retry v2
/*
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
View Add and Enumerate List Folder PropertyBag Values.ts
/*
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">
@phillipharding
phillipharding / Add-ValidateUpdateListItems.js
Last active May 12, 2023 00:50
SharePoint REST API Add/ValidateUpdateListItems
View Add-ValidateUpdateListItems.js
See:
- https://robertschouten.com/2018/04/30/update-file-metadata-with-rest-api-using-validateupdatelistitem-method/
- http://blog.arvosys.com/2018/07/06/list-items-system-update-options-in-sharepoint-online/index.html
FieldValues =
[
// Text field (single line and note)
{ FieldName: "TextField", FieldValue: "123" },
// Number field