Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Communication]- Common -Adding Samples. #17937

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions sdk/communication/azure-communication-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<name>Microsoft Azure common library for communication service client</name>
<description>
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.
</description>
<url>https://github.com/Azure/azure-sdk-for-java</url>
Expand Down Expand Up @@ -46,12 +46,17 @@
<artifactId>azure-core</artifactId>
<version>1.11.0</version> <!-- {x-version-update;com.azure:azure-core;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-communication-administration</artifactId>
<version>1.0.0-beta.4</version> <!-- {x-version-update;com.azure:azure-communication-administration;current} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-netty</artifactId>
<version>1.7.0</version> <!-- {x-version-update;com.azure:azure-core-http-netty;dependency} -->
<scope>compile</scope>
</dependency>
</dependency>
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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://<RESOURCE_NAME>.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<String> 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;

}


}