0

I have generated a Shared Access Signature in the Azure portal. It gives me three strings: Connection string, SAS token, and Table service SAS URL. I would have thought that I could take the value of Connection string which contains the value of the SAS token prefixed by a url and create a new TableClient and query my table but it doesn't work.

Please note: I'm using Azure.Data.Tables 12.8.0

TableClient tc = new TableClient("<value-of-Connection-string>", "<my-table-name>");
var data = tc.Query<MyPoco>();    // I realize this is a table scan but don't care until it works

This returns error:

RequestFailedException: This request is not authorized to perform this operation using this resource type.
RequestId:dfe1fbe6-XXXX-002d-7997-XXXXXXXXXXXX
Time:2023-03-14T17:09:53.0004938Z
Status: 403 (Forbidden)
ErrorCode: AuthorizationResourceTypeMismatch

Can anyone help?

phil
  • 1,938
  • 4
  • 23
  • 33
  • Can you share what the SAS token/URL looks like? Also, just to confirm you are using SAS URL for connection string in your code. Right? – Gaurav Mantri Mar 14 '23 at 17:19
  • @GauravMantri, `Table service SAS URL` looks like `https://.table.core.windows.net/?sv=xxx&ss=yyy&sig=zzz&spr=uuu...`. If I use the value of this as the connection string I get error: `Connection string parsing error`. – phil Mar 14 '23 at 17:26
  • `Connection string` looks like: `BlobEndpoint=...;TableEndpoint=https://.table.core.windows.net...;SharedAccessSignature=sv=xxx&ss=yyy&sig=zzz&spr=uuu...` – phil Mar 14 '23 at 17:29
  • You cannot use SAS token in connection string. – Gaurav Mantri Mar 14 '23 at 17:30
  • Then I do not know how to supply the SAS token to the `TableClient` and query my table. – phil Mar 14 '23 at 17:32
  • Added an answer with 2 options. Please give them a try. HTH. – Gaurav Mantri Mar 14 '23 at 17:36
  • Argh! I assumed that allowing Container resource type also implied Object resource types but obviously not! If I check Object resource type and pass `Connection string` to `TableClient` it works. – phil Mar 14 '23 at 17:38

1 Answers1

1

If you want to use SAS URL to create an instance of TableClient, please use the following constructor: TableClient(Uri, TableClientOptions) where the URI is the SAS URL of the table in https://account.table.core.windows.net/table-name?sas-token format.

Other alternative would be to use the following constructor: TableClient(Uri, AzureSasCredential, TableClientOptions) where URI is the base URI of the table in https://account.table.core.windows.net/table-name format and AzureSasCredential is something you would create with your SAS token using something like:

var credentials = new AzureSasCredential(sasToken);
var tableClient = new TableClient(new Uri("https://account.table.core.windows.net/table-name"), credentials);
Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241