Skip to content
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

[FormRecognizer] Bring back Azure AD credential support #8898

Merged
merged 2 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { PipelineOptions } from '@azure/core-http';
import { PollerLike } from '@azure/core-lro';
import { PollOperationState } from '@azure/core-lro';
import { RestResponse } from '@azure/core-http';
import { TokenCredential } from '@azure/identity';

// @public
export interface AccountProperties {
Expand Down Expand Up @@ -196,7 +197,7 @@ export type FormPollerLike = PollerLike<PollOperationState<RecognizeFormResultRe

// @public
export class FormRecognizerClient {
constructor(endpointUrl: string, credential: KeyCredential, options?: FormRecognizerClientOptions);
constructor(endpointUrl: string, credential: TokenCredential | KeyCredential, options?: FormRecognizerClientOptions);
beginRecognizeContent(data: FormRecognizerRequestBody, contentType?: ContentType, options?: BeginRecognizeContentOptions): Promise<ContentPollerLike>;
beginRecognizeContentFromUrl(documentUrl: string, options?: BeginRecognizeContentOptions): Promise<ContentPollerLike>;
beginRecognizeForms(modelId: string, data: FormRecognizerRequestBody, contentType?: ContentType, options?: BeginRecognizeFormsOptions): Promise<FormPollerLike>;
Expand Down Expand Up @@ -260,7 +261,7 @@ export interface FormText {

// @public
export class FormTrainingClient {
constructor(endpointUrl: string, credential: KeyCredential, options?: FormRecognizerClientOptions);
constructor(endpointUrl: string, credential: TokenCredential | KeyCredential, options?: FormRecognizerClientOptions);
beginTraining(blobContainerUrl: string, useLabels?: boolean, options?: BeginTrainingOptions<FormModelResponse>): Promise<PollerLike<PollOperationState<FormModelResponse>, FormModelResponse>>;
deleteModel(modelId: string, options?: DeleteModelOptions): Promise<RestResponse>;
readonly endpointUrl: string;
Expand Down Expand Up @@ -588,8 +589,8 @@ export type ValueTypes = "string" | "date" | "time" | "phoneNumber" | "number" |

// Warnings were encountered during analysis:
//
// src/formRecognizerClient.ts:70:3 - (ae-forgotten-export) The symbol "BeginRecognizePollState" needs to be exported by the entry point index.d.ts
// src/formTrainingClient.ts:68:3 - (ae-forgotten-export) The symbol "BeginTrainingPollState" needs to be exported by the entry point index.d.ts
// src/formRecognizerClient.ts:73:3 - (ae-forgotten-export) The symbol "BeginRecognizePollState" needs to be exported by the entry point index.d.ts
// src/formTrainingClient.ts:71:3 - (ae-forgotten-export) The symbol "BeginTrainingPollState" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)

Expand Down
15 changes: 10 additions & 5 deletions sdk/formrecognizer/ai-form-recognizer/src/formRecognizerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import {
createPipelineFromOptions,
InternalPipelineOptions,
isTokenCredential,
bearerTokenAuthenticationPolicy,
operationOptionsToRequestOptionsBase,
AbortSignalLike,
ServiceClientCredentials
} from "@azure/core-http";
import { TokenCredential } from '@azure/identity';
import { KeyCredential } from "@azure/core-auth";
import { SDK_VERSION } from "./constants";
import { SDK_VERSION, DEFAULT_COGNITIVE_SCOPE } from "./constants";
import { logger } from "./logger";
import { createSpan } from "./tracing";
import {
Expand Down Expand Up @@ -182,7 +185,7 @@ export class FormRecognizerClient {
* @internal
* @ignore
*/
private readonly credential: KeyCredential;
private readonly credential: TokenCredential | KeyCredential;

/**
* @internal
Expand All @@ -204,12 +207,12 @@ export class FormRecognizerClient {
* );
* ```
* @param {string} endpointUrl Url to an Azure Form Recognizer service endpoint
* @param {KeyCredential} credential Used to authenticate requests to the service.
* @param {TokenCredential | KeyCredential} credential Used to authenticate requests to the service.
* @param {FormRecognizerClientOptions} [options] Used to configure the Form Recognizer client.
*/
constructor(
endpointUrl: string,
credential: KeyCredential,
credential: TokenCredential | KeyCredential,
options: FormRecognizerClientOptions = {}
) {
this.endpointUrl = endpointUrl;
Expand All @@ -226,7 +229,9 @@ export class FormRecognizerClient {
pipelineOptions.userAgentOptions.userAgentPrefix = libInfo;
}

const authPolicy = createFormRecognizerAzureKeyCredentialPolicy(credential);
const authPolicy = isTokenCredential(credential)
? bearerTokenAuthenticationPolicy(credential, DEFAULT_COGNITIVE_SCOPE)
: createFormRecognizerAzureKeyCredentialPolicy(credential);

const internalPipelineOptions: InternalPipelineOptions = {
...pipelineOptions,
Expand Down
13 changes: 9 additions & 4 deletions sdk/formrecognizer/ai-form-recognizer/src/formTrainingClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
import {
createPipelineFromOptions,
InternalPipelineOptions,
isTokenCredential,
bearerTokenAuthenticationPolicy,
operationOptionsToRequestOptionsBase,
RestResponse,
ServiceClientCredentials
} from "@azure/core-http";
import { TokenCredential } from '@azure/identity';
import { KeyCredential } from "@azure/core-auth";
import { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging";
import "@azure/core-paging";
import { SDK_VERSION } from "./constants";
import { SDK_VERSION, DEFAULT_COGNITIVE_SCOPE } from "./constants";
import { logger } from "./logger";
import { createSpan } from "./tracing";
import { CanonicalCode } from "@opentelemetry/api";
Expand Down Expand Up @@ -98,12 +101,12 @@ export class FormTrainingClient {
* );
* ```
* @param {string} endpointUrl Url to an Azure Form Recognizer service endpoint
* @param {AzureKeyCredential} credential Used to authenticate requests to the service.
* @param {TokenCredential | KeyCredential} credential Used to authenticate requests to the service.
* @param {FormRecognizerClientOptions} [options] Used to configure the client.
*/
constructor(
endpointUrl: string,
credential: KeyCredential,
credential: TokenCredential | KeyCredential,
options: FormRecognizerClientOptions = {}
) {
this.endpointUrl = endpointUrl;
Expand All @@ -119,7 +122,9 @@ export class FormTrainingClient {
pipelineOptions.userAgentOptions.userAgentPrefix = libInfo;
}

const authPolicy = createFormRecognizerAzureKeyCredentialPolicy(credential);
const authPolicy = isTokenCredential(credential)
? bearerTokenAuthenticationPolicy(credential, DEFAULT_COGNITIVE_SCOPE)
: createFormRecognizerAzureKeyCredentialPolicy(credential);

const internalPipelineOptions: InternalPipelineOptions = {
...pipelineOptions,
Expand Down