I have a desktop application that needs to connect to Azure Blob Storage.
Since it is not running on Azure, using managed identity is not an option.
I wanted to check the feasibility of using federated identity credentials to connect to Azure Blob Storage from the desktop application.
It would be helpful if I can get some steps or some sample code which I can use to check the feasibility.
Also, is there any other better way to achieve the above mentioned scenario without using connection strings or SAS tokens?
2
Answers
You can use the
ClientSecretCredential
to authenticate Azure Blob Storage without a SAS token and connection string.First, create an app registration in the portal and fetch the
client ID
,tenant ID
, andclient secret
from the app. Assign theStorage Blob Data Contributor
role to the storage account to access Azure Blob Storage.Here is the code to get the list of blob names with
ClientSecretCredential
using .NET.Code:
Output:
Reference:
Authorize access to blobs using Microsoft Entra ID – Azure Storage | Microsoft Learn
Exactly what you request is possible with Configure a federated identity credential on an app Configure a federated identity credential on an app. The link before gives you the example on how to configure the managed identity for GitHub – it must be adapted to your identity provider accordingly.
Then, if you use the MSAL library, you can make sure to get the corresponding access token with this code:
This should cover your usecase.