ODBC Driver for Microsoft Dynamics 365

Build 24.0.9060

Linux DSN Configuration

This section describes how to set up ODBC connectivity and configure DSNs on several Linux distributions: Debian-based systems, like Ubuntu, and Red Hat Linux platforms, like Red Hat Enterprise Linux (RHEL) and Fedora.

Minimum Linux Versions

Here are the minimum supported versions for Red Hat-based and Debian-based systems:

OSMin. Version
Ubuntu18.04
Debian10
RHEL8
Fedora28
SUSE15

Installing the Driver Dependencies

Run the following commands as root or with sudo to install the necessary dependencies:

  • Debian/Ubuntu:
    apt-get install libc6 libstdc++6 zlib1g libgcc1
  • RHEL/Fedora:
    yum install glibc libstdc++ zlib libgcc

Installing the Driver

You can use standard package management systems to install the driver.

On Debian-based systems, like Ubuntu, run the following command with root or sudo:

dpkg -i /path/to/driver/setup/Dynamics365ODBCDriverforUnix.deb 

On systems that support the RPM package format, run the following command with root or sudo:

rpm -ivh /path/to/driver/Dynamics365ODBCDriverforUnix.rpm 

Licensing the Driver

Run the following commands to license the driver. To activate a trial, omit the <key> input.

cd /opt/cdata/cdata-odbc-driver-for-dynamics365/bin/
sudo ./install-license.sh <key>

Connecting through the Driver Manager

The driver manager loads the driver and passes function calls from the application to the driver. You need to register the driver with the driver manager and you define DSNs in the driver manager's configuration files.

The driver installation registers the driver with the unixODBC driver manager and creates a system DSN. The unixODBC driver manager can be used from Python and from many other applications. Your application may embed another driver manager.

Creating the DSN

See Using unixODBC to install unixODBC and configure DSNs. See Using the DataDirect Driver Manager to create a DSN to connect to OBIEE, Informatica, and SAS.

Connecting to Microsoft Dynamics 365

Edition and OrganizationUrl are required connection properties for connection. The Microsoft Dynamics 365 driver supports connecting to the following Microsoft Dynamics 365 editions:

  • CustomerService
  • FieldService
  • FinOpsOnline
  • FinOpsOnPremise
  • HumanResources
  • Marketing
  • ProjectOperations
  • Sales

Note that "Supply Chain Management" is the same as "Finance and Operations." You can connect to it by setting the Edition to either "FinOpsOnline" or "FinOpsOnPremise."

For Microsoft Dynamics 365 Business Central, use the separate Microsoft Dynamics 365 Business Central driver.

OrganizationUrl is the URL to your Microsoft Dynamics 365 organization. For instance, https://orgcb42e1d0.crm.dynamics.com

Authenticating to Microsoft Dynamics 365

OAuth

If required by your organization, Admin Consent is needed when authorizing a new OAuth application for your Azure Tenant. In all OAuth flows, the first time someone in your organization installs and uses an OAuth application, an administrator for the organization must approve the application for their Azure Tenant.

Your organization can choose, however, to disable this requirement.

Desktop Applications

CData provides an embedded OAuth application that simplifies OAuth desktop Authentication. Alternatively, you can create a custom OAuth application. See Creating an Azure AD Application for information about creating custom applications and reasons for doing so.

For authentication, the only difference between the two methods is that you must set two additional connection properties when using custom OAuth applications. After setting the following connection properties, you are ready to connect:

  • AuthScheme: The AzureAD in your application settings.
  • OAuthClientId: (custom applications only) The client Id in your application settings.
  • OAuthClientSecret: (custom applications only) The client secret in your application settings.
  • CallbackURL: The Redirect URL in your application settings.

When you connect the driver opens the OAuth endpoint in your default browser. Log in and grant permissions to the application.

Web Applications

When connecting via a Web application, you need to create and register a custom OAuth application with Microsoft Dynamics 365. See Creating an Azure AD Application for more information about custom applications. You can then use the driver to get and manage the OAuth token values.

Get an OAuth Access Token

Set the following connection properties to obtain the OAuthAccessToken:

  • AuthScheme: AzureAD.
  • OAuthClientId: The client Id in your application settings.
  • OAuthClientSecret: The client secret in your application settings

Then call stored procedures to complete the OAuth exchange:

  1. Call the GetOAuthAuthorizationUrl stored procedure. Set the CallbackURL input to the callback URL you specified in your application settings. If necessary, set the Scope parameter to request custom permissions. The stored procedure returns the URL to the OAuth endpoint.
  2. Open the URL, log in, and authorize the application. You are redirected back to the callback URL.
  3. Call the GetOAuthAccessToken stored procedure. Set the AuthMode input to WEB. Set the Verifier input to the "code" parameter in the query string of the callback URL. If necessary, set the Scope parameter to request custom permissions.

Once you have obtained the access and refresh tokens, you can connect to data and refresh the OAuth access token either automatically or manually.

Automatic Refresh of the OAuth Access Token

To have the driver automatically refresh the OAuth access token, set the following on the first data connection:

  • InitiateOAuth: REFRESH.
  • OAuthClientId: The client Id in your application settings.
  • OAuthClientSecret: The client secret in your application settings.
  • OAuthAccessToken: The access token returned by GetOAuthAccessToken.
  • OAuthRefreshToken: The refresh token returned by GetOAuthAccessToken.
  • OAuthSettingsLocation: The location where the driver saves the OAuth token values, which persist across connections.
On subsequent data connections, the values for OAuthAccessToken and OAuthRefreshToken are taken from OAuthSettingsLocation.

Manual Refresh of the OAuth Access Token

The only value needed to manually refresh the OAuth access token when connecting to data is the OAuth refresh token.

Use the RefreshOAuthAccessToken stored procedure to manually refresh the OAuthAccessToken after the ExpiresIn parameter value returned by GetOAuthAccessToken has elapsed, then set the following connection properties:

  • OAuthClientId: The client Id in your application settings.
  • OAuthClientSecret: The client secret in your application settings.

Then call RefreshOAuthAccessToken with OAuthRefreshToken set to the OAuth refresh token returned by GetOAuthAccessToken. After the new tokens have been retrieved, open a new connection by setting the OAuthAccessToken property to the value returned by RefreshOAuthAccessToken.

Finally, store the OAuth refresh token so that you can use it to manually refresh the OAuth access token after it has expired.

Headless Machines

To configure the driver to use OAuth with a user account on a headless machine, you need to authenticate on another device that has an internet browser.

  1. Choose one of these two options:
    • Option 1: Obtain the OAuthVerifier value as described in "Obtain and Exchange a Verifier Code" below.
    • Option 2: Install the driver on another machine and transfer the OAuth authentication values after you authenticate through the usual browser-based flow, as described in "Transfer OAuth Settings" below.
  2. Then configure the driver to automatically refresh the access token from the headless machine.

You can follow the headless OAuth authentication flow using the OAuth credentials for your custom OAuth app. To create a custom OAuth application, see Creating an Azure AD Application. This section describes the procedure to authenticate and connect to data.

Option 1: Obtain and Exchange a Verifier Code

First, set the following properties on the headless machine:

  • InitiateOAuth: Set to OFF.
  • OAuthClientId: Set to the Client ID in your OAuth Integration settings.
  • OAuthClientSecret: Set to the Client Secret in your OAuth Integration settings.

Next, authenticate from another machine and obtain the OAuthVerifier connection property:

  1. Call the GetOAuthAuthorizationUrl stored procedure. Set the CallbackURL input to the Redirect URI you specified in your application settings. The stored procedure returns the URL to the OAuth endpoint.
  2. Open the returned URL in a browser. Log in and grant permissions to the driver. You are then redirected to the callback URL, which contains the verifier code.
  3. Save the value of the Verifier. You must set the value of the Verifier in the OAuthVerifier connection property.

Finally, on the headless machine, set the following connection properties to obtain the OAuth authentication values:

  • OAuthClientId: Set to the Client ID in your OAuth Integration settings.
  • OAuthClientSecret: Set to the Client Secret in your OAuth Integration settings.
  • OAuthVerifier: Set to the verifier code.
  • OAuthSettingsLocation: Set to persist the encrypted OAuth authentication values to the specified location.
  • InitiateOAuth: Set to REFRESH.

Connect to Data

After the OAuth settings file is generated, set the following properties to connect to data:

  • OAuthSettingsLocation: Set to the location containing the encrypted OAuth authentication values. Make sure this location gives read and write permissions to the provider to enable the automatic refreshing of the access token.
  • InitiateOAuth: Set to REFRESH.

Option 2: Transfer OAuth Settings

To install the driver on another machine, authenticate, and then transfer the resulting OAuth values:

  1. On a second machine, install the driver and connect with the following properties set:
    • OAuthSettingsLocation: Set to a writable location.
    • OAuthClientId: Set to the client ID in your application settings.
    • OAuthClientSecret: Set to the client secret in your application settings.
    • CallbackURL: Set to the callback URL in your application settings.
  2. Test the connection to authenticate. The resulting authentication values are written and encrypted to the path specified by OAuthSettingsLocation. After you have successfully tested the connection, copy the OAuth settings file to your headless machine. On the headless machine, set the following connection properties to connect to data:
    • InitiateOAuth: Set to REFRESH.
    • OAuthSettingsLocation: Set to the location of your OAuth settings file. Make sure this location gives read and write permissions to the driver to enable the automatic refreshing of the access token.

Admin Consent

Admin consent refers to when the Admin for an Azure Active Directory tenant grants permissions to an application which requires an admin to consent to the use case. The embedded application within the CData ODBC Driver for Microsoft Dynamics 365, contains no permissions that require admin consent. Therefore, this information applies only to custom applications.

Admin Consent Permissions

When creating a new OAuth application in the Azure Portal, you must specify which permissions the application requires. Some permissions may be marked stating "Admin Consent Required". For example, all Groups permissions require Admin Consent. If your application requires admin consent, there are a couple of ways this can be done.

The easiest way to grant admin consent is to just have an admin log into portal.azure.com and navigate to the application you have created in App Registrations. Under API Permissions, click Grant Consent, which grants your application the necessary permissions on the tenant on which it was created.

If your organization has multiple tenants or the application needs to be granted permissions for other tenants outside your organization, you can use the GetAdminConsentURL to generate the Admin Authorization URL. Unlike the GetOAuthAuthorizationUrl, there is no important information returned from this endpoint. If the tenant grants access, it returns a boolean indicating that permissions were granted.

After an admin grants consent, authentication may be performed as normal.

Client Credentials

Client credentials refers to a flow in OAuth where there is no direct user authentication taking place. Instead, credentials are created for just the application itself. All tasks taken by the application are done without a default user context. This makes the authentication flow a bit different from standard.

Client OAuth Flow

All permissions related to the client oauth flow require admin consent. This means the application embedded with the CData ODBC Driver for Microsoft Dynamics 365 cannot be used in the client oauth flow. You must create your own OAuth application to use client credentials. See Creating an Azure AD Application for more details.

In "App Registration" in portal.azure.com, navigate to API Permissions and select the Microsoft Graph permissions. There are two distinct sets of permissions - Delegated and Application permissions. The permissions used during client credential authentication are under Application Permissions. Select the applicable permissions you require for your integration.

You are ready to connect after setting one of the below connection properties groups depending on the authentication type.

  1. Client Secret
    • InitiateOAuth: GETANDREFRESH. You can use InitiateOAuth to avoid repeating the OAuth exchange and manually setting the OAuthAccessToken.
    • AzureTenant: The tenant you wish to connect to.
    • OAuthGrantType: CLIENT.
    • OAuthClientId: The client Id in your app settings.
    • OAuthClientSecret: The client secret in your app settings.
  2. Certificate
    • InitiateOAuth: GETANDREFRESH. You can use InitiateOAuth to avoid repeating the OAuth exchange and manually setting the OAuthAccessToken.
    • AzureTenant: The tenant you wish to connect to.
    • OAuthGrantType: CLIENT.
    • OAuthClientId: The client Id in your app settings.
    • OAuthJWTCert: The JWT Certificate store.
    • OAuthJWTCertType: The type of the certificate store specified by OAuthJWTCert.

Azure AD

Azure AD is a connection type that leverages OAuth to authenticate. Set your AuthScheme to AzureAD.

Follow the steps below to authenticate with the credentials for a custom AzureAD app. See Creating an Azure AD Application.

There are two types of app authentication available: using a client secret and using a certificate. You can use any of them depending on the configured app authentication.

Get an AzureAD Access Token

You are ready to connect after setting one of the below connection properties groups depending on the authentication type.

  1. Client Secret
    • AuthScheme: AzureServicePrincipal in your app settings.
    • InitiateOAuth: GETANDREFRESH. You can use InitiateOAuth to avoid repeating the AzureAD exchange and manually setting the OAuthAccessToken.
    • AzureTenant: The tenant you wish to connect to.
    • OAuthClientId: The Client Id in your app settings.
    • OAuthClientSecret: The client secret in your app settings.
  2. Certificate
    • AuthScheme: The AzureServicePrincipal in your app settings.
    • InitiateOAuth: GETANDREFRESH. You can use InitiateAzureAD to avoid repeating the AzureAD exchange and manually setting the OAuthAccessToken.
    • AzureTenant: The tenant you wish to connect to.
    • OAuthClientId: The client Id in your app settings.
    • OAuthJWTCert: The JWT Certificate store.
    • OAuthJWTCertType: The type of the certificate store specified by OAuthJWTCert.

Azure Service Principal

The authentication as an Azure Service Principal is handled via the OAuth Client Credentials flow. It does not involve direct user authentication. Instead, credentials are created for just the application itself. All tasks taken by the app are done without a default user context, but based on the assigned roles. The application access to the resources is controlled through the assigned roles' permissions. Create an AzureAD App and an Azure Service Principal When authenticating using an Azure Service Principal, you must register an application with an Azure AD tenant. See Creating a Custom AzureAD Service Principal App for more information.

Assign a role to the application

To access resources in your subscription, you must assign a role to the application.

  1. Open the Subscriptions page by searching and selecting the Subscriptions service from the search bar.
  2. Select the subscription to assign the application to.
  3. Open the Access control (IAM) and select Add > Add role assignment to open the Add role assignment page.
  4. Select Owner as the role to assign to your created Azure AD app.
Complete the Authentication

To connect follow these steps:

  1. Set the AuthScheme to AzureServicePrincipal for using a client secret or AzureServicePrincipalCert for using a certificate in your application setting.
  2. Set the connection properties that apply to both schemes.
  3. Set the connection properties specific to the authentication scheme you selected.

For Both Client Secret and Certificate

Set these connection properties and then continue to the relevant section below:

  • InitiateOAuth: GETANDREFRESH. You can use InitiateOAuth to avoid repeating the OAuth exchange and manually setting the OAuthAccessToken.
  • AzureTenant: The tenant you want to connect to.
Client Secret

Continue with the following:

  • OAuthClientId: The client Id in your application settings.
  • OAuthClientSecret: The client secret in your application settings.

Certificate

Continue with the following:

  • OAuthJWTCert: The JWT Certificate store.
  • OAuthJWTCertType: The type of the certificate store specified by OAuthJWTCert.

Refreshing OAuth Values

The driver can refresh the temporary OAuth access tokens obtained during the browser-based OAuth authentication exchange. By default, the driver saves the encrypted tokens in the odbc.ini file corresponding to the DSN. Access to this odbc.ini file can be restricted in the case of System DSNs.

To enable the automatic token exchange, you can give the driver write access to the system odbc.ini. Or, you can set the OAuthSettingsLocation connection property to an alternate file path, to which the driver would have read and write access.

    OAuthSettingsLocation=/tmp/oauthsettings.txt
    

Installing Dependencies for OAuth Authentication

The OAuth authentication standard requires the authenticating user to interact with Microsoft Dynamics 365, using a web-browser. If the first OAuth interaction is to be done on the same machine the driver is installed on, for example, a desktop application, the driver needs access to the xdg-open program, which opens the default browser.

To satisfy this dependency, install the corresponding package with your package manager:

Debian/Ubuntu PackageRHEL/Fedora PackageFile
xdg-utilsxdg-utilsxdg-open

Set the Driver Encoding

The ODBC drivers need to specify which encoding to use with the ODBC Driver Manager. By default, the CData ODBC Drivers for Unix are configured to use UTF-16 which is compatible with unixODBC, but other Driver Managers may require alternative encoding.

Alternatively, if you are using the ODBC driver from an application that uses the ANSI ODBC API it may be necessary to set the ANSI code page. For example, to import Japanese characters in an ANSI application, you can specify the code page in the config file '/opt/cdata/cdata-odbc-driver-for-dynamics365/lib/cdata.odbc.dynamics365.ini':

[Driver]
AnsiCodePage = 932

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 24.0.9060