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

[Communication] - Identity - Auth with Token Credential #12906

Merged
merged 24 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3aff0f5
[communicationIdentityClient] adding new constructor using token cred…
JoshuaLai Dec 11, 2020
47d97dd
[communicationIdentityClient] new implementation to take pass in toke…
JoshuaLai Dec 15, 2020
a7bf1cb
Revert changes to this file
JoshuaLai Dec 15, 2020
5fe3f51
[communicationIdentityClient] adding linted files
JoshuaLai Dec 15, 2020
c894dfb
[communicationIdentityClient] remove unused import
JoshuaLai Dec 15, 2020
86725ee
[communicationIdentityClient] fixing the comments as per PR feedback
JoshuaLai Dec 15, 2020
ca71362
[communicationIdentityClient] import for bearerTokenAuthenticationPolicy
JoshuaLai Dec 15, 2020
6270623
[Token] adding in live tests for constructor with token credential
JoshuaLai Dec 21, 2020
7922ca1
[Format] rush format fixes
JoshuaLai Dec 21, 2020
75fd688
[karma] added the environment vars to karma for browser
JoshuaLai Dec 21, 2020
42d048f
[karma] format fixes by rush
JoshuaLai Dec 21, 2020
a3fb197
[recordedClient] adding in a mock token credential for playback mode
JoshuaLai Jan 4, 2021
3750344
[Recordings] removing the port from endpoint url
JoshuaLai Jan 5, 2021
90498b9
[recordedClient] using ClientSecretCredential instead of DefaultAzure…
JoshuaLai Jan 5, 2021
4846fb2
[communicationIdentityClientWithToken] for browser we stick to the ol…
JoshuaLai Jan 8, 2021
b078fce
[createRecordedCommunicationIdentityClient] formatting fixes
JoshuaLai Jan 8, 2021
d91bf3a
[README] update the read me samples and the changelog
JoshuaLai Jan 8, 2021
7c7181f
[communicationIdentityClientWithToken] updating test to skip if the t…
JoshuaLai Jan 12, 2021
b61fdcd
[communicationAuthPolicy] Created new auth policy to so client has cl…
JoshuaLai Jan 12, 2021
9ee5228
[format] rush format fixes
JoshuaLai Jan 12, 2021
ab561e5
[recordedClient] remove the sinon lib
JoshuaLai Jan 12, 2021
c71519e
[rush] format fixes
JoshuaLai Jan 12, 2021
b71137b
Merge branch 'master' into feature/authidentity
JoshuaLai Jan 12, 2021
2bb31cf
Update sdk/communication/communication-administration/src/communicati…
JoshuaLai Jan 13, 2021
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
4 changes: 4 additions & 0 deletions sdk/communication/communication-administration/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
- Fixed a bug where poller options were ignored for `beginReleasePhoneNumbers`, `beginReservePhoneNumbers` and `beginPurchaseReservation`.
- Fixed paging for `listPhoneNumbers`, `listPhonePlanGroups`, `listPhonePlans`, `listReleases`, `listSearches`, `listSupportedCountries`.

### Added

- `CommunicationIdentityClient` added a constructor that supports `TokenCredential`.

## 1.0.0-beta.3 (2020-11-16)

### Added
Expand Down
9 changes: 9 additions & 0 deletions sdk/communication/communication-administration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ const connectionString = `endpoint=HOST;accessKey=KEY`;
const client = new CommunicationIdentityClient(connectionString);
```

### Using a `TokenCredential`

```typescript
import { CommunicationIdentityClient } from "@azure/communication-administration";

let credential = new DefaultAzureCredential();
const client = new CommunicationIdentityClient(HOST, credential);
```

If you use a key to initialize the client you will also need to provide the appropriate endpoint. You can get this endpoint from your Communication Services resource in [Azure Portal][azure_portal].

## Usage
Expand Down
10 changes: 9 additions & 1 deletion sdk/communication/communication-administration/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,15 @@ module.exports = function(config) {
// inject following environment values into browser testing with window.__env__
// environment values MUST be exported or set with same console running "karma start"
// https://www.npmjs.com/package/karma-env-preprocessor
envPreprocessor: ["TEST_MODE", "COMMUNICATION_CONNECTION_STRING", "INCLUDE_PHONENUMBER_TESTS"],
envPreprocessor: [
"TEST_MODE",
"COMMUNICATION_CONNECTION_STRING",
"INCLUDE_PHONENUMBER_TESTS",
"COMMUNICATION_ENDPOINT",
"AZURE_CLIENT_ID",
"AZURE_CLIENT_SECRET",
"AZURE_TENANT_ID"
],

// test results reporter to use
// possible values: 'dots', 'progress'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/test-utils-recorder": "^1.0.0",
"@azure/identity": "^1.1.0",
"@microsoft/api-documenter": "~7.8.17",
"@microsoft/api-extractor": "7.7.11",
"@rollup/plugin-commonjs": "11.0.2",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { PagedAsyncIterableIterator } from '@azure/core-paging';
import { PipelineOptions } from '@azure/core-http';
import { PollerLike } from '@azure/core-lro';
import { PollOperationState } from '@azure/core-lro';
import { TokenCredential } from '@azure/core-auth';

// @public
export interface AcquiredPhoneNumber {
Expand Down Expand Up @@ -78,6 +79,7 @@ export interface CarrierDetails {
export class CommunicationIdentityClient {
constructor(connectionString: string, options?: CommunicationIdentityOptions);
constructor(url: string, credential: KeyCredential, options?: CommunicationIdentityOptions);
constructor(url: string, credential: TokenCredential, options?: CommunicationIdentityOptions);
createUser(options?: OperationOptions): Promise<CreateUserResponse>;
deleteUser(user: CommunicationUserIdentifier, options?: OperationOptions): Promise<VoidResponse>;
issueToken(user: CommunicationUserIdentifier, scopes: TokenScope[], options?: OperationOptions): Promise<IssueTokenResponse>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// Licensed under the MIT license.

import {
createCommunicationAccessKeyCredentialPolicy,
createCommunicationAuthPolicy,
parseClientArguments,
isKeyCredential,
CommunicationUserIdentifier
} from "@azure/communication-common";
import { KeyCredential } from "@azure/core-auth";
import { isTokenCredential, KeyCredential, TokenCredential } from "@azure/core-auth";
import {
InternalPipelineOptions,
createPipelineFromOptions,
Expand All @@ -30,7 +30,7 @@ import { VoidResponse } from "../common/models";
import { attachHttpResponse } from "../common/mappers";

const isCommunicationIdentityOptions = (options: any): options is CommunicationIdentityOptions =>
options && !isKeyCredential(options);
options && !isTokenCredential(options) && !isKeyCredential(options);

/**
* Client class for interacting with Azure Communication Services User Token Management.
Expand Down Expand Up @@ -60,7 +60,17 @@ export class CommunicationIdentityClient {
credential: KeyCredential,
options?: CommunicationIdentityOptions
);

/**
* Initializes a new instance of the CommunicationIdentity class using a TokenCredential.
* @param url The endpoint of the service (ex: https://contoso.eastus.communications.azure.net)
* @param credential TokenCredential that is used to authenticate requests to the service.
* @param options Optional. Options to configure the HTTP pipeline.
*/
public constructor(
0rland0Wats0n marked this conversation as resolved.
Show resolved Hide resolved
url: string,
credential: TokenCredential,
options?: CommunicationIdentityOptions
);
/**
* Creates an instance of CommunicationIdentity.
*
Expand All @@ -70,7 +80,7 @@ export class CommunicationIdentityClient {
*/
public constructor(
connectionStringOrUrl: string,
credentialOrOptions?: KeyCredential | CommunicationIdentityOptions,
credentialOrOptions?: KeyCredential | CommunicationIdentityOptions | TokenCredential,
maybeOptions: CommunicationIdentityOptions = {}
) {
const { url, credential } = parseClientArguments(connectionStringOrUrl, credentialOrOptions);
0rland0Wats0n marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -98,9 +108,8 @@ export class CommunicationIdentityClient {
}
};

const authPolicy = createCommunicationAccessKeyCredentialPolicy(credential);
const authPolicy = createCommunicationAuthPolicy(credential);
const pipeline = createPipelineFromOptions(internalPipelineOptions, authPolicy);

this.client = new IdentityRestClient(url, pipeline).communicationIdentity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class PhoneNumberAdministrationClient {
}
};

const authPolicy = createCommunicationAccessKeyCredentialPolicy(credential);
const authPolicy = createCommunicationAccessKeyCredentialPolicy(credential as KeyCredential);
const pipeline = createPipelineFromOptions(internalPipelineOptions, authPolicy);
this.client = new PhoneNumberRestClient(url, pipeline).phoneNumberAdministration;
}
Expand Down
Loading