Use Microsoft Entra ID to authorize access in application code
To authorize access to Azure Storage with Microsoft Entra ID, you can use one of the following client libraries to acquire an OAuth 2.0 token:
- The Azure Identity client library is recommended for most development scenarios.
- The Microsoft Authentication Library (MSAL) may be suitable for certain advanced scenarios.
Azure Identity client library
The Azure Identity client library simplifies the process of getting an OAuth 2.0 access token for authorization with Microsoft Entra ID via the Azure SDK. The latest versions of the Azure Storage client libraries for .NET, Java, Python, JavaScript, and Go integrate with the Azure Identity libraries for each of those languages to provide a simple and secure means to acquire an access token for authorization of Azure Storage requests.
An advantage of the Azure Identity client library is that it enables you to use the same code to acquire the access token whether your application is running in the development environment or in Azure. The Azure Identity client library returns an access token for a security principal. When your code is running in Azure, the security principal may be a managed identity for Azure resources, a service principal, or a user or group. In the development environment, the client library provides an access token for either a user or a service principal for testing purposes.
The access token returned by the Azure Identity client library is encapsulated in a token credential. You can then use the token credential to get a service client object to use in performing authorized operations against Azure Storage. A simple way to get the access token and token credential is to use the DefaultAzureCredential class that is provided by the Azure Identity client library. DefaultAzureCredential attempts to get the token credential by sequentially trying several different credential types. DefaultAzureCredential works in both the development environment and in Azure.
The following table points to additional information for authorizing access to data in various scenarios:
| Language | .NET | Java | JavaScript | Python | Go |
|---|---|---|---|---|---|
| Overview of auth with Microsoft Entra ID | How to authenticate .NET applications with Azure services | Azure authentication with Java and Azure Identity | Authenticate JavaScript apps to Azure using the Azure SDK | Authenticate Python apps to Azure using the Azure SDK | N/A |
| Auth using developer service principals | Authenticate .NET apps to Azure services during local development using service principals | Azure authentication with service principal | Auth JS apps to Azure services with service principal | Authenticate Python apps to Azure services during local development using service principals | Azure SDK for Go authentication with a service principal |
| Auth using developer or user accounts | Authenticate .NET apps to Azure services during local development using developer accounts | Azure authentication with user credentials | Auth JS apps to Azure services with dev accounts | Authenticate Python apps to Azure services during local development using developer accounts | Azure authentication with the Azure SDK for Go |
| Auth from Azure-hosted apps | Authenticating Azure-hosted apps to Azure resources with the Azure SDK for .NET | Authenticate Azure-hosted Java applications | Authenticating Azure-hosted JavaScript apps to Azure resources with the Azure SDK for JavaScript | Authenticating Azure-hosted apps to Azure resources with the Azure SDK for Python | Authentication with the Azure SDK for Go using a managed identity |
| Auth from on-premises apps | Authenticate to Azure resources from .NET apps hosted on-premises | N/A | Authenticate on-premises JavaScript apps to Azure resources | Authenticate to Azure resources from Python apps hosted on-premises | N/A |
| Identity client library overview | Azure Identity client library for .NET | Azure Identity client library for Java | Azure Identity client library for JavaScript | Azure Identity client library for Python | Azure Identity client library for Go |
Microsoft Authentication Library (MSAL)
While Microsoft recommends using the Azure Identity client library when possible, the MSAL library may be appropriate to use in certain advanced scenarios.
When you use MSAL to acquire an OAuth token for access to Azure Storage, you need to provide a Microsoft Entra resource ID. The Microsoft Entra resource ID indicates the audience for which a token that is issued can be used to provide access to an Azure resource. In the case of Azure Storage, the resource ID may be specific to a single storage account, or it may apply to any storage account.
When you provide a resource ID that is specific to a single storage account and service, the resource ID is used to acquire a token for authorizing requests to the specified account and service only. The following table lists examples of values to use for the resource ID, based on the cloud you're working with. Replace <account-name> with the name of your storage account.
| Cloud | Resource ID |
|---|---|
| Azure Global | example: account-name.blob.core.windows.net |
| Azure Government | example: account-name.blob.core.usgovcloudapi.net |
| Azure China 21Vianet | example: account-name.blob.core.chinacloudapi.cn |
You can also provide a resource ID that applies to any storage account, as shown in the following table. This resource ID is the same for all public and sovereign clouds, and is used to acquire a token for authorizing requests to any storage account.
| Cloud | Resource ID |
|---|---|
| Azure Global Azure Government Azure China 21Vianet | example: storage.azure.com |
microsoft windows server certification training courses malaysia
Comments
Post a Comment