-
Notifications
You must be signed in to change notification settings - Fork 2.1k
AAD sample and README revised, and correct indentation #7074
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f3e2f66
revised aad sample and readme
27b1143
indentation
f4a1b19
add ReadmeSamples and update readme automatically
5661c8f
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-java …
9da9b5a
fixes spotbugs
df123e8
try catch final revised
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,7 +107,9 @@ az appconfig create --name <config-store-name> --resource-group <resource-group- | |
|
|
||
| In order to interact with the App Configuration service you'll need to create an instance of the Configuration Client class. To make this possible you'll need the connection string of the Configuration Store. | ||
|
|
||
| #### Get credentials | ||
| #### Use connection string | ||
|
|
||
| ##### Get credentials | ||
|
|
||
| Use the [Azure CLI][azure_cli] snippet below to get the connection string from the Configuration Store. | ||
|
|
||
|
|
@@ -117,7 +119,7 @@ az appconfig credential list --name <config-store-name> | |
|
|
||
| Alternatively, get the connection string from the Azure Portal. | ||
|
|
||
| #### Create a Configuration Client | ||
| ##### Create a Configuration Client | ||
|
|
||
| Once you have the value of the connection string you can create the configuration client: | ||
|
|
||
|
|
@@ -135,14 +137,60 @@ ConfigurationAsyncClient client = new ConfigurationClientBuilder() | |
| .buildAsyncClient(); | ||
| ``` | ||
|
|
||
| You can also use `TokenCredential` to create a configuration client, such as an Azure Active Directory (AAD) token. | ||
| Unlike a connection string if you're using an AAD token you must supply the endpoint of AppConfiguration service. The | ||
| endpoint can be obtained by going to your App Configuration instance in the Azure portal and navigating to "Overview" | ||
| page and look for the "Endpoint" keyword. | ||
| #### Use AAD token | ||
|
|
||
| Here we demonstrate using [DefaultAzureCredential][default_cred_ref] | ||
| to authenticate as a service principal. However, the configuration client | ||
| accepts any [azure-identity][azure_identity] credential. See the | ||
| [azure-identity][azure_identity] documentation for more information about other | ||
| credentials. | ||
|
|
||
| ##### Create a service principal (optional) | ||
| This [Azure CLI][azure_cli] snippet shows how to create a | ||
| new service principal. Before using it, replace "your-application-name" with | ||
| the appropriate name for your service principal. | ||
|
|
||
| Create a service principal: | ||
| ```Bash | ||
| az ad sp create-for-rbac --name http://my-application --skip-assignment | ||
| ``` | ||
|
|
||
| > Output: | ||
| > ```json | ||
| > { | ||
| > "appId": "generated app id", | ||
| > "displayName": "my-application", | ||
| > "name": "http://my-application", | ||
| > "password": "random password", | ||
| > "tenant": "tenant id" | ||
| > } | ||
| > ``` | ||
|
|
||
| Use the output to set **AZURE_CLIENT_ID** ("appId" above), **AZURE_CLIENT_SECRET** | ||
| ("password" above) and **AZURE_TENANT_ID** ("tenant" above) environment variables. | ||
| The following example shows a way to do this in Bash: | ||
| ```Bash | ||
| export AZURE_CLIENT_ID="generated app id" | ||
| export AZURE_CLIENT_SECRET="random password" | ||
| export AZURE_TENANT_ID="tenant id" | ||
| ``` | ||
|
|
||
| Assign one of the applicable [App Configuration roles][app_config_role] to the service principal. | ||
|
|
||
| ##### Create a client | ||
| Once the **AZURE_CLIENT_ID**, **AZURE_CLIENT_SECRET** and | ||
| **AZURE_TENANT_ID** environment variables are set, | ||
| [DefaultAzureCredential][default_cred_ref] will be able to authenticate the | ||
| configuration client. | ||
|
|
||
| Constructing the client also requires your configuration store's URL, which you can | ||
| get from the Azure CLI or the Azure Portal. In the Azure Portal, the URL can be found listed as the service "Endpoint" | ||
|
|
||
| ```Java | ||
| // An example of using TokenCredential and Endpoint to create a synchronous client | ||
| TokenCredential credential = new DefaultAzureCredential(); | ||
| import com.azure.identity.DefaultAzureCredential; | ||
| import com.azure.identity.DefaultAzureCredentialBuilder; | ||
|
|
||
| DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build(); | ||
|
|
||
| ConfigurationClient client = new ConfigurationClientBuilder() | ||
| .credential(credential) | ||
|
|
@@ -337,23 +385,26 @@ When you submit a pull request, a CLA-bot will automatically determine whether y | |
| This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For more information see the [Code of Conduct FAQ][coc_faq] or contact [[email protected]][coc_contact] with any additional questions or comments. | ||
|
|
||
| <!-- LINKS --> | ||
| [add_headers_from_context_policy]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core/src/main/java/com/azure/core/http/policy/AddHeadersFromContextPolicy.java | ||
| [api_documentation]: https://aka.ms/java-docs | ||
| [app_config_store]: https://docs.microsoft.com/azure/azure-app-configuration/quickstart-dotnet-core-app#create-an-app-configuration-store | ||
| [app_config_role]: https://github.com/Azure/AppConfiguration/blob/master/docs/REST/authorization/aad.md | ||
| [azconfig_docs]: https://docs.microsoft.com/azure/azure-app-configuration | ||
| [azure_cli]: https://docs.microsoft.com/cli/azure | ||
| [azure_identity]: https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/identity/azure-identity | ||
| [azure_subscription]: https://azure.microsoft.com/free | ||
| [cla]: https://cla.microsoft.com | ||
| [coc]: https://opensource.microsoft.com/codeofconduct/ | ||
| [coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ | ||
| [coc_contact]: mailto:[email protected] | ||
| [default_cred_ref]: https://azuresdkdocs.blob.core.windows.net/$web/java/azure-identity/1.0.1/com/azure/identity/DefaultAzureCredential.html | ||
| [maven]: https://maven.apache.org/ | ||
| [package]: https://search.maven.org/artifact/com.azure/azure-data-appconfiguration | ||
| [performance_tuning]: https://github.com/Azure/azure-sdk-for-java/wiki/Performance-Tuning | ||
| [rest_api]: https://github.com/Azure/AppConfiguration#rest-api-reference | ||
| [samples]: src/samples/java/com/azure/data/appconfiguration | ||
| [samples_readme]: src/samples/README.md | ||
| [source_code]: src | ||
| [spring_quickstart]: https://docs.microsoft.com/azure/azure-app-configuration/quickstart-java-spring-app | ||
| [performance_tuning]: https://github.com/Azure/azure-sdk-for-java/wiki/Performance-Tuning | ||
| [add_headers_from_context_policy]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core/src/main/java/com/azure/core/http/policy/AddHeadersFromContextPolicy.java | ||
|
|
||
|  | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer to use code embedding for READMEs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.