azure-docs icon indicating copy to clipboard operation
azure-docs copied to clipboard

Issue while calling TableServiceClient using DefaultAzureCredentials()

Open jahirul2022 opened this issue 2 years ago • 1 comments

Facing issue while calling TableServiceClient using DefaultAzureCredentials() from local environment

**Used the below code

TokenCredential credential = new DefaultAzureCredential();
             TableServiceClient client = new TableServiceClient(
                   endpoint: new Uri("cosmostableuri"),
                   tokenCredential: credential
              );

             var cosmosTable = client.GetTableClient("tablename");
             var entity = cosmosTable.GetEntity<Entity>("partitionKey", "rowkey");

### Getting an error : Azure.RequestFailedException: 'Authorization header doesn't confirm to the required format. Please verify and try again. ActivityId: 07e97c33-90c9-4faf-a5b7-b031f4dbf621, documentdb-dotnet-sdk/2.14.0 Host/64-bit MicrosoftWindowsNT/10.0.19041.0 RequestID:07e97c33-90c9-4faf-a5b7-b031f4dbf621 Status: 401 (Unauthorized) ErrorCode: Unauthorized Content: {"odata.error":{"code":"Unauthorized","message":{"lang":"en-us","value":"Authorization header doesn't confirm to the required format. Please verify and try again.\r\nActivityId: 07e97c33-90c9-4faf-a5b7-b031f4dbf621, documentdb-dotnet-sdk/2.14.0 Host/64-bit MicrosoftWindowsNT/10.0.19041.0\nRequestID:07e97c33-90c9-4faf-a5b7-b031f4dbf621\n"}}} Headers: Date: Thu, 20 Oct 2022 06:40:54 GMT Transfer-Encoding: chunked Content-Type: application/json; odata=minimalmetadata

jahirul2022 avatar Oct 21 '22 08:10 jahirul2022

@jahirul2022 It would be great if you could add a link to the documentation you are following for these steps? This would help us redirect the issue to the appropriate team. Thanks!!

YashikaTyagii avatar Oct 21 '22 17:10 YashikaTyagii

I have followed below documentation : [https://learn.microsoft.com/en-us/azure/cosmos-db/table/how-to-dotnet-get-started?tabs=azure-cli%2Cwindows#connect-using-the-microsoft-identity-platform](https://learn.microsoft.com/en-us/azure/cosmos-db/table/how-to-dotnet-get-started?tabs=azure-cli%2Cwindows#connect-using-the-microsoft-identity-platform)https://learn.microsoft.com/en-us/azure/cosmos-db/table/how-to-dotnet-get-started?tabs=azure-cli%2Cwindows#connect-using-the-microsoft-identity-platform

jahirul2022 avatar Oct 22 '22 05:10 jahirul2022

Hi @GeethaThatipatri-MSFT / @YashikaTyagi-MSFT , Please provide some update .

jahirul2022 avatar Oct 25 '22 08:10 jahirul2022

@seesharprun Can you please provide your inputs here

GeethaThatipatri-MSFT avatar Oct 25 '22 13:10 GeethaThatipatri-MSFT

@jahirul2022, I'm checking with the server-side team for the API for Table to see why this error code is being displayed. Based on our documentation and the SDK readme, you should be able to use the DefaultAzureCredential class to create a TableServiceClient or TableClient.

I tried both these blocks of code and got the same error message:

TableServiceClient client = new(
    endpoint: new Uri("https://<account-name>.table.cosmos.azure.com:443/"),
    tokenCredential: new DefaultAzureCredential()
);
TableClient tableClient = new TableClient(
    endpoint: new Uri("https://<account-name>.table.cosmos.azure.com:443/"),
    tableName: "adventureworks",
    tokenCredential: new DefaultAzureCredential()
);

I'll report back once I hear from the SDK or the service team. Thanks!

seesharprun avatar Oct 26 '22 16:10 seesharprun

It looks like this may be a bug with either the SDK or the server-side service. I went ahead and opened a bug in the Azure SDK for .NET repository:

https://github.com/Azure/azure-sdk-for-net/issues/32058

Since we don't have an action item right now in the docs, I will close this issue. I will revisit this issue once we get some feedback from the Azure SDK for .NET team or the service team.

#please-close

seesharprun avatar Oct 27 '22 12:10 seesharprun

We just got a response in the Azure SDK for .NET repo that Azure AD is not supported with Azure Cosmos DB for Table. The how-to guide was errant and the errant section is being immediately removed from the guide. Thank you for your patience.

seesharprun avatar Oct 27 '22 14:10 seesharprun

@seesharprun Thanks for the quick response .

jahirul2022 avatar Oct 27 '22 14:10 jahirul2022