Azure Communication Services common utilities for Java. Use when working with CommunicationTokenCredential, user identifiers, token refresh, or shared authentication across ACS services.
Add this skill
npx mdskills install sickn33/azure-communication-common-javaComprehensive Java authentication reference with excellent examples and edge case coverage
Shared authentication utilities and data structures for Azure Communication Services.
com.azure
azure-communication-common
1.4.0
| Class | Purpose |
|---|---|
CommunicationTokenCredential | Authenticate users with ACS services |
CommunicationTokenRefreshOptions | Configure automatic token refresh |
CommunicationUserIdentifier | Identify ACS users |
PhoneNumberIdentifier | Identify PSTN phone numbers |
MicrosoftTeamsUserIdentifier | Identify Teams users |
UnknownIdentifier | Generic identifier for unknown types |
import com.azure.communication.common.CommunicationTokenCredential;
// Simple static token - no refresh
String userToken = "";
CommunicationTokenCredential credential = new CommunicationTokenCredential(userToken);
// Use with Chat, Calling, etc.
ChatClient chatClient = new ChatClientBuilder()
.endpoint("https://.communication.azure.com")
.credential(credential)
.buildClient();
import com.azure.communication.common.CommunicationTokenRefreshOptions;
import java.util.concurrent.Callable;
// Token refresher callback - called when token is about to expire
Callable tokenRefresher = () -> {
// Call your server to get a fresh token
return fetchNewTokenFromServer();
};
// With proactive refresh
CommunicationTokenRefreshOptions refreshOptions = new CommunicationTokenRefreshOptions(tokenRefresher)
.setRefreshProactively(true) // Refresh before expiry
.setInitialToken(currentToken); // Optional initial token
CommunicationTokenCredential credential = new CommunicationTokenCredential(refreshOptions);
import java.util.concurrent.CompletableFuture;
// Async token fetcher
Callable asyncRefresher = () -> {
CompletableFuture future = fetchTokenAsync();
return future.get(); // Block until token is available
};
CommunicationTokenRefreshOptions options = new CommunicationTokenRefreshOptions(asyncRefresher)
.setRefreshProactively(true);
CommunicationTokenCredential credential = new CommunicationTokenCredential(options);
import com.azure.identity.InteractiveBrowserCredentialBuilder;
import com.azure.communication.common.EntraCommunicationTokenCredentialOptions;
import java.util.Arrays;
import java.util.List;
// For Teams Phone Extensibility
InteractiveBrowserCredential entraCredential = new InteractiveBrowserCredentialBuilder()
.clientId("")
.tenantId("")
.redirectUrl("")
.build();
String resourceEndpoint = "https://.communication.azure.com";
List scopes = Arrays.asList(
"https://auth.msft.communication.azure.com/TeamsExtension.ManageCalls"
);
EntraCommunicationTokenCredentialOptions entraOptions =
new EntraCommunicationTokenCredentialOptions(entraCredential, resourceEndpoint)
.setScopes(scopes);
CommunicationTokenCredential credential = new CommunicationTokenCredential(entraOptions);
import com.azure.communication.common.CommunicationUserIdentifier;
// Create identifier for ACS user
CommunicationUserIdentifier user = new CommunicationUserIdentifier("8:acs:resource-id_user-id");
// Get raw ID
String rawId = user.getId();
import com.azure.communication.common.PhoneNumberIdentifier;
// E.164 format phone number
PhoneNumberIdentifier phone = new PhoneNumberIdentifier("+14255551234");
String phoneNumber = phone.getPhoneNumber(); // "+14255551234"
String rawId = phone.getRawId(); // "4:+14255551234"
import com.azure.communication.common.MicrosoftTeamsUserIdentifier;
// Teams user identifier
MicrosoftTeamsUserIdentifier teamsUser = new MicrosoftTeamsUserIdentifier("")
.setCloudEnvironment(CommunicationCloudEnvironment.PUBLIC);
// For anonymous Teams users
MicrosoftTeamsUserIdentifier anonymousTeamsUser = new MicrosoftTeamsUserIdentifier("")
.setAnonymous(true);
import com.azure.communication.common.UnknownIdentifier;
// For identifiers of unknown type
UnknownIdentifier unknown = new UnknownIdentifier("some-raw-id");
import com.azure.communication.common.CommunicationIdentifier;
import com.azure.communication.common.CommunicationIdentifierModel;
// Parse raw ID to appropriate type
public 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);
}
}
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());
}
}
import com.azure.core.credential.AccessToken;
// Get current token (for debugging/logging - don't expose!)
CommunicationTokenCredential credential = new CommunicationTokenCredential(token);
// Sync access
AccessToken accessToken = credential.getToken();
System.out.println("Token expires: " + accessToken.getExpiresAt());
// Async access
credential.getTokenAsync()
.subscribe(token -> {
System.out.println("Token: " + token.getToken().substring(0, 20) + "...");
System.out.println("Expires: " + token.getExpiresAt());
});
// Clean up when done
credential.close();
// Or use try-with-resources
try (CommunicationTokenCredential cred = new CommunicationTokenCredential(options)) {
// Use credential
chatClient.doSomething();
}
import com.azure.communication.common.CommunicationCloudEnvironment;
// Available environments
CommunicationCloudEnvironment publicCloud = CommunicationCloudEnvironment.PUBLIC;
CommunicationCloudEnvironment govCloud = CommunicationCloudEnvironment.GCCH;
CommunicationCloudEnvironment dodCloud = CommunicationCloudEnvironment.DOD;
// Set on Teams identifier
MicrosoftTeamsUserIdentifier teamsUser = new MicrosoftTeamsUserIdentifier("")
.setCloudEnvironment(CommunicationCloudEnvironment.GCCH);
AZURE_COMMUNICATION_ENDPOINT=https://.communication.azure.com
AZURE_COMMUNICATION_USER_TOKEN=
setRefreshProactively(true) for long-lived clients// Pattern: Create credential for Chat/Calling client
public 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();
}
Install via CLI
npx mdskills install sickn33/azure-communication-common-javaAzure Communication Common Java is a free, open-source AI agent skill. Azure Communication Services common utilities for Java. Use when working with CommunicationTokenCredential, user identifiers, token refresh, or shared authentication across ACS services.
Install Azure Communication Common Java with a single command:
npx mdskills install sickn33/azure-communication-common-javaThis downloads the skill files into your project and your AI agent picks them up automatically.
Azure Communication Common Java works with Claude Code, Claude Desktop, Cursor, Vscode Copilot, Windsurf, Continue Dev, Codex, Gemini Cli, Amp, Roo Code, Goose, Opencode, Trae, Qodo, Command Code. Skills use the open SKILL.md format which is compatible with any AI coding agent that reads markdown instructions.