CakePHP + Azure SQL / System Managed Identity Connections

Has anyone managed to get Cake working with Azure’s managed identities?

I can connect directly from the app service in a test.php file using:

<?php

$azureServer = 'my-server.database.windows.net';
$azureDatabase = 'sqldb-mydb-001';
$connectionInfo = array(
    'Database' => $azureDatabase,
    'Authentication' => 'ActiveDirectoryMsi'
);
$conn = sqlsrv_connect($azureServer, $connectionInfo);

this works fine so I know it’s configured OK.

I tried creating a DSN but for whatever reason it kills my app and no errors get logged:

'url' => 'Driver={ODBC Driver 17 for SQL Server};Server=my-server.database.windows.net,1433;Database=sqldb-mydb-001;Authentication=ActiveDirectoryMsi;UID=a;'

Any ideas what I may be missing?

OK I think I “solved” this by adding

Authentication=ActiveDirectoryMsi

to the DSN in

/vendor/cakephp/cakephp/src/Database/Driver/Sqlserver.php

$dsn = "sqlsrv:Server={$config['host']}{$port};Database={$config['database']};MultipleActiveResultSets=false;Authentication=ActiveDirectoryMsi";

can suggest a pull request to add Authentication as part of the config – there are various other connection methods (Service Principal, AD Password etc) with Sql Server.