Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into pr/daviwil/5669
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Oct 22, 2019
1 parent 15a6b1f commit 126f6f5
Show file tree
Hide file tree
Showing 64 changed files with 387 additions and 196 deletions.
4 changes: 2 additions & 2 deletions sdk/core/core-lro/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export * from "./pollOperation";
export * from "./poller";
9 changes: 6 additions & 3 deletions sdk/core/core-lro/src/pollOperation.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { AbortSignalLike } from "@azure/abort-controller";

export interface PollOperationState<TResult> {
started?: boolean;
completed?: boolean;
cancelled?: boolean;
isStarted?: boolean;
isCompleted?: boolean;
isCancelled?: boolean;
error?: Error;
result?: TResult;
}
Expand Down
5 changes: 4 additions & 1 deletion sdk/core/core-lro/src/poller.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { PollOperation, PollOperationState } from "./pollOperation";
import { AbortSignalLike } from "@azure/abort-controller";

Expand Down Expand Up @@ -134,7 +137,7 @@ export abstract class Poller<TState, TResult> implements PollerLike<TState, TRes

public isDone(): boolean {
const state = this.getOperationState();
return Boolean(state.completed || state.cancelled || state.error);
return Boolean(state.isCompleted || state.isCancelled || state.error);
}

public stopPolling(): void {
Expand Down
3 changes: 3 additions & 0 deletions sdk/core/core-lro/test/abort.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import assert from "assert";
import { delay, WebResource, HttpHeaders } from "@azure/core-http";
import { TestClient } from "./utils/testClient";
Expand Down
14 changes: 9 additions & 5 deletions sdk/core/core-lro/test/testClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

Expand All @@ -6,6 +9,7 @@ import { delay, WebResource, HttpHeaders, isNode } from "@azure/core-http";
import { TestClient } from "./utils/testClient";
import { PollerStoppedError, PollerCancelledError } from "../src";
import { TestTokenCredential } from "./utils/testTokenCredential";
import { TestOperationState } from "./utils/testOperation";

const testHttpHeaders: HttpHeaders = new HttpHeaders();
const testHttpRequest: WebResource = new WebResource();
Expand Down Expand Up @@ -48,12 +52,12 @@ describe("Long Running Operations - custom client", function() {
const result = await poller.pollUntilDone();

// Checking the serialized version of the operation
let serializedOperation = JSON.parse(poller.toString());
assert.ok(serializedOperation.state.started);
let serializedOperation: { state: TestOperationState } = JSON.parse(poller.toString());
assert.ok(serializedOperation.state.isStarted);

assert.ok(poller.initialResponse!.parsedBody.started);
assert.ok(poller.previousResponse!.parsedBody.finished);
assert.ok(poller.getOperationState().completed);
assert.ok(poller.getOperationState().isCompleted);
assert.equal(result, "Done");
});

Expand Down Expand Up @@ -93,7 +97,7 @@ describe("Long Running Operations - custom client", function() {

await poller.pollUntilDone();
assert.ok(poller.previousResponse!.parsedBody.finished);
assert.ok(poller.getOperationState().completed);
assert.ok(poller.getOperationState().isCompleted);

result = await poller.getResult();
assert.equal(result, "Done");
Expand Down Expand Up @@ -124,7 +128,7 @@ describe("Long Running Operations - custom client", function() {
assert.equal(client.totalSentRequests, 11);

await poller.cancelOperation();
assert.ok(poller.getOperationState().cancelled);
assert.ok(poller.getOperationState().isCancelled);

// Cancelling a poller stops it
assert.ok(poller.isStopped());
Expand Down
3 changes: 3 additions & 0 deletions sdk/core/core-lro/test/utils/testClient.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import {
ServiceClientCredentials,
ServiceClientOptions,
Expand Down
3 changes: 3 additions & 0 deletions sdk/core/core-lro/test/utils/testNonCancellablePoller.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { delay, RequestOptionsBase, HttpOperationResponse } from "@azure/core-http";
import { Poller } from "../../src";
import { TestServiceClient } from "./testServiceClient";
Expand Down
9 changes: 6 additions & 3 deletions sdk/core/core-lro/test/utils/testOperation.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { HttpOperationResponse, RequestOptionsBase } from "@azure/core-http";
import { AbortSignalLike } from "@azure/abort-controller";
import { PollOperationState, PollOperation } from "../../src";
Expand Down Expand Up @@ -30,10 +33,10 @@ async function update(
if (!initialResponse) {
response = await client.sendInitialRequest(new TestWebResource(abortSignal));
this.state.initialResponse = response;
this.state.started = true;
this.state.isStarted = true;
} else if (doFinalResponse) {
response = await client.sendFinalRequest(new TestWebResource(abortSignal));
this.state.completed = true;
this.state.isCompleted = true;
this.state.result = "Done";
this.state.previousResponse = response;
} else {
Expand Down Expand Up @@ -78,7 +81,7 @@ async function cancel(

return makeOperation({
...this.state,
cancelled: true,
isCancelled: true,
previousResponse: response
});
}
Expand Down
3 changes: 3 additions & 0 deletions sdk/core/core-lro/test/utils/testPoller.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { delay, RequestOptionsBase, HttpOperationResponse } from "@azure/core-http";
import { Poller } from "../../src";
import { TestServiceClient } from "./testServiceClient";
Expand Down
3 changes: 3 additions & 0 deletions sdk/core/core-lro/test/utils/testServiceClient.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import {
HttpOperationResponse,
ServiceClient,
Expand Down
3 changes: 3 additions & 0 deletions sdk/core/core-lro/test/utils/testTokenCredential.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http";

export class TestTokenCredential implements TokenCredential {
Expand Down
3 changes: 3 additions & 0 deletions sdk/core/core-lro/test/utils/testWebResource.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { WebResource } from "@azure/core-http";
import { AbortSignalLike } from "@azure/abort-controller";

Expand Down
12 changes: 8 additions & 4 deletions sdk/identity/identity/review/identity.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export const AuthenticationErrorName = "AuthenticationError";

// @public
export class AuthorizationCodeCredential implements TokenCredential {
constructor(tenantId: string, clientId: string, clientSecret: string | undefined, authorizationCode: string, redirectUri: string, options?: IdentityClientOptions);
constructor(tenantId: string | "common", clientId: string, clientSecret: string, authorizationCode: string, redirectUri: string, options?: IdentityClientOptions);
constructor(tenantId: string | "common", clientId: string, authorizationCode: string, redirectUri: string, options?: IdentityClientOptions);
getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
}

Expand Down Expand Up @@ -64,7 +65,7 @@ export class DefaultAzureCredential extends ChainedTokenCredential {

// @public
export class DeviceCodeCredential implements TokenCredential {
constructor(tenantId: string, clientId: string, userPromptCallback: DeviceCodePromptCallback, options?: IdentityClientOptions);
constructor(tenantId: string | "organizations", clientId: string, userPromptCallback: DeviceCodePromptCallback, options?: IdentityClientOptions);
getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
}

Expand Down Expand Up @@ -106,23 +107,26 @@ export interface IdentityClientOptions extends ServiceClientOptions {

// @public
export class InteractiveBrowserCredential implements TokenCredential {
constructor(tenantId: string, clientId: string, options?: InteractiveBrowserCredentialOptions);
constructor(options?: InteractiveBrowserCredentialOptions);
getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
}

// @public
export interface InteractiveBrowserCredentialOptions extends IdentityClientOptions {
clientId?: string;
loginStyle?: BrowserLoginStyle;
postLogoutRedirectUri?: string | (() => string);
redirectUri?: string | (() => string);
tenantId?: string;
}

// @public
export const logger: import("@azure/logger").AzureLogger;

// @public
export class ManagedIdentityCredential implements TokenCredential {
constructor(clientId?: string, options?: IdentityClientOptions);
constructor(clientId: string, options?: IdentityClientOptions);
constructor(options?: IdentityClientOptions);
getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
}

Expand Down
19 changes: 19 additions & 0 deletions sdk/identity/identity/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

/**
* The default client ID for authentication
* @internal
* @ignore
*/
// TODO: temporary - this is the Azure CLI clientID - we'll replace it when
// Developer Sign On application is available
// https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/identity/Azure.Identity/src/Constants.cs#L9
export const DeveloperSignOnClientId = "04b07795-8ddb-461a-bbee-02f9e1bf7b46";

/**
* The default tenant for authentication
* @internal
* @ignore
*/
export const DefaultTenantId = "common";
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,35 @@
/* eslint-disable @typescript-eslint/no-unused-vars */

import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http";
import { IdentityClientOptions } from "../client/identityClient";
import { IdentityClientOptions } from '../client/identityClient';

const BrowserNotSupportedError = new Error(
"AuthorizationCodeCredential is not supported in the browser. InteractiveBrowserCredential is more appropriate for this use case."
);

export class AuthorizationCodeCredential implements TokenCredential {
constructor(
tenantId: string,
tenantId: string | "common",
clientId: string,
clientSecret: string | undefined,
clientSecret: string,
authorizationCode: string,
redirectUri: string,
options?: IdentityClientOptions
);
constructor(
tenantId: string | "common",
clientId: string,
authorizationCode: string,
redirectUri: string,
options?: IdentityClientOptions
);
constructor(
tenantId: string | "common",
clientId: string,
clientSecretOrAuthorizationCode: string,
authorizationCodeOrRedirectUri: string,
redirectUriOrOptions: string | IdentityClientOptions | undefined,
options?: IdentityClientOptions
) {
throw BrowserNotSupportedError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import qs from "qs";
import { createSpan } from "../util/tracing";
import { AuthenticationErrorName } from "../client/errors";
import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http";
import { IdentityClientOptions, IdentityClient, TokenResponse } from "../client/identityClient";
import { IdentityClient, TokenResponse, IdentityClientOptions } from "../client/identityClient";
import { CanonicalCode } from "@azure/core-tracing";

/**
Expand Down Expand Up @@ -37,10 +37,9 @@ export class AuthorizationCodeCredential implements TokenCredential {
* https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/identity/identity/samples/authorizationCodeSample.ts
*
* @param tenantId The Azure Active Directory tenant (directory) ID or name.
* 'common' may be used when dealing with multi-tenant scenarios.
* @param clientId The client (application) ID of an App Registration in the tenant.
* @param clientSecret A client secret that was generated for the App Registration or
'undefined' if using this credential in a desktop or mobile
application.
* @param clientSecret A client secret that was generated for the App Registration
* @param authorizationCode An authorization code that was received from following the
authorization code flow. This authorization code must not
have already been used to obtain an access token.
Expand All @@ -49,19 +48,71 @@ export class AuthorizationCodeCredential implements TokenCredential {
* @param options Options for configuring the client which makes the access token request.
*/
constructor(
tenantId: string,
tenantId: string | "common",
clientId: string,
clientSecret: string | undefined,
clientSecret: string,
authorizationCode: string,
redirectUri: string,
options?: IdentityClientOptions
);
/**
* Creates an instance of CodeFlowCredential with the details needed
* to request an access token using an authentication that was obtained
* from Azure Active Directory.
*
* It is currently necessary for the user of this credential to initiate
* the authorization code flow to obtain an authorization code to be used
* with this credential. A full example of this flow is provided here:
*
* https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/identity/identity/samples/authorizationCodeSample.ts
*
* @param tenantId The Azure Active Directory tenant (directory) ID or name.
* 'common' may be used when dealing with multi-tenant scenarios.
* @param clientId The client (application) ID of an App Registration in the tenant.
* @param authorizationCode An authorization code that was received from following the
authorization code flow. This authorization code must not
have already been used to obtain an access token.
* @param redirectUri The redirect URI that was used to request the authorization code.
Must be the same URI that is configured for the App Registration.
* @param options Options for configuring the client which makes the access token request.
*/
constructor(
tenantId: string | "common",
clientId: string,
authorizationCode: string,
redirectUri: string,
options?: IdentityClientOptions
);
/**
* @ignore
* @internal
*/
constructor(
tenantId: string | "common",
clientId: string,
clientSecretOrAuthorizationCode: string,
authorizationCodeOrRedirectUri: string,
redirectUriOrOptions: string | IdentityClientOptions | undefined,
options?: IdentityClientOptions
) {
this.identityClient = new IdentityClient(options);
this.tenantId = tenantId;
this.clientId = clientId;
this.clientSecret = clientSecret;
this.authorizationCode = authorizationCode;
this.redirectUri = redirectUri;
this.tenantId = tenantId;

if (typeof redirectUriOrOptions === "string") {
// the clientId+clientSecret constructor
this.clientSecret = clientSecretOrAuthorizationCode;
this.authorizationCode = authorizationCodeOrRedirectUri;
this.redirectUri = redirectUriOrOptions;
// options okay
} else {
// clientId only
this.clientSecret = undefined;
this.authorizationCode = clientSecretOrAuthorizationCode;
this.redirectUri = authorizationCodeOrRedirectUri as string;
options = redirectUriOrOptions as IdentityClientOptions;
}

this.identityClient = new IdentityClient(options);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class DefaultAzureCredential extends ChainedTokenCredential {
constructor(identityClientOptions?: IdentityClientOptions) {
super(
new EnvironmentCredential(identityClientOptions),
new ManagedIdentityCredential(undefined, identityClientOptions)
new ManagedIdentityCredential(identityClientOptions)
);
}
}
Loading

0 comments on commit 126f6f5

Please sign in to comment.