2
``const { DefaultAzureCredential } = require('@azure/identity');
const { BlobServiceClient } = require("@azure/storage-blob");
const { v1: uuidv1 } = require("uuid");
require("dotenv").config();

async function main() {
try {
console.log("Azure Blob storage v12 - JavaScript quickstart sample");

     } catch (err) {
    console.err(`Error: ${err.message}`);

}
// Quick start code goes here
const accountName = process.env.demostorageaccount2023;
//if (!accountName) throw Error('Azure Storage accountName not found');

const blobServiceClient = new BlobServiceClient(
`https://${accountName}.blob.core.windows.net`,
new DefaultAzureCredential()
);
// Create a unique name for the container
const containerName = 'quickstart' + u`your text`uidv1();

console.log('\\nCreating container...');
console.log('\\t', containerName);

// Get a reference to a container
const containerClient = blobServiceClient.getContainerClient(containerName);
// Create the container
const createContainerResponse = await containerClient.create();
console.log(
`Container was created successfully.\n\trequestId:${createContainerResponse.requestId}\n\tURL:         ${containerClient.url}`
);
}

main()
.then(() =\> console.log("Done"))
.catch((ex) =\> console.log(ex.message));`

` I am trying to connect to Azure storage account and create a blob container.

I am logged in VS as global admin on the tenant. The account has "storage account contributor" and "Blob data owner" rights. I have also created a user managed identity and gave that "storage account contributor" access rights.

In addition, I run Az Login and re-enter my creds before I run node index.js in the VS terminal window. It fails to create the blobs with the below error message....

ChainedTokenCredential authentication failed. CredentialUnavailableError: EnvironmentCredential is unavailable. No underlying credential could be used. To troubleshoot, visit https://aka.ms/azsdk/js/identity/environmentcredential/troubleshoot.
CredentialUnavailableError: ManagedIdentityCredential: Authentication failed. Message ManagedIdentityCredential - No MSI credential available CredentialUnavailableError: ERROR: AADSTS50079: Due to a configuration change made by your administrator, or because you moved to a new location, you must enroll in multi-factor authentication to access 'e406a681-f3d4-42a8-90b6-c2b029497af1'. Trace ID: 88ea514a-ad3b-4905-b019-e11e2c92dc00 Correlation ID: dfe36549-0b86-4e4f-be5b-505a111ee3a4 Timestamp: 2022-12-17 20:37:40Z Interactive authentication is needed. Please run: az login --scope https://storage.azure.com/.default

Login to VS with a global admin account User-managed identity with access rights on the storage account AZ Login- re-enter the global admin account

  • 1
    Any help at all? ChainedTokenCredential authentication failed. CredentialUnavailableError: EnvironmentCredential is unavailable. No underlying credential could be used – Rafat Sumreen Dec 22 '22 at 03:50

0 Answers0