Retrieve an access token for Azure ACR using Azure Javascript SDK

118 Views Asked by At

I have an Azure subscription and I am using Azure Container Registry. I need to docker login to access my repository. This is easily done using the CLIs [docs]:

TOKEN=$(az acr login --name <acrName> --expose-token --output tsv --query accessToken)
docker login myregistry.azurecr.io --username 00000000-0000-0000-0000-000000000000 --password-stdin <<< $TOKEN

Is there a way to get this token using the official SDK? Specifically javascript SDK.

I instantiate the ACR client this way, but I don't see a way to retrieve the token. Yet the CLI tool is clearly capable of doing that :)

  const credential = new DefaultAzureCredential();
  const client = new ContainerRegistryClient(endpoint, credential);

For context, in AWS ECR this is achieved with GetAuthorizationTokenCommand command on ECR client [docs]. The response includes the token:

{ // GetAuthorizationTokenResponse
  authorizationData: [ // AuthorizationDataList
    { // AuthorizationData
      authorizationToken: "STRING_VALUE",
      expiresAt: new Date("TIMESTAMP"),
      proxyEndpoint: "STRING_VALUE",
    },
  ],
};
0

There are 0 best solutions below