Skip to content

File Picker Set Up

r-a-y edited this page May 10, 2021 · 1 revision

In order for your users to select files from their own OneDrive account, you will need to register an app with Microsoft Azure.

  1. Sign in to Microsoft Azure and create a new Registration here: https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade

    • When creating your registration, under Supported account types, select the account type you wish to allow on your site.
    • For the majority of sites, Personal Microsoft accounts only should be sufficient.
    • If your site uses an enterprise version of OneDrive (eg. SharePoint), you will want to select an option that allows for multitenant. It is important to note that only Word, Powerpoint, Excel and Visio files can be embedded natively with an enterprise version of OneDrive. All other drive items will display an icon of the file. For more info, see https://github.com/hwdsb/onedrive/issues/1.
    • For Redirect URI, you will want to add the following URL: https://example.com/wp-content/plugins/onedrive/picker.html
      (Replace example.com with your domain)
  2. Your app should now be registered. On the Overview page, you should see the Application (client) ID. Copy that value and in your wp-config.php file, enter:

    define( 'HWDSB_ONEDRIVE_CLIENT_ID', PASTE_YOUR_APP_ID_HERE );

    If you plan to use this with solely an enterprise version of OneDrive, you will also need to add the following entry to your wp-config.php file:

    define( 'HWDSB_ONEDRIVE_SHARE_TYPE', 'view' );

  3. Now we'll want to set the app's authentication options. You can do that by clicking on Authentication in the left sidebar. Under Implicit grant and hybrid flows, ensure both Access tokens and ID tokens are checked and click on the "Save" button.

  4. Next, we'll want to create a client secret. You can do that by clicking on Certificates & secrets located in the left sidebar and clicking on the New client secret button.

    • Here, you can add a description for your client secret and you can set the date when the client secret should expire. Depending on your security level, you might want to set a long expiry date so you will not have to change the client secret that often.
    • Once the client secret is created, copy it from the Value table column and note it down somewhere. Next, add the client secret to your wp-config.php:
      define( 'HWDSB_ONEDRIVE_CLIENT_SECRET, PASTE_YOUR_SECRET_VALUE_HERE );
  5. Now, when writing a post in the Block Editor, you can select the OneDrive block and an Or Select From Drive button should appear. Your users can now click on that button to login to their OneDrive account and select a file for embedding.

Clone this wiki locally