The resource principal was not found in the tenant
grunam opened this issue · 1 comments
Describe the bug
I have an error when I try to connect to Microsoft Dynamics database in linux terminal.
web498@pic-mutu02:/var/www/clients/client1/web498/web/templates/tx_morph/includes$ php7.4 -f ./joomla_microsoft-dynamics.php
PHP Fatal error: Uncaught AlexaCRM\WebAPI\OData\AuthenticationException: Authentication at Azure AD failed. AADSTS500011: The resource principal named ########################## was not found in the tenant named 3c33e00c-1756-47c6-825f-3f6907f2ff07. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.
Trace ID: 5f7e75a3-378c-41e0-bedc-b04170a61000
Correlation ID: 7f1116b5-3d01-4150-8b0f-5b1d856568cd
Timestamp: 2020-10-23 07:48:15Z in /var/www/clients/client1/web498/web/templates/tx_morph/includes/vendor/alexacrm/dynamics-webapi-toolkit/src/WebAPI/OData/OnlineAuthMiddleware.php:162
To Reproduce
The database Manager manages to connect with the c# code in this screenshoot
I have an error with dynamics-webapi-toolkit php code below.
$api = '#############################';
$clientIdApplication = '#############################';
$clientSecretKey = '*********************************************';
$settings = new \AlexaCRM\WebAPI\OData\OnlineSettings();
$settings->instanceURI = $api;
$settings->applicationID = $clientIdApplication;
$settings->applicationSecret = $clientSecretKey;
/* A modifier en PROD */
$settings->tlsVerifyPeers = false;
$middleware = new \AlexaCRM\WebAPI\OData\OnlineAuthMiddleware( $settings );
$odataClient = new \AlexaCRM\WebAPI\OData\Client( $settings, $middleware );
$client = new \AlexaCRM\WebAPI\Client( $odataClient );
Expected behavior
Connection to Microsoft Dynamics
Additionnal infos
the tenant ID, clientIdApplication and clientSecretKey are the same between c# code and php code.
@grunam In C# code, check ap.Resource on the line you're acquiring the token. That should be your resource when authenticating. In other words:
$settings->instanceURI
= $api;
That's instance URI e.g. https://contoso.crm.dynamics.com, not api URI. We discover and build API URI for you.