-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Support AAD Authentication in Form Recognizer #11156
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 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
71154c6
added AAD support
f90c671
resolve conflict
1f744ab
address feedbacks
aacc161
resolve conflict
dd1786e
resolve conflict
083b52d
address iscai feedbacks
d04924d
refactor
68d1868
remove non-used json
bc653df
add api key back
1472dbe
add aad to training client
e887003
add license title
4ee0910
validate null of account properoty values instead of real value
70d6222
hide model id
3c6a265
minor feedbacks
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
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
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
65 changes: 65 additions & 0 deletions
65
...re-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/AadAuthenticationTest.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.ai.formrecognizer; | ||
|
|
||
| import com.azure.ai.formrecognizer.models.CustomFormModelInfo; | ||
| import com.azure.core.credential.AzureKeyCredential; | ||
| import com.azure.core.http.HttpClient; | ||
| import com.azure.core.test.TestBase; | ||
| import com.azure.core.util.Configuration; | ||
| import com.azure.identity.DefaultAzureCredentialBuilder; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
|
|
||
| import static com.azure.ai.formrecognizer.FormTrainingClientTestBase.AZURE_FORM_RECOGNIZER_API_KEY; | ||
| import static com.azure.ai.formrecognizer.FormTrainingClientTestBase.AZURE_FORM_RECOGNIZER_ENDPOINT; | ||
| import static com.azure.ai.formrecognizer.TestUtils.DISPLAY_NAME_WITH_ARGUMENTS; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| /** | ||
| * Test for using Azure Active Directory token credential. | ||
| */ | ||
| public class AadAuthenticationTest extends TestBase { | ||
| private static FormTrainingClient client; | ||
|
|
||
| private void setup(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { | ||
| final String endpoint = getEndpoint(); | ||
| if (interceptorManager.isPlaybackMode()) { | ||
| // In playback mode use connection string because CI environment doesn't set up to support AAD | ||
|
mssfang marked this conversation as resolved.
Outdated
|
||
| client = new FormRecognizerClientBuilder() | ||
| .credential(new AzureKeyCredential(getApiKey())) | ||
| .endpoint(endpoint) | ||
| .httpClient(interceptorManager.getPlaybackClient()) | ||
| .buildClient().getFormTrainingClient(); | ||
| } else { | ||
| client = new FormRecognizerClientBuilder() | ||
| .httpClient(httpClient) | ||
| .credential(new DefaultAzureCredentialBuilder().build()) | ||
| .endpoint(endpoint) | ||
| .addPolicy(interceptorManager.getRecordPolicy()) // Record | ||
| .serviceVersion(serviceVersion) | ||
| .buildClient().getFormTrainingClient(); | ||
| } | ||
| } | ||
|
|
||
| @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) | ||
| @MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters") | ||
| public void aadAuthenticationTest(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { | ||
|
mssfang marked this conversation as resolved.
Outdated
|
||
| setup(httpClient, serviceVersion); | ||
| for (CustomFormModelInfo modelInfo : client.getModelInfos()) { | ||
| assertTrue(modelInfo.getModelId() != null && modelInfo.getCreatedOn() != null | ||
| && modelInfo.getLastUpdatedOn() != null && modelInfo.getStatus() != null); | ||
| } | ||
| } | ||
|
|
||
| private String getApiKey() { | ||
| return interceptorManager.isPlaybackMode() ? "apiKeyInPlayback" | ||
| : Configuration.getGlobalConfiguration().get(AZURE_FORM_RECOGNIZER_API_KEY); | ||
| } | ||
|
|
||
| private String getEndpoint() { | ||
| return interceptorManager.isPlaybackMode() ? "https://localhost:8080" | ||
| : Configuration.getGlobalConfiguration().get(AZURE_FORM_RECOGNIZER_ENDPOINT); | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.