Using Office 365 Public CDN in SharePoint Online

In the void – bytes counts. You think that’s air you’re breathing? The Appsters wanted to improve their solution by using the public CDN functionality in SharePoint Online. It’s pretty easy to enable in a tenant. I recommend this  Office Dev Center guide for how to do it, and I’m not going into details of exactly that here.

What it does is that enables a library/folder of your choice to be reached from Office 365 using a specific path on the format<tenant host name>/<ID of the public CDN origin>/<sub-path under the origin>

The Appsters’ public CDN URL is

We wanted to share how we work with the Public CDN and Office PnP templates. We are incorporating this into our solution using the CDN URL as a parameter into our pnp-templates.

We are then able to use the parameter when specifying the URL to our JavaScript and CSS files (Of course we’re not referencing every single file – we use a JavaScript script-loader that uses the Sod-functionality to load dependencies (but that’s for another blog post :)). As an example, take a look at how we reference the script-loader from a custom action:

And for the site logo:

And with Chrome Source explorer you can see that our files are loaded from the CDN.

We’re using the public CDN for all of our JavaScript-files, CSS-files, images and logos etc. The only limitation we’ve hit so far is that Office PnP parameters doesn’t work in .spfont files, unfortunately needing us to have the CDN-URL multiple places.

That’s it – happy coding!

How to trigger an Azure web job using the web hook from a flow

I spent some time to figure this out, so thought I would share.

We have a web job in Azure that runs a PowerShell-script that polls a list looking for new items, picks them up, creates a site collection and applies pnp templates. This works really well as a scheduled job, but it would be nicer if we could trigger the job automatically so we don’t have to wait for the scheduled start time.

It turns out that you can do this with the new Flow! Steps as follows:

  1. First you need the authentication tokens. Go to your App Service where you have the web job running, and click on Get publish profile 
  2. In that file, look for the publishprofile with publishMethod=”MSDeploy”. You need the userName and userPwd. E.g. in my case it was userName=”$ASPC2017″ userPWD=”LBxk5ttrvZTgAM7msxDGRZA0hy9Wws3gdNeuK33hacB52SSaAQRslmuzshzi”
  3. Then you need the web hook url. You find that by selecting your web job and clicking on properties.
  4. Go to the list from where you want to trigger the web job and create a new flow.
  5. The first step is to add a SharePoint action for “when an item is created”, and give the url to your site and your list as input.
  6. The next step is to add an HTTP-action. Choose method POST, add the Uri to the web hook url. You don’t need to set headers and body. Choose Basic authentication and use the username and password from step 2.
  7. The final flow should look like the following

That’s it! After an item is added to the list, your web job will trigger and start running. Happy coding!

How to consent to an Office 365 service app

Many times you might want to create services which interact with the Microsoft Graph. If your application has an actual web page you will get prompted when you visit and login to do the actual consent. If you have elevated privileges you would tack on &prompt=admin_consent to the URL and then your service can authenticate and do what you need it to.

If you just create an Office 365 entry and have no web application tied to it, this is not automatic.

One approach to get the consent URL is to create a small c# app using ADAL.

string ResourceId = ""; // Microsoft Graph End-point
Uri RedirectUri = new Uri("[APP ID URI]");
ClientId = "[O365 App ClientId]";
ClientSecret = "[O365 App ClientSecret]";

var authenticationContext = new AuthenticationContext("");
var url = await authenticationContext.GetAuthorizationRequestUrlAsync(ResourceId, ClientId, RedirectUri, UserIdentifier.AnyUser, "prompt=admin_consent");

If you have a multi-tenant app, the above code has to be ran per tenant where the service will act against.

Pro tip for triggering Microsoft Flow’s from code

As the trigger action pick an HTTP Request action.



Then head over to to generate the swagger JSON schema needed. Just enter your JSON object, any way you want, click generate schema, and copy paste the output into the Flow action.


Your object properties are now available to use in a new action, as the one picture below where we create a new CRM record.



Once you save your Flow, you can copy the endpoint URL and do a POST with your JSON object to that andpoint and you’re ready to roll Smile