Skip to main content

OAuth 2.0 Applications and Storage Setup​

This page describes how to let ExFlow store incoming document attachments in SharePoint (or an Azure Blob Container) instead of in the Business Central database.

For support regarding below, please contact the internal IT department or trusted Business Central partner.

Overview of the setup​

  1. Register an application in Microsoft Entra and give it access to SharePoint.
  2. Create an OAuth 2.0 Application in ExFlow that uses the Entra application to get an access token.
  3. Prepare a SharePoint folder and create a Storage Setup in ExFlow that points to it.
  4. Activate Blob Storage so ExFlow starts moving documents.

For an Azure Blob Container, steps 1 and 2 are not needed. See Blob Storage Setup for Azure Container.

Values to copy from Microsoft Entra​

Keep these at hand, they are needed in step 2:

ValueUsed in ExFlow field
Application (client) IDApplication / Client ID
Client secret (value)Client Secret
OAuth 2.0 token endpoint (v2)Access Token URL
OAuth 2.0 authorization endpoint (v2)Authorization URL
Microsoft Graph API endpointScope (as https://graph.microsoft.com/.default)

Create Application or Service Principal in MS Entra (or Azure)​

In the Microsoft Entra admin center, go to App registrations and select New registration. Enter a name of choice, select Accounts in any organizational directory and then select Register.

Register a new application in Microsoft Entra

After registration, copy the Application (client) ID.

Application (client) ID on the app overview

Go to API permissions and select Add a permission.

API permissions page

Select Microsoft Graph and Application permissions.
Search for "site" and add the permission Sites.ReadWrite.All.

Add Microsoft Graph Sites.ReadWrite.All permission

Select Add a permission again, then SharePoint and Application permissions.
Select and add both permissions: Sites.ReadWrite.All and Sites.Manage.All.

Add SharePoint permissions

Select Grant admin consent for these permissions:

Grant admin consent

The permissions should look like this:

Configured permissions

Go to Certificates & secrets.

Certificates & secrets

Create a new client secret:

Create a client secret

Copy the secret Value right away and store it safely. It is only shown once. If the secret is lost or expires, create a new secret and enter it in the OAuth 2.0 Application in ExFlow.

Copy the client secret value

Go back to the list of App registrations and select Endpoints. Copy the OAuth 2.0 authorization endpoint (v2), the OAuth 2.0 token endpoint (v2) and the Microsoft Graph API endpoint.


App registration endpoints

The setup in Microsoft Entra is now complete.

Configure an OAuth2 Application in ExFlow​

Go to: ExFlow Setup --> Actions --> Functions --> OAuth2 Applications

Select New to create a new OAuth 2.0 Application.

OAuth 2.0 Applications list

OAuth 2.0 Application card

Fill in the fields as follows:

General
CodeA short code of choice that identifies this application, for example SHAREPOINT.
DescriptionA description of the application.
Application / Client IDPaste the Application (client) ID from Microsoft Entra.
Client SecretPaste the client secret value from Microsoft Entra. The value is stored securely and shown as asterisks.
Grant TypeSelect Client Credentials. This is the grant type to use for SharePoint storage. (Authorization Code and Password Credentials are also available. Password Credentials shows extra User Name and Password fields.)
Redirect URLLeave empty. Only used with the Authorization Code grant type.
ScopeEnter https://graph.microsoft.com/.default (the Microsoft Graph API endpoint followed by .default).

Endpoints
Authorization URLPaste the OAuth 2.0 authorization endpoint (v2). Only used with the Authorization Code grant type, but can be filled in anyway.
Access Token URLPaste the OAuth 2.0 token endpoint (v2). Required.
Auth. URL ParmsLeave empty. Only used with the Authorization Code grant type.

Both URLs must start with https://.

OAuth 2.0 Application filled in

Test the setup by selecting Request Access Token. With Client Credentials, no login is prompted. If everything is correct, the message "Access Token updated successfully." is shown and Status on the OAuth 2.0 Applications list is set to Connected. If something is wrong, the error from Microsoft is shown and Status is set to Error.

Actions
Request Access TokenGets a new access token using the settings on the card. Use this to test the setup.
Refresh Access TokenRefreshes the access token using a refresh token. Not used with Client Credentials, since no refresh token is issued. ExFlow requests a new token automatically when the old one expires.

SharePoint Setup​

In SharePoint, go to Site contents and create a new Document library. Then create a folder in the new document library. ExFlow stores the documents in this folder.

Open the newly created folder and copy the complete URL from the browser's address field. The URL is needed in the Storage Setup below.

Note: Make sure the URL is copied after opening the folder. The folder name is read from the ?id=... part of that URL. If only the URL of the document library is copied, the folder must be entered manually.

Storage Setup​

Go to: ExFlow Setup --> Actions --> Functions --> Blob Storage Mgmt (the page ExFlow Storage Management Setup).

Select Storage Setup and then New.

ExFlow Storage Setup

Enter a Code and Description. For Blob Source, select SharePoint.

Then select Setup Storage to open the SharePoint Setup.

SharePoint Setup page

Paste the URL copied from SharePoint into the field SharePoint Url. When leaving the field, the values for Host, Site, Document Library and Folder are filled in automatically. If a value is missing (most often Folder), enter it manually.

SharePoint Setup with values filled in

Note: If the SharePoint Url is changed later, a confirmation is required. All SharePoint values are then cleared and read again from the new URL, and the connection must be tested again.

In OAuth2 Application Code, select the OAuth 2.0 Application created earlier, and select Connect to test the connection.

If all is OK, SharePoint Connection Status is set to Connected, and Site Id, Drive Id and List Id are filled in.

If the connection fails, the error from SharePoint is shown, for example:

MessageMost likely cause
Not FoundThe site or document library name is wrong.
Unauthorized or ForbiddenThe API permissions are missing or admin consent has not been granted in Microsoft Entra.

SharePoint Connection Status
DisconnectedThe connection has not been tested yet.
RevalidateA setting has changed since the last test. Select Connect again.
ConnectedThe connection has been tested successfully.

Close the SharePoint Setup page. On the ExFlow Storage Setup page, select Enable / Disable so that Enabled is turned on. This is only possible when SharePoint Connection Status is Connected.

Storage Setup enabled

Close ExFlow Storage Setup and return to ExFlow Storage Management Setup.

Activate Blob Storage​

On ExFlow Storage Management Setup, select the new storage setup in Incoming Doc. Storage Code.

Select Incoming Doc. Storage Code

Check Blob Name Structure before continuing. The default, Split String 2 Char 3 Levels, is recommended. Blob Name Structure and Incoming Doc. Storage Code cannot be changed while Blob Storage is active.

Turn on Active, or select Enable/Disable Blob Storage.

Activate Blob Storage

If there are posted invoices or credit memos in ExFlow, ExFlow asks to add them to blob storage. Select Yes to continue. Selecting No cancels the activation.

When Blob Storage is activated, ExFlow creates the job queue entry ExFlow Blob Storage Job - Recurring (category EXFLOW). It runs every 60 minutes between 08:00 and 17:00 and moves documents to storage. Read more under Job Queues.

To check the status of posted invoices in blob storage, select Actions --> Storage Details.

To move documents to storage right away instead of waiting for the job queue, select Sync Storage.

Storage Details and Sync Storage

Refresh the SharePoint folder in the browser. The new folders created by ExFlow should now be visible.

Folders created by ExFlow in SharePoint

Deactivating Blob Storage: If Active is turned off again, a confirmation is required. All documents stored in blob storage are then restored to the Business Central database, and the storage cache and cross references are cleared. This can take some time if there are many documents.

Blob Storage Setup for Azure Container​

The setup for an Azure Blob Container is similar to SharePoint, but does not use an OAuth 2.0 Application.

Go to: ExFlow Setup --> Actions --> Functions --> Blob Storage Mgmt, select Storage Setup and create a new setup with Blob Source set to Azure Container. Then select Setup Storage to configure the Azure Blob Container settings.

Azure Container Setup
Storage AccountName of the Azure Storage Account. Must be between 3 and 24 characters.
Container NameName of the container in the Storage Account. Must be between 3 and 63 characters.
Shared Access KeyThe access key found under the Azure Storage Account's Access keys in the Azure portal. The key is kept in isolated storage and is shown as ********** once saved. Clear the field to delete the key.
TestChecks that the settings are valid and that the container exists. The message "Azure Blob Container settings OK" is shown if all is OK.

If the test fails, one of these messages is shown:

MessageMost likely cause
Azure Shared Account Key missingShared Access Key is empty.
Unable to fetch list of containers, please review settingsStorage Account or Shared Access Key is wrong.
Container does not exist, please review settingsContainer Name is wrong, or the container has not been created in Azure.

When the test is OK, go back to ExFlow Storage Setup, select Enable / Disable so that Enabled is turned on, and continue in the same way as for SharePoint: select the setup in Incoming Doc. Storage Code and activate Blob Storage.

For details on working with Azure Blob Containers, please go to Microsoft Learn Introduction to Azure Blob Storage.

Reference: ExFlow Storage Management Setup​

Actions
Storage SetupConfigure one or more storage setups (SharePoint or Azure Container).
Enable/Disable Blob StorageActivate or deactivate blob storage. Same as the Active field.
Storage DetailsShows cached entries and cross reference entries.
Sync StorageRuns the same transfer as the job queue, right away.
Manually Add All Posted Documents to CacheAdds all incoming documents linked to ExFlow posted documents to the storage cache.
Manually Restore All Posted Incoming From CacheRestores all incoming documents linked to ExFlow posted documents from storage back to the database.

General
Cache in DaysSpecifies how many days cached content remains in Business Central. After the specified number of days, the content is removed from local storage. Recommended to set 60 days.
Batch SizeSet to 0 to transfer all documents in one batch during sync. Set to a value above 0 to transfer only that many documents per sync. Applies both to the job queue and to Sync Storage.
Blob Name StructureSpecifies the naming convention used for the path to blobs. Split String 2 Char 3 Levels (default and recommended) splits the name into a path like ab/cd/ef/abcdefgh. As-Is uses the name without splitting. Cannot be changed while Blob Storage is active.
ActiveEnables Blob Storage. Requires Incoming Doc. Storage Code to be filled in.

Storage Codes
Incoming Doc. Storage CodeThe storage setup used for incoming document attachments of ExFlow posted documents. File names, folder structure and retrieval are handled by ExFlow. Cannot be changed while Blob Storage is active.
General Blob Storage CodeThe storage setup used by the general Blob Storage API. Only needed for partner/developer extensions, see below.

For partners and developers: When General Blob Storage Code is set to a storage setup (this can be the same as for Incoming Doc. Storage Code), the file API in codeunit BSApi (Blob Storage API) can be used. It works like a file system where files can be written and read, and the developer controls names and structure. The Blob Storage for incoming document attachments uses the same BSApi internally.