title | keywords | author | ms.author | ms.date | ms.topic | ms.prod | ms.technology | ms.devlang | ms.service |
---|---|---|---|---|---|---|---|---|---|
Azure Identity Brokered Authentication client library for .NET |
Azure, dotnet, SDK, API, Azure.Identity.BrokeredAuthentication, identity |
schaabs |
sschaab |
04/06/2022 |
reference |
azure |
azure |
dotnet |
identity |
The library extends the Azure.Identity library to provide authentication broker support. It includes the necessary dependencies, and provides the InteractiveBrowserCredentialBrokerOptions
class. This options class can be used to create an InteractiveBrowserCredential
capable of using the system authentication broker in lieu of the system browser when available.
Source code | Package (nuget) | API reference documentation | Azure Active Directory documentation
Install the Azure Identity client library for .NET with NuGet:
dotnet add package Azure.Identity.BrokeredAuthentication --prerelease
- The Azure.Identity library is a dependency of Azure.Identity.BrokeredAuthentication.
This example demonstrates configuring the InteractiveBrowserCredential
with the specialized options type InteractiveBrowserCredentialBrokerOptions
to enable brokered authentication.
// Create an interactive browser credential which will use the system authentication broker
var credential = new InteractiveBrowserCredential(new InteractiveBrowserCredentialBrokerOptions());
// Use the credential to authenticate a secret client
var client = new SecretClient(new Uri("https://myvault.vault.azure.net/"), credential);
See the troubleshooting guide for details on how to diagnose various failure scenarios.
Errors arising from authentication can be raised on any service client method which makes a request to the service. This is because the first time the token is requested from the credential is on the first call to the service, and any subsequent calls might need to refresh the token. In order to distinguish these failures from failures in the service client Azure Identity classes raise the AuthenticationFailedException
with details to the source of the error in the exception message as well as possibly the error message. Depending on the application these errors may or may not be recoverable.
using Azure.Identity;
using Azure.Security.KeyVault.Secrets;
// Create a secret client using the DefaultAzureCredential
var client = new SecretClient(new Uri("https://myvault.vault.azure.net/"), new DefaultAzureCredential());
try
{
KeyVaultSecret secret = await client.GetSecretAsync("secret1");
}
catch (AuthenticationFailedException e)
{
Console.WriteLine($"Authentication Failed. {e.Message}");
}
For more details on dealing with errors arising from failed requests to Azure Active Directory, or managed identity endpoints please refer to the Azure Active Directory documentation on authorization error codes.
The Azure Identity library provides the same logging capabilities as the rest of the Azure SDK.
The simplest way to see the logs to help debug authentication issues is to enable the console logging.
// Setup a listener to monitor logged events.
using AzureEventSourceListener listener = AzureEventSourceListener.CreateConsoleLogger();
All credentials can be configured with diagnostic options, in the same way as other clients in the SDK.
DefaultAzureCredentialOptions options = new DefaultAzureCredentialOptions()
{
Diagnostics =
{
LoggedHeaderNames = { "x-ms-request-id" },
LoggedQueryParameters = { "api-version" },
IsLoggingContentEnabled = true
}
};
CAUTION: Requests and responses in the Azure Identity library contain sensitive information. Precaution must be taken to protect logs when customizing the output to avoid compromising account security.
We guarantee that all credential instance methods are thread-safe and independent of each other (guideline). This ensures that the recommendation of reusing credential instances is always safe, even across threads.
Client options | Accessing the response | Diagnostics | Mocking | Client lifetime
Many of the client libraries listed here support authenticating with TokenCredential
and the Azure Identity library.
There you will also find links where you can learn more about their use, including additional documentation and samples.
This library does not currently support scenarios relating to the AAD B2C service.
Currently open issues for the Azure.Identity library can be found here.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.