diff --git a/sdk/communication/azure-communication-common/pom.xml b/sdk/communication/azure-communication-common/pom.xml index ac05c45d0be69..ce2ea9ebfbf04 100644 --- a/sdk/communication/azure-communication-common/pom.xml +++ b/sdk/communication/azure-communication-common/pom.xml @@ -17,7 +17,7 @@ Microsoft Azure common library for communication service client - This package contains data structures commonly used for communicating with Microsoft Azure Communication Services. + This package contains data structures commonly used for communicating with Microsoft Azure Communication Services. For this release, see notes - https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/communication/azure-communication-common/README.md and https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/communication/azure-communication-common/CHANGELOG.md. https://github.com/Azure/azure-sdk-for-java @@ -46,12 +46,17 @@ azure-core 1.11.0 + + com.azure + azure-communication-administration + 1.0.0-beta.4 + com.azure azure-core-http-netty 1.7.0 compile - + com.nimbusds nimbus-jose-jwt diff --git a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CallingApplication.java b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CallingApplication.java index 8eadfb2a2803c..3d001a50d01f6 100644 --- a/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CallingApplication.java +++ b/sdk/communication/azure-communication-common/src/main/java/com/azure/communication/common/CallingApplication.java @@ -11,9 +11,9 @@ public class CallingApplication extends CommunicationIdentifier { private final String id; - /** + /**mvn * Creates a CallingApplication object - * + * * @param id the string identifier representing the identity * @throws IllegalArgumentException thrown if id parameter fail the validation. */ diff --git a/sdk/communication/azure-communication-common/src/samples/java/SampleAutentication.java b/sdk/communication/azure-communication-common/src/samples/java/SampleAutentication.java new file mode 100644 index 0000000000000..d0da64984323c --- /dev/null +++ b/sdk/communication/azure-communication-common/src/samples/java/SampleAutentication.java @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import com.azure.communication.administration.CommunicationIdentityClient; +import com.azure.communication.administration.CommunicationIdentityClientBuilder; +import com.azure.communication.administration.CommunicationUserToken; +import com.azure.communication.common.CommunicationUser; +import com.azure.core.http.HttpClient; +import com.azure.core.http.netty.NettyAsyncHttpClientBuilder; + + +public class SampleAutentication { + + /** + * Sample code for creating a sync Communication Identity Client. + * + * @return the Communication Identity Client. + */ + public CommunicationIdentityClient createCommunicationIdentityClient() { + // You can find your endpoint and access key from your resource in the Azure Portal + String endpoint = "https://.communication.azure.com"; + String accessKey = "SECRET"; + + // Create an HttpClient builder of your choice and customize it + HttpClient httpClient = new NettyAsyncHttpClientBuilder().build(); + + CommunicationIdentityClient communicationIdentityClient = new CommunicationIdentityClientBuilder() + .endpoint(endpoint) + .accessKey(accessKey) + .httpClient(httpClient) + .buildClient(); + + return communicationIdentityClient; + } + + public CommunicationUserToken createComunicationUserToken() { + CommunicationIdentityClient communicationIdentityClient = createCommunicationIdentityClient(); + CommunicationUser user = communicationIdentityClient.createUser(); + List scopes = new ArrayList<>(Arrays.asList("chat")); + CommunicationUserToken userToken = communicationIdentityClient.issueToken(user, scopes); + System.out.println("Token: " + userToken.getToken()); + System.out.println("Expires On: " + userToken.getExpiresOn()); + return userToken; + + } + + +}