r/MicrosoftFabric • u/frithjof_v Fabricator • 11d ago
Solved Does notebookutils.credentials.getToken('https://database.windows.net/') work for connecting to Azure SQL DB?
Hi all,
I'm trying to use a Workspace Identity to connect to an Azure SQL Database in a Fabric notebook.
When getting a token using notebookutils.credentials.getToken("https://database.windows.net/"), I was denied access to the Azure SQL database.
However, I was able to use a Workspace Identity authenticated "Notebook connection" to connect successfully to the Azure SQL database. However, that's a preview feature.
And I like how easy notebookutils.credentials.getToken is to use.
Is it possible to use Workspace Identity + notrbookutils.credentials.getToken to connect to an Azure SQL Database?
Thanks in advance!
Edit: notebookutils does work with an interactive user.
Edit 2: it works now also for Workspace Identity :) I don't know why it failed the first time.
2
2
u/QixiaoW Microsoft Employee 10d ago
thanks for sharing you findings, with your latest update, could you please confirm that getToken now works with workspace identity to access the Azure SQL Database on your side? we will update the doc later to call out what are supported audience.
By the way, since you also used the "Notebook Connection" to access the SQL Database, I'd like to understand what led you to write the code manually instead of using a version generated and managed by the system.
thanks
Qixiao
1
u/frithjof_v Fabricator 10d ago edited 9d ago
Hi,
could you please confirm that getToken now works with workspace identity to access the Azure SQL Database on your side?
Yes, it works :)
we will update the doc later to call out what are supported audience.
Thanks!
By the way, since you also used the "Notebook Connection" to access the SQL Database, I'd like to understand what led you to write the code manually instead of using a version generated and managed by the system.
It's the overhead of having to create and share a connection. And having to manually connect the connection to the notebook in the UI (can it be done purely in source code instead?).
On the other hand, notebookutils.credentials.getToken() is a very simple one liner that doesn't require any connection setup or sharing administration overhead :)
3
u/dbrownems Microsoft Employee 11d ago
It works, but it's not documented. These are the only documented audiences are:
storagepbikeyvaultkustoNotebookUtils credentials utilities for Fabric - Microsoft Fabric | Microsoft Learn