TypeScript icon, indicating that this package has built-in type declarations

    1.0.0 • Public • Published

    Azure Communication Identity client library for JavaScript

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

    Getting started



    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.

    Key concepts


    The CommunicationIdentityClient provides methods to manage users and their tokens.



    You can get a key and/or connection string from your Communication Services resource in 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

    import { AzureKeyCredential } from "@azure/core-auth";
    import { CommunicationIdentityClient } from "@azure/communication-identity";
    const credential = new AzureKeyCredential(KEY);
    const client = new CommunicationIdentityClient(ENDPOINT, credential);

    Using a connection string

    import { CommunicationIdentityClient } from "@azure/communication-identity";
    const connectionString = `endpoint=ENDPOINT;accessKey=KEY`;
    const client = new CommunicationIdentityClient(connectionString);

    Using a TokenCredential

    import { DefaultAzureCredential } from "@azure/identity";
    import { CommunicationIdentityClient } from "@azure/communication-identity";
    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.


    Creating an instance of CommunicationIdentityClient

    import { CommunicationIdentityClient } from "@azure/communication-identity";
    const client = new CommunicationIdentityClient(CONNECTION_STRING);

    Creating a new user

    Use the createUser method to create a new user.

    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 (Chat)
    • voip (Voice over IP)
    let { token } = await client.getToken(user, ["chat"]);

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

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

    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.

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

    Revoking tokens for a user

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

    await client.revokeTokens(user);

    Deleting a user

    Use the deleteUser method to delete a user.

    await client.deleteUser(user);


    Next steps

    Please take a look at the samples directory for detailed examples on how to use this library.


    If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.

    Related projects



    npm i @azure/communication-identity

    DownloadsWeekly Downloads






    Unpacked Size

    134 kB

    Total Files


    Last publish


    • azure-sdk