# @azure/communication-identity

> SDK for Azure Communication service which facilitates user token administration.

Latest version **2.0.0** (published 2026-10-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install @azure/communication-identity
pnpm add @azure/communication-identity
yarn add @azure/communication-identity
bun add @azure/communication-identity
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2026-10-02 |
| First published | 2021-01-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22.0.0 |
| Dependencies | 8 |
| Unpacked size | 749.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2301 |
| Author | Microsoft Corporation |
| Maintainers | azure-sdk, microsoft1es, microsoft-oss-releases |
| Keywords | azure, cloud, communication |

## Links

- npm: https://www.npmjs.com/package/@azure/communication-identity
- Repository: https://github.com/Azure/azure-sdk-for-js
- Homepage: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-identity/README.md
- Issues: https://github.com/Azure/azure-sdk-for-js/issues
- npm.io page: https://npm.io/package/@azure/communication-identity

## Dependencies (8)

- [tslib](https://npm.io/package/tslib.md) ^2.8.1
- [@azure/logger](https://npm.io/package/@azure/logger.md) ^1.1.4
- [@azure/core-auth](https://npm.io/package/@azure/core-auth.md) ^1.9.0
- [@azure/core-client](https://npm.io/package/@azure/core-client.md) ^1.11.1
- [@azure/core-tracing](https://npm.io/package/@azure/core-tracing.md) ^1.2.0
- [@azure-rest/core-client](https://npm.io/package/@azure-rest/core-client.md) ^2.6.1
- [@azure/core-rest-pipeline](https://npm.io/package/@azure/core-rest-pipeline.md) ^1.18.2
- [@azure/communication-common](https://npm.io/package/@azure/communication-common.md) ^2.3.1

## Recent versions

- 2.0.0 (latest) — 2026-10-02
- 1.4.0-alpha.20260211.1 (dev) — 2026-02-11
- 1.4.0-beta.1 (next) — 2025-06-20
- 1.4.0-alpha.20260210.1 — 2026-02-10
- 1.4.0-alpha.20260209.1 — 2026-02-09
- 1.4.0-alpha.20260206.1 — 2026-02-06
- 1.4.0-alpha.20260205.1 — 2026-02-05
- 1.4.0-alpha.20260204.1 — 2026-02-04
- 1.4.0-alpha.20260203.1 — 2026-02-03
- 1.4.0-alpha.20260130.1 — 2026-01-30
- 1.4.0-alpha.20260129.1 — 2026-01-29
- 1.4.0-alpha.20260128.1 — 2026-01-28
- 1.4.0-alpha.20260127.1 — 2026-01-27
- 1.4.0-alpha.20260126.1 — 2026-01-26
- 1.4.0-alpha.20260123.1 — 2026-01-23
- … 427 more at https://npm.io/package/@azure/communication-identity/versions

## README

# Azure Communication Identity client library for JavaScript

The identity library is used for managing users and tokens for Azure Communication Services.

## Getting started

### Prerequisites

- An [Azure subscription][azure_sub].
- An existing Communication Services resource. If you need to create the resource, you can use the [Azure Portal][azure_portal], the [Azure PowerShell][azure_powershell], or the [Azure CLI][azure_cli].

### Installing

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

### Browser support

#### JavaScript Bundle

To use this client library in the browser, first you need to use a bundler. For details on how to do this, please refer to our [bundling documentation](https://aka.ms/AzureSDKBundling).

## Key concepts

### Clients

The `CommunicationIdentityClient` provides methods to manage users and their tokens.

## Examples

## Authentication

You can get a key and/or connection string from your Communication Services resource in [Azure Portal][azure_portal]. Once you have a key, you can authenticate the `CommunicationIdentityClient` with any of the following methods:

### Create `KeyCredential` with `AzureKeyCredential` before initializing the client

```ts snippet:ReadmeSampleCreateClient_KeyCredential
import { AzureKeyCredential } from "@azure/core-auth";
import { CommunicationIdentityClient } from "@azure/communication-identity";

const key = "<some-key>";
const endpoint = "https://contoso.eastus.communications.azure.net";

const credential = new AzureKeyCredential(key);
const client = new CommunicationIdentityClient(endpoint, credential);
```

### Using a connection string

```ts snippet:ReadmeSampleCreateClient_ConnectionString
import { CommunicationIdentityClient } from "@azure/communication-identity";

// Example connection string
const connectionString =
  "endpoint=https://contoso.eastus.communications.azure.net/;accesskey=secret";

const client = new CommunicationIdentityClient(connectionString);
```

### Using a `TokenCredential`

```ts snippet:ReadmeSampleCreateClient_TokenCredential
import { DefaultAzureCredential } from "@azure/identity";
import { CommunicationIdentityClient } from "@azure/communication-identity";

const endpoint = "https://contoso.eastus.communications.azure.net";

const credential = new DefaultAzureCredential();
const client = new CommunicationIdentityClient(endpoint, 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

### Creating a new user

Use the `createUser` method to create a new user.

```ts snippet:ReadmeSampleCreateUser
import { DefaultAzureCredential } from "@azure/identity";
import { CommunicationIdentityClient } from "@azure/communication-identity";

const endpoint = "https://contoso.eastus.communications.azure.net";

const credential = new DefaultAzureCredential();
const client = new CommunicationIdentityClient(endpoint, credential);

const user = await client.createUser();
```

### Creating and refreshing a user token

Use the `getToken` method to issue or refresh a token for an existing user. The method also takes in a list of communication token scopes. Scope options include:

- `chat` (Use this for full access to Chat APIs)
- `voip` (Use this for full access to Calling APIs)
- `chat.join` (Access to Chat APIs but without the authorization to create, delete or update chat threads)
- `chat.join.limited` (A more limited version of chat.join that doesn't allow to add or remove participants)
- `voip.join` (Access to Calling APIs but without the authorization to start new calls)

```ts snippet:ReadmeSampleCreateToken
import { DefaultAzureCredential } from "@azure/identity";
import { CommunicationIdentityClient } from "@azure/communication-identity";

const endpoint = "https://contoso.eastus.communications.azure.net";

const credential = new DefaultAzureCredential();
const client = new CommunicationIdentityClient(endpoint, credential);

const user = await client.createUser();

const { token } = await client.getToken(user, ["chat"]);
```

To refresh the user token, issue another token with the same user.

```ts snippet:ReadmeSampleRefreshToken
import { DefaultAzureCredential } from "@azure/identity";
import { CommunicationIdentityClient } from "@azure/communication-identity";

const endpoint = "https://contoso.eastus.communications.azure.net";

const credential = new DefaultAzureCredential();
const client = new CommunicationIdentityClient(endpoint, credential);

const user = await client.createUser();

let { token } = await client.getToken(user, ["chat"]);

// Refresh the token again
({ token } = await client.getToken(user, ["chat"]));
```

### Creating a user token with custom expiration

It's also possible to create a Communication Identity access token by customizing the expiration time. Validity period of the token must be within [60,1440] minutes range. If not provided, the default value of 1440 minutes (24 hours) will be used.

```ts snippet:ReadmeSampleCreateTokenWithOptions
import { DefaultAzureCredential } from "@azure/identity";
import { CommunicationIdentityClient } from "@azure/communication-identity";

const endpoint = "https://contoso.eastus.communications.azure.net";

const credential = new DefaultAzureCredential();
const client = new CommunicationIdentityClient(endpoint, credential);

const user = await client.createUser();

const tokenOptions = { tokenExpiresInMinutes: 60 };
const { token } = await client.getToken(user, ["chat"], tokenOptions);
```

### Creating a user and a token in a single request

For convenience, use `createUserAndToken` to create a new user and issue a token with one function call. This translates into a single web request as opposed to creating a user first and then issuing a token.

```ts snippet:ReadmeSampleCreateUserAndToken
import { DefaultAzureCredential } from "@azure/identity";
import { CommunicationIdentityClient } from "@azure/communication-identity";

const endpoint = "https://contoso.eastus.communications.azure.net";

const credential = new DefaultAzureCredential();
const client = new CommunicationIdentityClient(endpoint, credential);

const { user, token } = await client.createUserAndToken(["chat"]);
```

### Creating a user and a token with custom expiration in a single request

It's also possible to create a Communication Identity access token by customizing the expiration time. Validity period of the token must be within [60,1440] minutes range. If not provided, the default value of 1440 minutes (24 hours) will be used.

```ts snippet:ReadmeSampleCreateUserAndTokenWithOptions
import { DefaultAzureCredential } from "@azure/identity";
import { CommunicationIdentityClient } from "@azure/communication-identity";

const endpoint = "https://contoso.eastus.communications.azure.net";

const credential = new DefaultAzureCredential();
const client = new CommunicationIdentityClient(endpoint, credential);

const userAndTokenOptions = { tokenExpiresInMinutes: 60 };
const { user, token } = await client.createUserAndToken(["chat"], userAndTokenOptions);
```

### Revoking tokens for a user

Use the `revokeTokens` method to revoke all issued tokens for a user.

```ts snippet:ReadmeSampleRevokeTokens
import { DefaultAzureCredential } from "@azure/identity";
import { CommunicationIdentityClient } from "@azure/communication-identity";

const endpoint = "https://contoso.eastus.communications.azure.net";

const credential = new DefaultAzureCredential();
const client = new CommunicationIdentityClient(endpoint, credential);

// Create user
const user = await client.createUser();

// Later when you want to revoke the user's tokens
await client.revokeTokens(user);
```

### Deleting a user

Use the `deleteUser` method to delete a user.

```ts snippet:ReadmeSampleDeleteUser
import { DefaultAzureCredential } from "@azure/identity";
import { CommunicationIdentityClient } from "@azure/communication-identity";

const endpoint = "https://contoso.eastus.communications.azure.net";

const credential = new DefaultAzureCredential();
const client = new CommunicationIdentityClient(endpoint, credential);

// Create user
const user = await client.createUser();

// Later when you want to delete the user
await client.deleteUser(user);
```

### Exchanging Azure AD access token of a Teams User for a Communication access token

Use `getTokenForTeamsUser` method to exchange an Azure AD access token of a Teams user for a new `CommunicationAccessToken` with a matching expiration time.

```ts snippet:ReadmeSampleGetTokenForTeamsUser
import { DefaultAzureCredential } from "@azure/identity";
import { CommunicationIdentityClient } from "@azure/communication-identity";

const endpoint = "https://contoso.eastus.communications.azure.net";

const credential = new DefaultAzureCredential();
const client = new CommunicationIdentityClient(endpoint, credential);

const { token, expiresOn } = await client.getTokenForTeamsUser({
  teamsUserAadToken: "<aad-access-token-of-a-teams-user>",
  clientId: "<cliend-id-of-an-aad-application>",
  userObjectId: "<aad-object-id-of-a-teams-user>",
});
```

## Troubleshooting

### Logging

Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:

```ts snippet:SetLogLevel
import { setLogLevel } from "@azure/logger";

setLogLevel("info");
```

## Next steps

Please take a look at the
[samples](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/communication/communication-identity/samples)
directory for detailed examples on how to use this library.

## Contributing

If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test the code.

## Related projects

- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)

[azure_cli]: https://learn.microsoft.com/cli/azure
[azure_sub]: https://azure.microsoft.com/free/
[azure_portal]: https://portal.azure.com
[azure_powershell]: https://learn.microsoft.com/powershell/module/az.communication/new-azcommunicationservice

---
_Source: https://npm.io/package/@azure/communication-identity · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
