Using Visual Studio Pro with C# .NET to Azure Blob Storage

Wahlroos, David (MNIT) 0 Reputation points
2025-07-31T21:11:34.0933333+00:00

I am part of a development team working with an app which uses C# and .NET on the backend. One of the functions is to write file uploads to Azure Blob Storage. All of the other developers have no problem, yet for some reason I receive errors on authentication.

We are connecting with a client secret. My environment variables are correct. I have checked, reset, rechecked them so many times I know that isn't the issue. I am using AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET all with the correct values, yet I am receiving the errors. I have placed debug breakpoints to look at the values for my Environment Variables and they all appear correct. I don't have access to any management capabilities for Azure management so I don't have any information from that.

They are correct after creating defaultAzureCredential in the Program.cs

Since the other 2 devs are not having issue, and our code is the same I am guessing it must be either something in my VS settings or a setup item missed in Azure. (although using a secret I don't know that there would be anything specific to a particular user)

Here are the errors I've captured, I am hoping someone can shed some light on the situation.


{"ClientSecretCredential authentication failed: A configuration issue is preventing authentication - check the error message from the server for details. You can modify the configuration in the application registration portal. See https://aka.ms/msal-net-invalid-client for details. Original exception: AADSTS7000215: Invalid client secret provided. Ensure the secret being sent in the request is the client secret value, not the client secret ID, for a secret added to app


"A configuration issue is preventing authentication - check the error message from the server for details. You can modify the configuration in the application registration portal. See https://aka.ms/msal-net-invalid-client for details. Original exception: AADSTS7000215: Invalid client secret provided. Ensure the secret being sent in the request is the client secret value, not the client secret ID, for a secret added to app


and this is being added to the log file.

[ERR] Error uploading files: DefaultAzureCredential failed to retrieve a token from the included credentials. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/defaultazurecredential/troubleshoot

  • EnvironmentCredential authentication unavailable. Environment variables are not fully configured. See the troubleshooting guide for more information.
Microsoft Security | Active Directory Federation Services
0 comments No comments
{count} votes

Accepted answer
  1. Marcin Policht 53,675 Reputation points MVP Volunteer Moderator
    2025-07-31T21:37:01.33+00:00

    The error messages seem to imply that environment variables were read but possibly are invalid or malformed and that Entra ID is rejecting the secret as invalid.

    1. Double-check you are using the secret value, not the secret ID

    Go to Azure portal > Entra ID > App Registrations > Your App > Certificates & secrets.

    • Secret ID = A GUID shown in the table (this is not what you use).
    • Secret Value = Only visible when the secret is first created. This is what you must copy and store securely.
    1. Verify your env vars are correctly named and loaded

    Azure SDK uses the following:

    AZURE_TENANT_ID
    AZURE_CLIENT_ID
    AZURE_CLIENT_SECRET
    

    Run the following in your debugger to confirm:

    Console.WriteLine($"Tenant: {Environment.GetEnvironmentVariable("AZURE_TENANT_ID")}");
    Console.WriteLine($"ClientId: {Environment.GetEnvironmentVariable("AZURE_CLIENT_ID")}");
    Console.WriteLine($"Secret: {(string.IsNullOrEmpty(Environment.GetEnvironmentVariable("AZURE_CLIENT_SECRET")) ? "MISSING" : "SET")}");
    

    If these are missing in the runtime process, even if they're set in the system/user environment, your app may not see them. In Visual Studio:

    • Go to Project > Properties > Debug
    • Ensure AZURE_TENANT_ID, etc., are present in "Environment variables" for the debug profile.

    Alternatively, set them in your shell and run the app from CLI.

    1. Check if you are using DefaultAzureCredential in an environment where other credentials interfere

    DefaultAzureCredential will try many credential types in order:

    • EnvironmentCredential
    • ManagedIdentityCredential
    • SharedTokenCacheCredential
    • VisualStudioCredential
    • etc.

    Add logging to confirm which credential is failing:

    var options = new DefaultAzureCredentialOptions
    {
        Diagnostics =
        {
            IsLoggingContentEnabled = true,
            LoggedHeaderNames = { "x-ms-request-id" },
            LoggedQueryParameters = { "api-version" },
            IsAccountIdentifierLoggingEnabled = true
        }
    };
    
    var credential = new DefaultAzureCredential(options);
    

    Or simplify for testing:

    var credential = new ClientSecretCredential(
        Environment.GetEnvironmentVariable("AZURE_TENANT_ID"),
        Environment.GetEnvironmentVariable("AZURE_CLIENT_ID"),
        Environment.GetEnvironmentVariable("AZURE_CLIENT_SECRET")
    );
    

    This eliminates all other credential types that might be interfering.


    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin


1 additional answer

Sort by: Most helpful
  1. Wahlroos, David (MNIT) 0 Reputation points
    2025-08-11T19:21:31.65+00:00

    I appreciate all of the feedback, Thank you everyone. We found that there was a user variable and system variable, both with the same name for each of the 3 variables. I removed them all, double checked all of the necessary variables and recreated only the user variables. I still had issues. It appears that the AZURE_CLIENT_SECRET variable I was using was from set up documentation that had not been updated with the correct value. That explains why everything seemed correct. When I was able to get some one-one time with one of our Hosting Integration people we were able to better review the problem.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.