Azure Communication Common Java

by microsoft354361d83247MITListed Oct 8, 2026Updated Oct 8, 2026

Azure Communication Services common utilities for Java. Use when working with CommunicationTokenCredential, user identifiers, token refresh, or shared authentication across ACS services.

FeaturedInstructions onlySoftware Development
AI-generated overview

Reference for Azure Communication Services common Java utilities: token credentials, refresh, and user identifiers.

What it does
This skill provides reference documentation for the Azure Communication Services common Java library (com.azure:azure-communication-common). It covers creating CommunicationTokenCredential instances with static tokens or proactive refresh, Entra ID authentication options, and the identifier classes for ACS users, phone numbers, Teams users, and unknown types. It also shows identifier parsing, type checking, token access, disposal, and cloud environment settings, with code samples throughout.
When to use it
Use it when writing or reviewing Java code that authenticates against Azure Communication Services, such as building Chat or Calling clients. It is also relevant when handling ACS user access tokens, token refresh callbacks, or mapping raw identifiers to the correct identifier type.
Requirements
Requires Java and the com.azure:azure-communication-common Maven dependency (version 1.4.0 shown), plus Azure Communication Services credentials such as a resource endpoint and user access token; Entra ID scenarios need an Azure identity client, tenant, and redirect URI. It is instructions only and ships no scripts.

Azure Communication Common (Java)

Shared authentication utilities and data structures for Azure Communication Services.

Installation

xml
<dependency>    <groupId>com.azure</groupId>    <artifactId>azure-communication-common</artifactId>    <version>1.4.0</version></dependency>

Key Concepts

ClassPurpose
CommunicationTokenCredentialAuthenticate users with ACS services
CommunicationTokenRefreshOptionsConfigure automatic token refresh
CommunicationUserIdentifierIdentify ACS users
PhoneNumberIdentifierIdentify PSTN phone numbers
MicrosoftTeamsUserIdentifierIdentify Teams users
UnknownIdentifierGeneric identifier for unknown types

CommunicationTokenCredential

Static Token (Short-lived Clients)

java
import com.azure.communication.common.CommunicationTokenCredential;
// Simple static token - no refreshString userToken = "<user-access-token>";CommunicationTokenCredential credential = new CommunicationTokenCredential(userToken);
// Use with Chat, Calling, etc.ChatClient chatClient = new ChatClientBuilder()    .endpoint("https://<resource>.communication.azure.com")    .credential(credential)    .buildClient();

Proactive Token Refresh (Long-lived Clients)

java
import com.azure.communication.common.CommunicationTokenRefreshOptions;import java.util.concurrent.Callable;
// Token refresher callback - called when token is about to expireCallable<String> tokenRefresher = () -> {    // Call your server to get a fresh token    return fetchNewTokenFromServer();};
// With proactive refreshCommunicationTokenRefreshOptions refreshOptions = new CommunicationTokenRefreshOptions(tokenRefresher)    .setRefreshProactively(true)      // Refresh before expiry    .setInitialToken(currentToken);    // Optional initial token
CommunicationTokenCredential credential = new CommunicationTokenCredential(refreshOptions);

Async Token Refresh

java
import java.util.concurrent.CompletableFuture;
// Async token fetcherCallable<String> asyncRefresher = () -> {    CompletableFuture<String> future = fetchTokenAsync();    return future.get();  // Block until token is available};
CommunicationTokenRefreshOptions options = new CommunicationTokenRefreshOptions(asyncRefresher)    .setRefreshProactively(true);
CommunicationTokenCredential credential = new CommunicationTokenCredential(options);

Entra ID (Azure AD) Authentication

java
import com.azure.identity.InteractiveBrowserCredentialBuilder;import com.azure.communication.common.EntraCommunicationTokenCredentialOptions;import java.util.Arrays;import java.util.List;
// For Teams Phone ExtensibilityInteractiveBrowserCredential entraCredential = new InteractiveBrowserCredentialBuilder()    .clientId("<your-client-id>")    .tenantId("<your-tenant-id>")    .redirectUrl("<your-redirect-uri>")    .build();
String resourceEndpoint = "https://<resource>.communication.azure.com";List<String> scopes = Arrays.asList(    "https://auth.msft.communication.azure.com/TeamsExtension.ManageCalls");
EntraCommunicationTokenCredentialOptions entraOptions =     new EntraCommunicationTokenCredentialOptions(entraCredential, resourceEndpoint)        .setScopes(scopes);
CommunicationTokenCredential credential = new CommunicationTokenCredential(entraOptions);

Communication Identifiers

CommunicationUserIdentifier

java
import com.azure.communication.common.CommunicationUserIdentifier;
// Create identifier for ACS userCommunicationUserIdentifier user = new CommunicationUserIdentifier("8:acs:resource-id_user-id");
// Get raw IDString rawId = user.getId();

PhoneNumberIdentifier

java
import com.azure.communication.common.PhoneNumberIdentifier;
// E.164 format phone numberPhoneNumberIdentifier phone = new PhoneNumberIdentifier("+14255551234");
String phoneNumber = phone.getPhoneNumber();  // "+14255551234"String rawId = phone.getRawId();              // "4:+14255551234"

MicrosoftTeamsUserIdentifier

java
import com.azure.communication.common.MicrosoftTeamsUserIdentifier;
// Teams user identifierMicrosoftTeamsUserIdentifier teamsUser = new MicrosoftTeamsUserIdentifier("<teams-user-id>")    .setCloudEnvironment(CommunicationCloudEnvironment.PUBLIC);
// For anonymous Teams usersMicrosoftTeamsUserIdentifier anonymousTeamsUser = new MicrosoftTeamsUserIdentifier("<teams-user-id>")    .setAnonymous(true);

UnknownIdentifier

java
import com.azure.communication.common.UnknownIdentifier;
// For identifiers of unknown typeUnknownIdentifier unknown = new UnknownIdentifier("some-raw-id");

Identifier Parsing

java
import com.azure.communication.common.CommunicationIdentifier;import com.azure.communication.common.CommunicationIdentifierModel;
// Parse raw ID to appropriate typepublic CommunicationIdentifier parseIdentifier(String rawId) {    if (rawId.startsWith("8:acs:")) {        return new CommunicationUserIdentifier(rawId);    } else if (rawId.startsWith("4:")) {        String phone = rawId.substring(2);        return new PhoneNumberIdentifier(phone);    } else if (rawId.startsWith("8:orgid:")) {        String teamsId = rawId.substring(8);        return new MicrosoftTeamsUserIdentifier(teamsId);    } else {        return new UnknownIdentifier(rawId);    }}

Type Checking Identifiers

java
import com.azure.communication.common.CommunicationIdentifier;
public void processIdentifier(CommunicationIdentifier identifier) {    if (identifier instanceof CommunicationUserIdentifier) {        CommunicationUserIdentifier user = (CommunicationUserIdentifier) identifier;        System.out.println("ACS User: " + user.getId());            } else if (identifier instanceof PhoneNumberIdentifier) {        PhoneNumberIdentifier phone = (PhoneNumberIdentifier) identifier;        System.out.println("Phone: " + phone.getPhoneNumber());            } else if (identifier instanceof MicrosoftTeamsUserIdentifier) {        MicrosoftTeamsUserIdentifier teams = (MicrosoftTeamsUserIdentifier) identifier;        System.out.println("Teams User: " + teams.getUserId());        System.out.println("Anonymous: " + teams.isAnonymous());            } else if (identifier instanceof UnknownIdentifier) {        UnknownIdentifier unknown = (UnknownIdentifier) identifier;        System.out.println("Unknown: " + unknown.getId());    }}

Token Access

java
import com.azure.core.credential.AccessToken;
// Get current token (for debugging/logging - don't expose!)CommunicationTokenCredential credential = new CommunicationTokenCredential(token);
// Sync accessAccessToken accessToken = credential.getToken();System.out.println("Token expires: " + accessToken.getExpiresAt());
// Async accesscredential.getTokenAsync()    .subscribe(token -> {        System.out.println("Token: " + token.getToken().substring(0, 20) + "...");        System.out.println("Expires: " + token.getExpiresAt());    });

Dispose Credential

java
// Clean up when donecredential.close();
// Or use try-with-resourcestry (CommunicationTokenCredential cred = new CommunicationTokenCredential(options)) {    // Use credential    chatClient.doSomething();}

Cloud Environments

java
import com.azure.communication.common.CommunicationCloudEnvironment;
// Available environmentsCommunicationCloudEnvironment publicCloud = CommunicationCloudEnvironment.PUBLIC;CommunicationCloudEnvironment govCloud = CommunicationCloudEnvironment.GCCH;CommunicationCloudEnvironment dodCloud = CommunicationCloudEnvironment.DOD;
// Set on Teams identifierMicrosoftTeamsUserIdentifier teamsUser = new MicrosoftTeamsUserIdentifier("<user-id>")    .setCloudEnvironment(CommunicationCloudEnvironment.GCCH);

Environment Variables

bash
AZURE_COMMUNICATION_ENDPOINT=https://<resource>.communication.azure.comAZURE_COMMUNICATION_USER_TOKEN=<user-access-token>

Best Practices

  1. Proactive Refresh - Always use setRefreshProactively(true) for long-lived clients
  2. Token Security - Never log or expose full tokens
  3. Close Credentials - Dispose of credentials when no longer needed
  4. Error Handling - Handle token refresh failures gracefully
  5. Identifier Types - Use specific identifier types, not raw strings

Common Usage Patterns

java
// Pattern: Create credential for Chat/Calling clientpublic ChatClient createChatClient(String token, String endpoint) {    CommunicationTokenRefreshOptions refreshOptions =         new CommunicationTokenRefreshOptions(this::refreshToken)            .setRefreshProactively(true)            .setInitialToken(token);        CommunicationTokenCredential credential =         new CommunicationTokenCredential(refreshOptions);        return new ChatClientBuilder()        .endpoint(endpoint)        .credential(credential)        .buildClient();}
private String refreshToken() {    // Call your token endpoint    return tokenService.getNewToken();}

Trigger Phrases

  • "ACS authentication", "communication token credential"
  • "user access token", "token refresh"
  • "CommunicationUserIdentifier", "PhoneNumberIdentifier"
  • "Azure Communication Services authentication"

Source and attribution

Source:microsoft/skillsin.github/plugins/azure-sdk-java/skills/azure-communication-common-javaat commit354361d

License: MIT

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal

More from microsoft/skills

Azure Mgmt Fabric Dotnet

microsoft

Featured

Guides .NET management-plane provisioning and lifecycle of Microsoft Fabric capacities via Azure Resource Manager.

DevOps & CloudOct 8, 2026

Azure Mgmt Botservice Dotnet

microsoft

Featured

Azure Resource Manager SDK for Bot Service in .NET. Management plane operations for creating and managing Azure Bot resources, channels (Teams, DirectLine, Slack), and connection settings. Triggers: "Bot Service", "BotResource", "Azure Bot", "DirectLine channel", "Teams channel", "bot management .NET", "create bot".

Awaiting classificationOct 8, 2026

Azure Communication Chat Java

microsoft

Featured

Guides Java developers in building real-time chat features with the Azure Communication Services Chat SDK.

Software DevelopmentOct 8, 2026

Azure Mgmt Arizeaiobservabilityeval Dotnet

microsoft

Featured

Azure Resource Manager SDK for Arize AI Observability and Evaluation (.NET). Use when managing Arize AI organizations on Azure via Azure Marketplace, creating/updating/deleting Arize resources, or integrating Arize ML observability into .NET applications. Triggers: "Arize AI", "ML observability", "ArizeAIObservabilityEval", "Arize organization".

Awaiting classificationOct 8, 2026

Azure Mgmt Applicationinsights Dotnet

microsoft

Featured

Azure Application Insights SDK for .NET. Application performance monitoring and observability resource management. Use for creating Application Insights components, web tests, workbooks, analytics items, and API keys. Triggers: "Application Insights", "ApplicationInsights", "App Insights", "APM", "application monitoring", "web tests", "availability tests", "workbooks".

Awaiting classificationOct 8, 2026

Azure Mgmt Apimanagement Dotnet

microsoft

Featured

Guides .NET management-plane provisioning of Azure API Management services, APIs, products, subscriptions and policies via Azure Resource Manager.

DevOps & CloudOct 8, 2026