<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: SAS Token in fabric-Not Working in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4368181#M6170</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="777262" data-lia-user-login="SachinNandanwar" class="lia-mention lia-mention-user"&gt;SachinNandanwar&lt;/a&gt;&amp;nbsp; - I'm happy to help here.&amp;nbsp; 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.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;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.&amp;nbsp; Could you try adjusting the signedPermissions and trying again?&lt;/P&gt;</description>
    <pubDate>Fri, 17 Jan 2025 00:16:17 GMT</pubDate>
    <dc:creator>Mabasile_MSFT</dc:creator>
    <dc:date>2025-01-17T00:16:17Z</dc:date>
    <item>
      <title>SAS Token in fabric-Not Working</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4234190#M4501</link>
      <description>&lt;P&gt;I created a SAS token for Fabric but it gives an error when I try to use it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;img /&gt;&lt;P&gt;I am unsure as to why is the request expecting a bearer token while using SAS ?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;img /&gt;&lt;P&gt;&lt;BR /&gt;Here are the parameters used in the request&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;img /&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 09 Oct 2024 13:15:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4234190#M4501</guid>
      <dc:creator>SachinNandanwar</dc:creator>
      <dc:date>2024-10-09T13:15:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Token in fabric-Not Working</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4234812#M4511</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="777262" data-lia-user-login="SachinNandanwar" class="lia-mention lia-mention-user"&gt;SachinNandanwar&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I went through the following documentation. It says&amp;nbsp;&lt;SPAN&gt;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.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/fabric/onelake/how-to-create-a-onelake-shared-access-signature" target="_blank" rel="noopener"&gt;Create a OneLake shared access signature (SAS) (Preview) - Microsoft Fabric | Microsoft Learn&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Typically, a SAS token should be sufficient for accessing the resources, as it includes the necessary permissions and signature for authentication. But&amp;nbsp;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.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Jing&lt;BR /&gt;Community Support Team&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2024 07:54:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4234812#M4511</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-10-09T07:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Token in fabric-Not Working</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4235261#M4521</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;.&lt;BR /&gt;&lt;BR /&gt;Are you aware what endpoints should I use ? For Fabric API's the endpoint used for bearer token is&amp;nbsp;&lt;A href="https://api.fabric.microsoft.com/.default" target="_blank"&gt;https://api.fabric.microsoft.com/.default&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;For DFS I tried using &lt;A href="https://onelake.dfs.fabric.microsoft.com/.default" target="_blank"&gt;https://onelake.dfs.fabric.microsoft.com/.default&lt;/A&gt; but this isnt working.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2024 14:36:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4235261#M4521</guid>
      <dc:creator>SachinNandanwar</dc:creator>
      <dc:date>2024-10-09T14:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Token in fabric-Not Working</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4235776#M4525</link>
      <description>&lt;P&gt;Anonymous&lt;/a&gt;&amp;nbsp;&amp;nbsp;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.&lt;BR /&gt;&lt;BR /&gt;But unfortunately this isnt the case.Have a look at the screengrab.&lt;BR /&gt;&lt;BR /&gt;&lt;img /&gt;&lt;BR /&gt;&lt;BR /&gt;Its the bearer token that takes the precedence in the request with SAS token being completely ignored.&lt;BR /&gt;&lt;BR /&gt;I used Azurecmdlet Powershell to create the bearer token.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Connect-AzAccount
$My_Token = Get-AzAccessToken -ResourceTypeName Storage
$My_Token.Token | Set-Clipboard&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2024 21:04:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4235776#M4525</guid>
      <dc:creator>SachinNandanwar</dc:creator>
      <dc:date>2024-10-09T21:04:45Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Token in fabric-Not Working</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4300336#M5342</link>
      <description>&lt;P&gt;Hello&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="777262" data-lia-user-login="SachinNandanwar" class="lia-mention lia-mention-user"&gt;SachinNandanwar&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2024 17:14:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4300336#M5342</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-25T17:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Token in fabric-Not Working</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4341816#M5756</link>
      <description>&lt;P&gt;Nope..Not yet..&lt;BR /&gt;&lt;BR /&gt;Its been over a month since I have blogged on the issue but there hasnt been any solution insight&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://www.azureguru.net/sas-token-in-fabric#heading-the-issue" target="_blank"&gt;https://www.azureguru.net/sas-token-in-fabric#heading-the-issue&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;I even tried the Fabric Reditt forum , but to no avail&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://www.reddit.com/r/MicrosoftFabric/comments/1g0m0sy/comment/lrf41kl/?context=3" target="_blank"&gt;https://www.reddit.com/r/MicrosoftFabric/comments/1g0m0sy/comment/lrf41kl/?context=3&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Dec 2024 07:40:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4341816#M5756</guid>
      <dc:creator>SachinNandanwar</dc:creator>
      <dc:date>2024-12-24T07:40:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Token in fabric-Not Working</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4368181#M6170</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="777262" data-lia-user-login="SachinNandanwar" class="lia-mention lia-mention-user"&gt;SachinNandanwar&lt;/a&gt;&amp;nbsp; - I'm happy to help here.&amp;nbsp; 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.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;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.&amp;nbsp; Could you try adjusting the signedPermissions and trying again?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jan 2025 00:16:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4368181#M6170</guid>
      <dc:creator>Mabasile_MSFT</dc:creator>
      <dc:date>2025-01-17T00:16:17Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Token in fabric-Not Working</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4374067#M6325</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="914230" data-lia-user-login="Mabasile_MSFT" class="lia-mention lia-mention-user"&gt;Mabasile_MSFT&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I added the read permission but unfortunately it didnt make any difference.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2025 16:33:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4374067#M6325</guid>
      <dc:creator>SachinNandanwar</dc:creator>
      <dc:date>2025-01-21T16:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Token in fabric-Not Working</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4375000#M6349</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="777262" data-lia-user-login="SachinNandanwar" class="lia-mention lia-mention-user"&gt;SachinNandanwar&lt;/a&gt;, I&amp;nbsp;see some code in your blog that needs to be changed, could you please make following changes to your code and try again?&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Use the endpoint&amp;nbsp;&amp;nbsp;&lt;A href="https://onelake.dfs.fabric.microsoft.com" target="_blank" rel="noopener"&gt;https://onelake.dfs.fabric.microsoft.com&lt;/A&gt;&amp;nbsp;to construct the&amp;nbsp;DataLakeServiceClient&lt;/LI&gt;&lt;LI&gt;Use following code to construct the&amp;nbsp;DataLakeSasBuilder, _keyStartTime and _keyExpiryTime should be the same value that you used when getting the user delegation key.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;DataLakeSasBuilder sasBuilder = new DataLakeSasBuilder()
{
    FileSystemName = workspaceName,
    Resource = "d",
    IsDirectory = true,
    Path = lakehouseName, // Should be {your lakehouse}.Lakehouse/Files
    StartsOn = _keyStartTime,
    ExpiresOn = _keyExpiryTime
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&amp;nbsp;Use &lt;STRONG&gt;onelake&lt;/STRONG&gt; as the account name instead of the endpoint when calling&amp;nbsp;ToSasQueryParameters&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Wed, 22 Jan 2025 07:00:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4375000#M6349</guid>
      <dc:creator>Yao-MSFT</dc:creator>
      <dc:date>2025-01-22T07:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Token in fabric-Not Working</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4375629#M6379</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="916838" data-lia-user-login="Yao-MSFT" class="lia-mention lia-mention-user"&gt;Yao-MSFT&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;BR /&gt;&lt;BR /&gt;Also, If you check my earlier screenshots of POST MAN in this post, you can see that I am using dfs endpoints.&lt;BR /&gt;&lt;BR /&gt;and my delegation expiration is set to an hour from the time the SAS token is generated&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;BR /&gt;The SAS token expiry is also set to an hour&lt;BR /&gt;&lt;img /&gt;&lt;BR /&gt;&lt;BR /&gt;After making your suggested changes its still the same error&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 12:16:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4375629#M6379</guid>
      <dc:creator>SachinNandanwar</dc:creator>
      <dc:date>2025-01-22T12:16:46Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Token in fabric-Not Working</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4646374#M8520</link>
      <description>&lt;P&gt;I was having this same issue for a few days trying to figure out what the problem is. I finally got it to work in Python with the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Requires 'pip install azure-storage-file-datalake azure-identity'
from azure.storage.filedatalake import (
    DataLakeServiceClient,
    generate_directory_sas,
)
from azure.identity import DefaultAzureCredential
from datetime import datetime, timedelta
import pytz


def get_user_delegation_sas(workspace: str, data_path: str) -&amp;gt; str:
    """
    Generates a User Delegation SAS token for accessing a Data Lake in Azure.
    """
    token_credential = DefaultAzureCredential()
    service_client = DataLakeServiceClient(
        account_url="https://onelake.dfs.fabric.microsoft.com",
        credential=token_credential
    )

    # Get a user delegation key that's valid for 30 minutes
    delegation_key_start_time = (datetime.now(pytz.utc) - timedelta(minutes=5)).replace(second=0, microsecond=0)
    delegation_key_expiry_time = delegation_key_start_time + timedelta(minutes=30)
    user_delegation_key = service_client.get_user_delegation_key(
        key_start_time=delegation_key_start_time,
        key_expiry_time=delegation_key_expiry_time,
    )

    return generate_directory_sas(
        account_name="onelake",
        file_system_name=workspace,
        directory_name=data_path,
        credential=user_delegation_key,
        permission="racwdl",
        expiry=delegation_key_expiry_time,
        start=delegation_key_start_time,
    )


if __name__ == "__main__":
    ACCOUNT_URL = "https://onelake.dfs.fabric.microsoft.com"
    WORKSPACE_NAME = "&amp;lt;workspace name&amp;gt;"
    LAKEHOUSE_NAME = "&amp;lt;Lakehouse name&amp;gt;"
    root_path = f"{LAKEHOUSE_NAME}.Lakehouse"
    data_path = f"{root_path}/Files"

    # SAS token has permission on lakehouse root path, could be more specific
    sas_token = get_user_delegation_sas(WORKSPACE_NAME, root_path)
    print("SAS token: ", sas_token)

    # Try to use sas token to list files
    service_client = DataLakeServiceClient(ACCOUNT_URL, credential=sas_token)
    file_system_client = service_client.get_file_system_client(WORKSPACE_NAME)
    paths = file_system_client.get_paths(path=data_path, recursive=True)
    for path in paths:
        print(path.name + "\n")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My main issue was that I used the endpoint in the generation and signing of the SAS token, but the right answer is to use "onelake" only. I have also been trying to use lakehouse and workspace Item IDs, but I only got it to work with names.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Apr 2025 08:25:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/SAS-Token-in-fabric-Not-Working/m-p/4646374#M8520</guid>
      <dc:creator>YKXC</dc:creator>
      <dc:date>2025-04-10T08:25:41Z</dc:date>
    </item>
  </channel>
</rss>

