Secretless cross-tenant dataverse access
Client secrets are like hiding your house key under the mat; easy to grab and impossible to audit. Certificates are just slightly better, because they at least prove who made the key. Until, of course, someone forgets where it’s stored. Even Azure Key Vault, while fantastic, doesn’t eliminate the problem; it just relocates it. So while secrets always need a mechanism on where and how to store, distribute and rotate, I rather prefer solutions that are totally secretless.
For today’s scenario, I want to call Dataverse in a completely different Entra tenant without ever storing a secret or managing a certificate. The setup is a User-Assigned Managed Identity in your operational tenant (let’s call it Tenant A), a multi-tenant app registration with a Federated Identity Credential configured in Tenant B, and an Azure Function that ties it all together.
The zero-secret pattern
Here’s what happens under the hood: The Azure Function in Tenant A uses its managed identity to request a token for api://AzureADTokenExchange/.default. That token is then exchanged for a Dataverse access token in Tenant B, validated by the FIC, which knows to trust this specific identity from that specific tenant. Dataverse then maps the resulting service principal to an Application User, and by that your cross-tenant API call works:securely, traceably, and without a single secret involved.
flowchart TB
subgraph TA["TENANT A (your Azure subscription)"]
FA["Function App<br/>(TypeScript)"]
UAMI["User-Assigned Managed Identity"]
APP["App Registration<br/>(multitenant)"]
FIC["Federated Identity Credential"]
FA -->|"uses"| UAMI
UAMI -->|"token for api://AzureADTokenExchange/.default"| APP
APP --- FIC
end
subgraph TB["TENANT B (Dataverse tenant)"]
SP["Service Principal"]
AU["Dataverse Application User"]
DV["Dataverse Web API"]
SP -->|"mapped to"| AU
AU --> DV
end
FA -. HTTPS request .-> TB
UAMI ==>|"token exchange"| SP
FA -->|"calls with issued token"| DV
DV -->|"returns data"| FA
One-command deployment
To make things super easy for you (and a bit more challenging for me), you can deploy all of that goodness in a single PowerShell command:
.\deploy-full-automation.ps1 `
-TenantAId "<your-tenant-a-id>" `
-TenantBId "<your-tenant-b-id>" `
-DataverseBaseUrl "https://yourorg.crm.dynamics.com"
The script creates the Function App and User-assigned Managed Identity in Tenant A, registers a multi-tenant app without any API permissions (that part is important), configures the federated credential, sets up the service principal in Tenant B, deploys the TypeScript function, creates the corresponding Dataverse Application User and assigns it with a security role.
When you’re done experimenting, one cleanup command wipes everything:
.\cleanup-all.ps1
You can find the full code in this GitHub repo.
What’s actually running
In Tenant A, you end up with a neat little cluster: a resource group, a Function App on Linux Consumption (Node 20), a user-assigned managed identity, and the multitenant app registration that contains the federated identity credential. Tenant B only needs two things: a service principal created automatically during setup, and a Dataverse Application User that maps to it with a role of your choice. Start with System Customizer if you just want to test; trim it down later for least privilege.
Testing the setup
If deployment finishes successfully, the easiest test is to run a simple WhoAmI request through your function:
$functionUrl = "https://func-dvproxy-prod.azurewebsites.net"
$whoami = Invoke-RestMethod "$functionUrl/api/dataverseproxy?path=WhoAmI"
Write-Host "User ID: $($whoami.data.UserId)"
Once that returns something, try querying accounts or system users. If it works, you just built a completely secretless integration across Microsoft Entra tenants.
The why behind the pattern
This pattern isn’t just about security, but about getting out of the business of secret-babysitting. Every secret rotation process you eliminate is one less operational cliff edge. Managed identities and federated credentials make identity the platform’s problem again, where it belongs. You control the trust relationship; Entra handles the token lifecycle; Dataverse handles the mapping. No oh no, it expired again moments. (been there, done that 🙄)
No more secrets :-)
Published on:
Learn moreWe can help you with Secretless cross-tenant dataverse access
If you want help implementing, troubleshooting, or improving this product, contact us and we’ll point you in the right direction.
Related posts
You are holding GitHub Copilot Wrong!
Most developers think that one can’t really use GitHub Copilot wrong. There is a chat interface that lets you also choose a model, so th...
You are holding GitHub Copilot Wrong!
Part 0 showed why constant prompting, re-prompting, and steering GitHub Copilot feels fragile. Not because Copilot is unreliable, but because ...
Building a Multi-Hierarchy Ticket Classification System (Because Keywords Aren't Enough)
Look, I love a good keyword-based system as much as the next developer. They’re fast, predictable, and when your user says “VPN,&r...
How Azure CLI handles your tokens and what you might be ignoring
Running az login feels like magic. A browser pops up, you pick an account, and from then on, everything just works. No more passwords, no more...
How Dev Proxy teaches you to make your apps more resilient
I added Microsoft Dev Proxy to my Mermaid → Dataverse converter, because I wanted to test how it handled rate limits and API errors. What I go...
Building Azure functions that never store secrets — ever
What if your function could hit Microsoft Graph with no client secrets, no certs, and no Key Vault entries? That is exactly what a Managed id...
Introducing Mermaid to Dataverse Converter
Why diagrams matter (and why they usually fail us) Entity-Relationship Diagrams (ERDs) are the universal shorthand for talking about data mode...
It’s OK to be seen trying
It’s OK to be seen trying Somewhere along the way, we started believing that you’re only allowed to speak after you’ve figured everything out....
Stuck in pilot - Part 1: no foundations, no future
“We just need to test the AI. We’ll figure out the data later.” That sentence has quietly killed more AI pilots than any model failure ever ...
The MVP trap: AI lets you do more, but often worse
There’s a narrative floating around right now: With AI, one person can do the work of a whole team. Code? Done. Design? Prompted. Copy? Gener...