---
title: Dynamics 365 (On-Premise)
slug: sidebar-gmail/dynamics-365-on-premise
description: Connect Unaric Sidebar for Gmail to Dynamics 365 on-premise to log emails and view CRM data inside Gmail.
image: https://archbee-image-uploads.s3.amazonaws.com/10Nod6Ww95R3dPr0k0TCJ/1SaGPkjEcVhINFJVWABUe_unaric-sidebar.png
docTags: 
createdAt: 2025-12-10T23:43:46.176Z
---

This page explains how to configure a connection to an on-premise instance of Microsoft Dynamics 365 using Active Directory Federation Services and OAuth2 authentication.

These instructions apply specifically to internet-facing deployments (IFD), where both Dynamics 365 and ADFS are accessible externally. You’ll set up an OAuth client, grant the required permissions, and configure token settings to enable secure communication between the connector and your Dynamics environment.

:::hint{type="warning"}
This instruction is for internet facing installation. Your Dynamics and ADFS need to be publicly reachable, otherwise, the connector won’t work.
:::

## Prerequisites

To connect to Dynamics 365 On-premise installation, you will need to provide:

- Dynamics 365 On-premise base URL
- ADFS base URL
- ADFS oAuth2 client id

## Create oAuth2 client in ADFS using PowerShell&#x20;

### 1. Register new client application to use with Unaric Sidebar

You need to create separate clients for **Unaric Sidebar add-on** and **Automatic sync**, depends on what you are using.

- [Re-direct URI for G-Suite add-on](https://script.google.com/macros/d/17V0Pk2A7VTevuNUbsgXMCnfgYIvN6pblZduRWjLNoNDlw5SzIem3o0Hi/usercallback)
- [Re-direct URI for Automatic sync](https://isync.ienterprises.com/oauth2client/mscrm.php)

To register a new oAuth2 client, run the following from the Administrative PowerShell prompt:

```powershell
Add-ADFSClient -Name "oAuth2 Client name here" -ClientId "some uid here" -RedirectUri "re-direct uri here"
```

Replace `some uid` with your client id. Use this client id in connection settings.

:::hint{type="info"}
For more information on this process, see Microsoft documentation, [Add-AdfsClient](https://docs.microsoft.com/en-us/powershell/module/adfs/add-adfsclient).
:::

### 2. Grant application permission to CRM

:::::Tabs
::::Tab{title="Windows Server 2016 and later"}
Grant Application permission to ADFS clients with the required scope(s), by running the following from Administrative PowerShell prompt :

```powershell
Grant-AdfsApplicationPermission -ClientRoleIdentifier "clientid" -ServerRoleIdentifier "Dynamics URI" -ScopeNames openid, user_impersonation
```

:::hint{type="info"}
For more information on this process, see Microsoft documentation, [Grant-AdfsApplicationPermission](https://docs.microsoft.com/en-us/powershell/module/adfs/grant-adfsapplicationpermission).
:::
::::

:::Tab{title="For ADFS 3.0 on Windows Server 2012 R2"}
1. Go to ADFS Management.
2. Expand ADFS > Trust Relationships > Relying Party Trusts.
3. Use the Add Relying Party Trust Wizard.
4. Create a Relying party manually and Permit all users to access this relying party.
:::
:::::

## Obtain refresh tokens from ADFS

Refresh tokens are needed from ADFS to keep the login active. To set them, run the following from an Administrative PowerShell prompt:

```powershell
Set-AdfsRelyingPartyTrust -TargetName "RPT Name" -IssueOAuthRefreshTokensTo AllDevices
Set-AdfsRelyingPartyTrust -TargetName "RPT Name" -TokenLifetime 10
Set-AdfsProperties -SSOLifetime 20160
```

This would issue access tokens with a lifetime of 10 minutes and refresh tokens to all clients with a lifetime of 14 days.

:::hint{type="info"}
For more information on this process, see Microsoft documentation, [Set-AdfsRelyingPartyTrust](https://docs.microsoft.com/en-us/powershell/module/adfs/set-adfsrelyingpartytrust) and [Set-AdfsRelyingPartyTrust](https://docs.microsoft.com/en-us/powershell/module/adfs/set-adfsproperties).
:::

<u></u>

