Skip to content

Commit

Permalink
Adding AAD authetication and making the "to" property optional (#23945)
Browse files Browse the repository at this point in the history
* Adding AAD token support

* Adding swagger directive to make "to" field optional

* Fixing formatting

Co-authored-by: Yogesh Mohanraj <ymohanraj@microsoft.com>
  • Loading branch information
yogeshmo and Yogesh Mohanraj committed Nov 22, 2022
1 parent 876ce3c commit f6d4cb8
Show file tree
Hide file tree
Showing 18 changed files with 229 additions and 27 deletions.
4 changes: 4 additions & 0 deletions sdk/communication/communication-email/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 1.0.0-beta.2 (Unreleased)

### Features Added

- Adding support for AAD token authentication

### Breaking Changes

- The EmailRecipients "cC" and "bCC" properties have been changed to "cc" and "bcc"
Expand Down
20 changes: 20 additions & 0 deletions sdk/communication/communication-email/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ const connectionString = `endpoint=https://<resource-name>.communication.azure.c
const client = new EmailClient(connectionString);
```

You can also authenticate with Azure Active Directory using the [Azure Identity library][azure_identity]. To use the [DefaultAzureCredential][defaultazurecredential] provider shown below, or other credential providers provided with the Azure SDK, please install the [`@azure/identity`][azure_identity] package:

```bash
npm install @azure/identity
```

The [`@azure/identity`][azure_identity] package provides a variety of credential types that your application can use to do this. The README for @azure/identity provides more details and samples to get you started.
AZURE_CLIENT_SECRET, AZURE_CLIENT_ID and AZURE_TENANT_ID environment variables are needed to create a DefaultAzureCredential object.

```typescript
import { DefaultAzureCredential } from "@azure/identity";
import { SmsClient } from "@azure/communication-email";

const endpoint = "https://<resource-name>.communication.azure.com";
let credential = new DefaultAzureCredential();
const client = new EmailClient(endpoint, credential);
```

### Send an Email Message

To send an email message, call the `send` function from the `EmailClient`.
Expand Down Expand Up @@ -164,6 +182,8 @@ This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For m
[coc]: https://opensource.microsoft.com/codeofconduct/
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
[coc_contact]: mailto:opencode@microsoft.com
[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential
[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity
[communication_resource_docs]: https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-azp
[email_resource_docs]: https://aka.ms/acsemail/createemailresource
[communication_resource_create_portal]: https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-azp
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.

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.

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 @@ -6,6 +6,7 @@

import { CommonClientOptions } from '@azure/core-client';
import { KeyCredential } from '@azure/core-auth';
import { TokenCredential } from '@azure/core-auth';

// @public
export interface EmailAddress {
Expand All @@ -27,6 +28,7 @@ export type EmailAttachmentType = string;
export class EmailClient {
constructor(connectionString: string, options?: EmailClientOptions);
constructor(endpoint: string, credential: KeyCredential, options?: EmailClientOptions);
constructor(endpoint: string, credential: TokenCredential, options?: EmailClientOptions);
getSendStatus(messageId: string): Promise<SendStatusResult>;
send(emailMessage: EmailMessage): Promise<SendEmailResult>;
}
Expand Down Expand Up @@ -67,7 +69,7 @@ export interface EmailMessage {
export interface EmailRecipients {
bcc?: EmailAddress[];
cc?: EmailAddress[];
to: EmailAddress[];
to?: EmailAddress[];
}

// @public
Expand Down

0 comments on commit f6d4cb8

Please sign in to comment.