[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-100b7820-e48d-42de-b904-b7d95c692307":3,"$fbs9_wKI_znYaP1t9jrnn7nOyh7bjoh8pQvcsapVWN5I":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"100b7820-e48d-42de-b904-b7d95c692307","azure-communication-common-java","Azure通信服务Java通用工具。用于处理CommunicationTokenCredential、用户标识符、令牌刷新或ACS服务间的共享身份验证。","cat_coding_devops","mod_coding","sickn33,coding","---\nname: azure-communication-common-java\ndescription: \"Azure Communication Services common utilities for Java. Use when working with CommunicationTokenCredential, user identifiers, token refresh, or shared authentication across ACS services.\"\nrisk: unknown\nsource: community\ndate_added: \"2026-02-27\"\n---\n\n# Azure Communication Common (Java)\n\nShared authentication utilities and data structures for Azure Communication Services.\n\n## Installation\n\n```xml\n\u003Cdependency>\n    \u003CgroupId>com.azure\u003C\u002FgroupId>\n    \u003CartifactId>azure-communication-common\u003C\u002FartifactId>\n    \u003Cversion>1.4.0\u003C\u002Fversion>\n\u003C\u002Fdependency>\n```\n\n## Key Concepts\n\n| Class | Purpose |\n|-------|---------|\n| `CommunicationTokenCredential` | Authenticate users with ACS services |\n| `CommunicationTokenRefreshOptions` | Configure automatic token refresh |\n| `CommunicationUserIdentifier` | Identify ACS users |\n| `PhoneNumberIdentifier` | Identify PSTN phone numbers |\n| `MicrosoftTeamsUserIdentifier` | Identify Teams users |\n| `UnknownIdentifier` | Generic identifier for unknown types |\n\n## CommunicationTokenCredential\n\n### Static Token (Short-lived Clients)\n\n```java\nimport com.azure.communication.common.CommunicationTokenCredential;\n\n\u002F\u002F Simple static token - no refresh\nString userToken = \"\u003Cuser-access-token>\";\nCommunicationTokenCredential credential = new CommunicationTokenCredential(userToken);\n\n\u002F\u002F Use with Chat, Calling, etc.\nChatClient chatClient = new ChatClientBuilder()\n    .endpoint(\"https:\u002F\u002F\u003Cresource>.communication.azure.com\")\n    .credential(credential)\n    .buildClient();\n```\n\n### Proactive Token Refresh (Long-lived Clients)\n\n```java\nimport com.azure.communication.common.CommunicationTokenRefreshOptions;\nimport java.util.concurrent.Callable;\n\n\u002F\u002F Token refresher callback - called when token is about to expire\nCallable\u003CString> tokenRefresher = () -> {\n    \u002F\u002F Call your server to get a fresh token\n    return fetchNewTokenFromServer();\n};\n\n\u002F\u002F With proactive refresh\nCommunicationTokenRefreshOptions refreshOptions = new CommunicationTokenRefreshOptions(tokenRefresher)\n    .setRefreshProactively(true)      \u002F\u002F Refresh before expiry\n    .setInitialToken(currentToken);    \u002F\u002F Optional initial token\n\nCommunicationTokenCredential credential = new CommunicationTokenCredential(refreshOptions);\n```\n\n### Async Token Refresh\n\n```java\nimport java.util.concurrent.CompletableFuture;\n\n\u002F\u002F Async token fetcher\nCallable\u003CString> asyncRefresher = () -> {\n    CompletableFuture\u003CString> future = fetchTokenAsync();\n    return future.get();  \u002F\u002F Block until token is available\n};\n\nCommunicationTokenRefreshOptions options = new CommunicationTokenRefreshOptions(asyncRefresher)\n    .setRefreshProactively(true);\n\nCommunicationTokenCredential credential = new CommunicationTokenCredential(options);\n```\n\n## Entra ID (Azure AD) Authentication\n\n```java\nimport com.azure.identity.InteractiveBrowserCredentialBuilder;\nimport com.azure.communication.common.EntraCommunicationTokenCredentialOptions;\nimport java.util.Arrays;\nimport java.util.List;\n\n\u002F\u002F For Teams Phone Extensibility\nInteractiveBrowserCredential entraCredential = new InteractiveBrowserCredentialBuilder()\n    .clientId(\"\u003Cyour-client-id>\")\n    .tenantId(\"\u003Cyour-tenant-id>\")\n    .redirectUrl(\"\u003Cyour-redirect-uri>\")\n    .build();\n\nString resourceEndpoint = \"https:\u002F\u002F\u003Cresource>.communication.azure.com\";\nList\u003CString> scopes = Arrays.asList(\n    \"https:\u002F\u002Fauth.msft.communication.azure.com\u002FTeamsExtension.ManageCalls\"\n);\n\nEntraCommunicationTokenCredentialOptions entraOptions = \n    new EntraCommunicationTokenCredentialOptions(entraCredential, resourceEndpoint)\n        .setScopes(scopes);\n\nCommunicationTokenCredential credential = new CommunicationTokenCredential(entraOptions);\n```\n\n## Communication Identifiers\n\n### CommunicationUserIdentifier\n\n```java\nimport com.azure.communication.common.CommunicationUserIdentifier;\n\n\u002F\u002F Create identifier for ACS user\nCommunicationUserIdentifier user = new CommunicationUserIdentifier(\"8:acs:resource-id_user-id\");\n\n\u002F\u002F Get raw ID\nString rawId = user.getId();\n```\n\n### PhoneNumberIdentifier\n\n```java\nimport com.azure.communication.common.PhoneNumberIdentifier;\n\n\u002F\u002F E.164 format phone number\nPhoneNumberIdentifier phone = new PhoneNumberIdentifier(\"+14255551234\");\n\nString phoneNumber = phone.getPhoneNumber();  \u002F\u002F \"+14255551234\"\nString rawId = phone.getRawId();              \u002F\u002F \"4:+14255551234\"\n```\n\n### MicrosoftTeamsUserIdentifier\n\n```java\nimport com.azure.communication.common.MicrosoftTeamsUserIdentifier;\n\n\u002F\u002F Teams user identifier\nMicrosoftTeamsUserIdentifier teamsUser = new MicrosoftTeamsUserIdentifier(\"\u003Cteams-user-id>\")\n    .setCloudEnvironment(CommunicationCloudEnvironment.PUBLIC);\n\n\u002F\u002F For anonymous Teams users\nMicrosoftTeamsUserIdentifier anonymousTeamsUser = new MicrosoftTeamsUserIdentifier(\"\u003Cteams-user-id>\")\n    .setAnonymous(true);\n```\n\n### UnknownIdentifier\n\n```java\nimport com.azure.communication.common.UnknownIdentifier;\n\n\u002F\u002F For identifiers of unknown type\nUnknownIdentifier unknown = new UnknownIdentifier(\"some-raw-id\");\n```\n\n## Identifier Parsing\n\n```java\nimport com.azure.communication.common.CommunicationIdentifier;\nimport com.azure.communication.common.CommunicationIdentifierModel;\n\n\u002F\u002F Parse raw ID to appropriate type\npublic CommunicationIdentifier parseIdentifier(String rawId) {\n    if (rawId.startsWith(\"8:acs:\")) {\n        return new CommunicationUserIdentifier(rawId);\n    } else if (rawId.startsWith(\"4:\")) {\n        String phone = rawId.substring(2);\n        return new PhoneNumberIdentifier(phone);\n    } else if (rawId.startsWith(\"8:orgid:\")) {\n        String teamsId = rawId.substring(8);\n        return new MicrosoftTeamsUserIdentifier(teamsId);\n    } else {\n        return new UnknownIdentifier(rawId);\n    }\n}\n```\n\n## Type Checking Identifiers\n\n```java\nimport com.azure.communication.common.CommunicationIdentifier;\n\npublic void processIdentifier(CommunicationIdentifier identifier) {\n    if (identifier instanceof CommunicationUserIdentifier) {\n        CommunicationUserIdentifier user = (CommunicationUserIdentifier) identifier;\n        System.out.println(\"ACS User: \" + user.getId());\n        \n    } else if (identifier instanceof PhoneNumberIdentifier) {\n        PhoneNumberIdentifier phone = (PhoneNumberIdentifier) identifier;\n        System.out.println(\"Phone: \" + phone.getPhoneNumber());\n        \n    } else if (identifier instanceof MicrosoftTeamsUserIdentifier) {\n        MicrosoftTeamsUserIdentifier teams = (MicrosoftTeamsUserIdentifier) identifier;\n        System.out.println(\"Teams User: \" + teams.getUserId());\n        System.out.println(\"Anonymous: \" + teams.isAnonymous());\n        \n    } else if (identifier instanceof UnknownIdentifier) {\n        UnknownIdentifier unknown = (UnknownIdentifier) identifier;\n        System.out.println(\"Unknown: \" + unknown.getId());\n    }\n}\n```\n\n## Token Access\n\n```java\nimport com.azure.core.credential.AccessToken;\n\n\u002F\u002F Get current token (for debugging\u002Flogging - don't expose!)\nCommunicationTokenCredential credential = new CommunicationTokenCredential(token);\n\n\u002F\u002F Sync access\nAccessToken accessToken = credential.getToken();\nSystem.out.println(\"Token expires: \" + accessToken.getExpiresAt());\n\n\u002F\u002F Async access\ncredential.getTokenAsync()\n    .subscribe(token -> {\n        System.out.println(\"Token: \" + token.getToken().substring(0, 20) + \"...\");\n        System.out.println(\"Expires: \" + token.getExpiresAt());\n    });\n```\n\n## Dispose Credential\n\n```java\n\u002F\u002F Clean up when done\ncredential.close();\n\n\u002F\u002F Or use try-with-resources\ntry (CommunicationTokenCredential cred = new CommunicationTokenCredential(options)) {\n    \u002F\u002F Use credential\n    chatClient.doSomething();\n}\n```\n\n## Cloud Environments\n\n```java\nimport com.azure.communication.common.CommunicationCloudEnvironment;\n\n\u002F\u002F Available environments\nCommunicationCloudEnvironment publicCloud = CommunicationCloudEnvironment.PUBLIC;\nCommunicationCloudEnvironment govCloud = CommunicationCloudEnvironment.GCCH;\nCommunicationCloudEnvironment dodCloud = CommunicationCloudEnvironment.DOD;\n\n\u002F\u002F Set on Teams identifier\nMicrosoftTeamsUserIdentifier teamsUser = new MicrosoftTeamsUserIdentifier(\"\u003Cuser-id>\")\n    .setCloudEnvironment(CommunicationCloudEnvironment.GCCH);\n```\n\n## Environment Variables\n\n```bash\nAZURE_COMMUNICATION_ENDPOINT=https:\u002F\u002F\u003Cresource>.communication.azure.com\nAZURE_COMMUNICATION_USER_TOKEN=\u003Cuser-access-token>\n```\n\n## Best Practices\n\n1. **Proactive Refresh** - Always use `setRefreshProactively(true)` for long-lived clients\n2. **Token Security** - Never log or expose full tokens\n3. **Close Credentials** - Dispose of credentials when no longer needed\n4. **Error Handling** - Handle token refresh failures gracefully\n5. **Identifier Types** - Use specific identifier types, not raw strings\n\n## Common Usage Patterns\n\n```java\n\u002F\u002F Pattern: Create credential for Chat\u002FCalling client\npublic ChatClient createChatClient(String token, String endpoint) {\n    CommunicationTokenRefreshOptions refreshOptions = \n        new CommunicationTokenRefreshOptions(this::refreshToken)\n            .setRefreshProactively(true)\n            .setInitialToken(token);\n    \n    CommunicationTokenCredential credential = \n        new CommunicationTokenCredential(refreshOptions);\n    \n    return new ChatClientBuilder()\n        .endpoint(endpoint)\n        .credential(credential)\n        .buildClient();\n}\n\nprivate String refreshToken() {\n    \u002F\u002F Call your token endpoint\n    return tokenService.getNewToken();\n}\n```\n\n## Trigger Phrases\n\n- \"ACS authentication\", \"communication token credential\"\n- \"user access token\", \"token refresh\"\n- \"CommunicationUserIdentifier\", \"PhoneNumberIdentifier\"\n- \"Azure Communication Services authentication\"\n\n## When to Use\nThis skill is applicable to execute the workflow or actions described in the overview.\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,114,346,"2026-05-16 13:05:58",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"编程开发","coding","mdi-code-braces","代码生成、调试、审查，提升开发效率",2,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"DevOps","devops","mdi-cog-outline","CI\u002FCD、容器化、部署运维",3,162,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"313d3c21-a24f-46e5-8682-692b32d09bb9","1.0.0","azure-communication-common-java.zip",2955,"uploads\u002Fskills\u002F100b7820-e48d-42de-b904-b7d95c692307\u002Fazure-communication-common-java.zip","6cf2ae5e3c52250cd316ade71bd3b4d07277dc01f1c363f9a1641e5131aec9c7","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":10051}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]