You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sdk/azidentity/README.md
+86-13Lines changed: 86 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,21 +62,91 @@ Directory (AAD). It offers a variety of credential types capable of acquiring
62
62
an AAD access token. See [Credential Types](#credential-types"Credential Types") below for a list of this module's credential types.
63
63
64
64
### DefaultAzureCredential
65
+
The `DefaultAzureCredential` is appropriate for most scenarios where the application is ultimately intended to run in Azure Cloud. This is because `DefaultAzureCredential` combines credentials commonly used to authenticate when deployed, with credentials used to authenticate in a development environment.
65
66
66
-
`DefaultAzureCredential` is appropriate for most applications which will run in
67
-
the Azure Cloud because it combines common production credentials with
68
-
development credentials. `DefaultAzureCredential` attempts to authenticate via
69
-
the following mechanisms in this order, stopping when one succeeds:
67
+
> Note: `DefaultAzureCredential` is intended to simplify getting started with the SDK by handling common scenarios with reasonable default behaviors. Developers who want more control or whose scenario isn't served by the default settings should use other credential types.
70
68
69
+
The `DefaultAzureCredential` will attempt to authenticate via the following mechanisms in order.
- Environment - `DefaultAzureCredential` will read account information specified
74
-
via [environment variables](#environment-variables"environment variables")
75
-
and use it to authenticate.
76
-
- Managed Identity - if the application is deployed to an Azure host with
77
-
Managed Identity enabled, `DefaultAzureCredential` will authenticate with it.
78
-
- Azure CLI - If a user has signed in via the Azure CLI `az login` command,
79
-
`DefaultAzureCredential` will authenticate as that user.
73
+
- Environment - The `DefaultAzureCredential` will read account information specified via [environment variables](#environment-variables) and use it to authenticate.
74
+
- Managed Identity - If the application is deployed to an Azure host with Managed Identity enabled, the `DefaultAzureCredential` will authenticate with that account.
75
+
- Azure CLI - If the developer has authenticated an account via the Azure CLI `az login` command, the `DefaultAzureCredential` will authenticate with that account.
76
+
77
+
78
+
## Examples
79
+
You can find more examples of using various credentials in [Azure Identity Examples Wiki page](https://github.com/Azure/azure-sdk-for-go/wiki/Azure-Identity-Examples).
80
+
81
+
### Authenticating with `DefaultAzureCredential`
82
+
This example demonstrates authenticating the `ResourcesClient` from the [armresources][armresources_library] module using `DefaultAzureCredential`.
83
+
84
+
```go
85
+
// The default credential checks environment variables for configuration.
See more how to configure the `DefaultAzureCredential` on your workstation or Azure in [Configure DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-go/wiki/Set-up-Your-Environment-for-Authentication#configure-defaultazurecredential).
96
+
97
+
### Authenticating a user assigned managed identity with `DefaultAzureCredential`
98
+
This example demonstrates authenticating the `ResourcesClient` from the [armresources][armresources_library] module using the `DefaultAzureCredential`, deployed to an Azure resource with a user assigned managed identity configured.
99
+
100
+
See more about how to configure a user assigned managed identity for an Azure resource in [Enable managed identity for Azure resources](https://github.com/Azure/azure-sdk-for-go/wiki/Set-up-Your-Environment-for-Authentication#enable-managed-identity-for-azure-resources).
101
+
102
+
```go
103
+
// The default credential will use the user assigned managed identity with the specified client ID.
104
+
// The client_ID for the user assigned is set through an environment variable.
The [Managed identity authentication](https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/overview) is supported via either the `DefaultAzureCredential` or the `ManagedIdentityCredential` directly for the following Azure Services:
*[Azure Service Fabric](https://docs.microsoft.com/azure/service-fabric/concepts-managed-identity)
122
+
123
+
### Examples
124
+
#### Authenticating in Azure with Managed Identity
125
+
This examples demonstrates authenticating the `ResourcesClient` from the [armresources][armresources_library] module using `ManagedIdentityCredential` in a virtual machine, app service, function app, cloud shell, or AKS environment on Azure, with system assigned, or user assigned managed identity enabled.
126
+
127
+
See more about how to configure your Azure resource for managed identity in [Enable managed identity for Azure resources](https://github.com/Azure/azure-sdk-for-go/wiki/Set-up-Your-Environment-for-Authentication#enable-managed-identity-for-azure-resources)
128
+
129
+
```go
130
+
// Authenticate with a User Assigned Managed Identity.
131
+
cred, err:= azidentity.NewManagedIdentityCredential("<USER ASSIGNED MANAGED IDENTITY CLIENT ID>", nil) // specify a client_ID for the user assigned identity
132
+
if err != nil {
133
+
// handle error
134
+
}
135
+
136
+
// Azure SDK Azure Resource Management clients accept the credential as a parameter
> CAUTION: logs from credentials contain sensitive information.
180
250
> These logs must be protected to avoid compromising account security.
181
251
182
-
# Next steps
252
+
## Next steps
253
+
254
+
The Go client libraries listed [here](https://azure.github.io/azure-sdk/releases/latest/go.html) support authenticating with `TokenCredential` and the Azure Identity library. You can learn more about their use, and find additional documentation on use of these client libraries along samples with can be found in the links mentioned [here](https://azure.github.io/azure-sdk/releases/latest/go.html).
183
255
184
256
## Provide Feedback
185
257
186
258
If you encounter bugs or have suggestions, please
187
259
[open an issue](https://github.com/Azure/azure-sdk-for-go/issues) and assign the `Azure.Identity` label.
188
260
189
-
# Contributing
261
+
##Contributing
190
262
191
263
This project welcomes contributions and suggestions. Most contributions require
192
264
you to agree to a Contributor License Agreement (CLA) declaring that you have
@@ -206,6 +278,7 @@ or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any
0 commit comments