I have created an app registration in the portal, let's say it's named MyRegistration with clientID 12345 and tenantId 678910
Then I created a user in the DB:
..........Create user MyRegistration from external provider
And I assigned typical permissions/roles to that user - db_datareader, db_datawriter, even db_owner.
In my C# application, I acquire a token using said clientID, plus a client secret.
string resourceId = $"https://database.windows.net/";
string authority = $"https://login.windows.net/{TenantId}/";
AuthenticationContext authenticationContext = new AuthenticationContext(authority);
ClientCredential clientCredential = new ClientCredential(ClientID, ClientSecret);
AuthenticationResult authenticationResult = Task.Run(async () => await authenticationContext.AcquireTokenAsync(resourceId, clientCredential)).Result;
_DBAccessToken = authenticationResult.AccessToken;
But when I create a System.Data.SqlClient.SqlConnection:
........cn.AccessToken = strToken;
........cn.Open();
I get an error message - a message that contains my clientId and TenantID (separated by an @-sign)
"Login Failed for User 12345@678910"
That's all it says. What am I doing wrong?