Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
SachinNandanwar
Super User
Super User

SAS Token in fabric-Not Working

I created a SAS token for Fabric but it gives an error when I try to use it.

 

SachinNandanwar_0-1728427241995.png

I am unsure as to why is the request expecting a bearer token while using SAS ?

SachinNandanwar_0-1728479666787.gif


Here are the parameters used in the request

SachinNandanwar_1-1728427858429.png

 



Regards,
Sachin
Check out my Blog
9 REPLIES 9
Yao-MSFT
Microsoft Employee
Microsoft Employee

Hi @SachinNandanwar, I see some code in your blog that needs to be changed, could you please make following changes to your code and try again?

  • Use the endpoint  https://onelake.dfs.fabric.microsoft.com to construct the DataLakeServiceClient
  • Use following code to construct the DataLakeSasBuilder, _keyStartTime and _keyExpiryTime should be the same value that you used when getting the user delegation key.

 

DataLakeSasBuilder sasBuilder = new DataLakeSasBuilder()
{
    FileSystemName = workspaceName,
    Resource = "d",
    IsDirectory = true,
    Path = lakehouseName, // Should be {your lakehouse}.Lakehouse/Files
    StartsOn = _keyStartTime,
    ExpiresOn = _keyExpiryTime
};

 

  •  Use onelake as the account name instead of the endpoint when calling ToSasQueryParameters

Hi @Yao-MSFT ,

I am using onelake.dfs endpoints. See the belwo screenshot of the code from my blog where I set the endpoint values to a variable.

SachinNandanwar_0-1737547081925.png

Also, If you check my earlier screenshots of POST MAN in this post, you can see that I am using dfs endpoints.

and my delegation expiration is set to an hour from the time the SAS token is generated

SachinNandanwar_1-1737547190741.png
The SAS token expiry is also set to an hour
SachinNandanwar_2-1737547295622.png

After making your suggested changes its still the same error

SachinNandanwar_3-1737548044525.png



Regards,
Sachin
Check out my Blog
Mabasile_MSFT
Microsoft Employee
Microsoft Employee

Hi @SachinNandanwar  - I'm happy to help here.  The reason you are receiving the error message regarding a bearer token is because, since all OneLake SAS are user-delegated, the SAS is authenticated very similarly to how a bearer token would, hence the similar error. 

From reviewing the samples above, your issue might be with the signedPermissions ('sp') field - it looks like you're only granting the SAS Write and List permissions, which means the SAS won't have permissions to Read, hence the authorization error.  Could you try adjusting the signedPermissions and trying again?

Hi @Mabasile_MSFT 

I added the read permission but unfortunately it didnt make any difference.

SachinNandanwar_0-1737477197723.png

 



Regards,
Sachin
Check out my Blog
DevanshA
New Member

Hello @v-jingzhan-msft and @SachinNandanwar , 

I am currently stuck on the same error and was wondering whether you have found a solution for the same? Any help would be greatly appreciated. Thank you.

Nope..Not yet..

Its been over a month since I have blogged on the issue but there hasnt been any solution insight

https://www.azureguru.net/sas-token-in-fabric#heading-the-issue

I even tried the Fabric Reditt forum , but to no avail

https://www.reddit.com/r/MicrosoftFabric/comments/1g0m0sy/comment/lrf41kl/?context=3



Regards,
Sachin
Check out my Blog
v-jingzhan-msft
Community Support
Community Support

Hi @SachinNandanwar 

 

I went through the following documentation. It says OneLake SAS can grant access to files and folders within data items like lakehouses, but it doesn't mention that it requires a combination of a SAS token and a bearer token. 

Create a OneLake shared access signature (SAS) (Preview) - Microsoft Fabric | Microsoft Learn

 

Typically, a SAS token should be sufficient for accessing the resources, as it includes the necessary permissions and signature for authentication. But to troubleshoot this further, you might try including a SAS token and a bearer token in your request and testing whether this would make the call work. You might test this first and let us know the result. Thank you in advance. 

 

Best Regards,
Jing
Community Support Team

@v-jingzhan-msft  I tried using a bearer token hoping that bearer token authenticates the request and with all the information in the SAS token the request is authroized.

But unfortunately this isnt the case.Have a look at the screengrab.

Recording 2024-10-10 at 01.15.54.gif

Its the bearer token that takes the precedence in the request with SAS token being completely ignored.

I used Azurecmdlet Powershell to create the bearer token.

 

Connect-AzAccount
$My_Token = Get-AzAccessToken -ResourceTypeName Storage
$My_Token.Token | Set-Clipboard

 

 



Regards,
Sachin
Check out my Blog

Thanks @v-jingzhan-msft .

Are you aware what endpoints should I use ? For Fabric API's the endpoint used for bearer token is https://api.fabric.microsoft.com/.default

For DFS I tried using https://onelake.dfs.fabric.microsoft.com/.default but this isnt working.



Regards,
Sachin
Check out my Blog

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

JanFabricDE_carousel

Fabric Monthly Update - January 2025

Explore the power of Python Notebooks in Fabric!

JanFabricDW_carousel

Fabric Monthly Update - January 2025

Unlock the latest Fabric Data Warehouse upgrades!

JanFabricDF_carousel

Fabric Monthly Update - January 2025

Take your data replication to the next level with Fabric's latest updates!