My “step by step” guide for implementing OData API authorisation in Business Central v17.x (Part 1)

ODATA

Good news: the medieval webkey authentication for Business Central API has finally been deprecated.

In this first article I am going to present a little overview of the secure and modern OAuth protocol with a “delegated permission” sample.

In next article I will describe an “Application permissions” implementation for an application that runs as a background service or daemon without a signed-in user. I am going to describe how I refactored an existing Xamarin mobile application that is currently directly getting and posting data to Business Central APIs.

IT’S TIME TO MOVE TO AZURE

Login in Azure Portal https://portal.azure.com/ , go to “All Services”, search “App Registration” and select “App registrations” list item.

Create a new registration.

Configure your application registration name and the redirect URI As Web with the URL “https://businesscentral.dynamics.com/”.

Or even better “https://businesscentral.dynamics.com/OAuthLanding.htm

Note down the “Application (client) ID” GUID, this is the “CLIENT ID” we are going to use in Insomia.

Select “API permission” blade,

Configure as in picture.

Go the “Certificate and secrets” blade.

Add a new “Client secret”

The “Client secret” and “Secret ID” will be generated,

Please notice that the “Client secret” is shown in clear text ONLY after the first generation and it will NEVER EVER be shown again. If lost you will need to generate a new one. There is not way to recover an existing “Client secret”.

Copy the “Value”, we are going to use it in Insomia as “CLIENT SECRET”.

TEST WITH INSOMNIA

Here are all mandatory parameters to make an OATH request:

Token-Name: Give the appropriate Token Name
Grant Type: Authorization Code

Callback URL: https://businesscentral.dynamics.com/

Auth URL:
https://login.windows.net/<tenant_id>/oauth2/authorize?resource=https://api.businesscentral.dynamics.com
Access Token URL:
https://login.windows.net/<tenant_id>/oauth2/token?resource=https://api.businesscentral.dynamics.com

Client ID: Client ID as in “ID” column in azure
Client Secret: Client Secret Value as in “Value” column in azure.

By using Insomnia you easily test the API:

The well known Microsoft Azure AD web page appears asking for the username.

And the password.. and it’s done.

SOURCES

Olisterr Tech blog

https://www.olisterr.tech/2020/12/setting-up-oauth-authentication-for.html

Arend-Jan Kauffmann

LAST UPDATED

24th of December, 2020

3 thoughts on “My “step by step” guide for implementing OData API authorisation in Business Central v17.x (Part 1)

  1. What about Grant Type as Client Credentials? It’s useless Grant Type as Authorization Code because you cannot automate between two applications

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s