Overview
Riva Cloud can connect to Microsoft Dynamics 365 Customer Engagement (on-premises) version 9.1 when it is set up as described in this article. On-premises installations can differ in small ways that affect sign-in and sync, so Riva supports one reference configuration that we build and test against ourselves.
If your environment matches this configuration, Riva Support can help you set up and troubleshoot your connection. If your environment differs, the connection may still work, but we can't guarantee it.
This article is for the Dynamics and Windows administrators who maintain your on-premises environment. Share it with them before you create your connection in Riva Cloud.
Supported versions
| Component | Supported version |
|---|---|
| Dynamics 365 Customer Engagement (on-premises) | 9.1 |
| Identity provider | Active Directory Federation Services (AD FS) 2019 |
| Database | SQL Server 2019 |
| Directory | Active Directory (single forest) with DNS |
| Server operating system | Windows Server 2019 |
Install each component following Microsoft's standard documentation (linked at the end of this article). Riva does not support Dynamics on-premises versions earlier than 9.1 or identity providers other than AD FS.
Environment and authentication setup
Your environment needs these pieces, configured as described.
Active Directory
- One or more domain controllers running DNS. AWS Managed Microsoft AD is also supported.
- A single AD forest with an added, routable UPN suffix (for example,
yourcompany.com), so every user has a routable user principal name (UPN).
AD FS 2019
Install AD FS on its own server (for example, adfs.yourcompany.com). Then create one application group containing:
- A server application. This is the application Riva authenticates against. When you create it, AD FS generates a client ID and a client secret. Save both: you'll enter them when you create your connection in Riva Admin Center.
-
A Web API application whose identifier is your Dynamics relying party identifier. Grant the server application these permissions (scopes) on it:
openidprofile-
offline_access(required for refresh tokens) user_impersonationallatclaims
Claim rules on the Web API application
Dynamics 9.1 uses the upn claim to match a token to a CRM user. If the token has no UPN, Dynamics rejects the request with a 401 error. Add these two Issuance Transform Rules using the "Send Claims Using a Custom Rule" template, in this order:
Rule 1 gets the user's UPN from Active Directory without emitting it yet:
c:[Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname",
Issuer == "AD AUTHORITY"]
=> add(store = "Active Directory",
types = ("http://tempuri.org/upn-raw"),
query = ";userPrincipalName;{0}",
param = c.Value);Rule 2 emits exactly one UPN claim into the token:
c:[Type == "http://tempuri.org/upn-raw"]
=> issue(Type = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn",
Value = c.Value);Dynamics 365 CE 9.1
- Configure claims-based authentication against your AD FS federation metadata.
- Enable OAuth on the deployment. To confirm, run this in PowerShell on the Dynamics server:
Add-PSSnapin Microsoft.Crm.PowerShell Get-CrmSetting -SettingType OAuthClaimsSettings
The result should show Enabled = True and Authority set to your AD FS URL (for example, https://adfs.yourcompany.com/adfs).
Service account and user requirements
Riva connects as one service account and then acts on behalf of each synced user. Set both up in Dynamics before you create your connection.
Service account
- An AD account that is also an enabled user in Dynamics.
- Assign it a security role with the Delegate privilege (
prvActOnBehalfOfAnotherUser), plus the entity privileges Riva needs to read and write your synced records. The Salesperson and Delegate roles together meet this requirement. - Turn off multi-factor authentication (MFA) for this account. Riva signs in with its username and password, which doesn't support MFA.
Synced users
Each person Riva syncs for needs an enabled user record in Dynamics:
- In Dynamics, go to Settings > Security > Users.
- Select New, fill in the required fields, and set Primary Email to the email address that person will sync. Save the user.
- Select the user, then Manage Roles, and assign the Salesperson role.
Each user's Dynamics username must be their domain login (for example, YOURDOMAIN\jsmith), and their AD UPN must match their Dynamics user record. Dynamics uses the UPN to identify the user, so a mismatch causes that user's sync to fail.
How Riva authenticates
Riva signs in with the service account's username and password (the OAuth resource owner password credentials grant), then keeps the connection alive without any user interaction:
- Riva sends the service account's username and password to AD FS at
/adfs/oauth2/token, along with your client ID, client secret and your Dynamics URL as the resource. - AD FS validates the account against Active Directory and returns an access token and a refresh token.
- Riva calls Dynamics with the access token. Dynamics validates it with AD FS and identifies the account by its UPN.
- For each synced user, Riva acts on their behalf using the Delegate privilege.
- When the access token expires, Riva uses the refresh token to get a new one.
Because Riva signs in with a password, the service account can't require multi-factor authentication. No redirect URI is needed. Riva Cloud must be able to reach your AD FS token endpoint and your Dynamics URL over HTTPS.
Create your connection in Riva Admin Center
Dynamics on-premises connections are created in Riva Admin Center, not Riva Web.
Before you start
Contact Riva Support to set up your sync policy. For now, Riva Support completes this step for you, and it must be done before you create the connection. If you don't see Create CRM Connection in Riva Admin Center, Riva Support can also turn on Dynamics on-premises connections for your account.
Have these values ready:
| Value | Where it comes from |
|---|---|
| Client ID and client secret | The server application in your AD FS application group |
| Username and password | The service account in Dynamics |
| Dynamics URL (resource) | Your Dynamics server URL, for example https://crm.yourcompany.com/
|
| AD FS authority | Your AD FS URL, for example https://adfs.yourcompany.com/adfs
|
Enter both URLs exactly as they're configured on your servers: a trailing slash or a space makes a difference. Both must be reachable from Riva Cloud.
Create the connection
- In Riva Admin Center, open the Connections tab and select Create CRM Connection.
- Select Dynamics On-Premise AD FS and enter the values above.
- Select Create Connection. Riva refreshes your Dynamics metadata and runs a connection test. If anything fails, an error message appears.
- In Riva Web, open your policy and enable it. The policy stays disabled until you do. If Riva Web doesn't show the new connection right away, sign out and back in.
To test the connection later, select the three dots beside its name on the Connections tab in Riva Admin Center.
Changing the connection
- To change the Dynamics URL, AD FS URL or other settings, edit the connection in Riva Web as usual.
- To change the client ID, client secret, username or password, contact Riva Support. The connection must be deleted and created again.
Troubleshooting
| Symptom | Likely cause |
|---|---|
| Connection creation fails in Riva Admin Center | A URL doesn't exactly match your server configuration (check trailing slashes), Riva Cloud can't reach it, or MFA is on for the service account. |
| 401 Unauthorized from Dynamics | The token has no upn claim. Check both claim rules exist on the Web API application, in the right order. |
| One user fails to sync while others work | That user's AD UPN doesn't match their Dynamics user record, or the user is disabled in Dynamics. |
| Riva can't act for a user | The service account is missing the Delegate (prvActOnBehalfOfAnotherUser) privilege. |
| Connection stops working after a while |
offline_access isn't granted, so AD FS issues no refresh token. |
Configurations Riva doesn't support include multiple AD forests, identity providers other than AD FS 2019, and Dynamics on-premises versions other than 9.1. If you need one of these, contact Riva Support before you set up your connection.
Microsoft references
We built our reference environment by following these Microsoft articles:
- Deploy and configure AD FS (Dynamics 365 Customer Engagement on-premises 9.1)
- Configure claims-based authentication (Dynamics 365 Customer Engagement on-premises 9.1)
- Use connection strings in XRM tooling (Developer Guide for Dynamics 365 Customer Engagement)
- AD FS OpenID Connect/OAuth concepts