Skip to content

Commit

Permalink
reverted back to the azure-communication-identity beta changes (Azure…
Browse files Browse the repository at this point in the history
  • Loading branch information
AikoBB authored May 20, 2022
1 parent 32c82ef commit 7965e36
Show file tree
Hide file tree
Showing 84 changed files with 2,550 additions and 1,112 deletions.
2 changes: 1 addition & 1 deletion eng/jacoco-test-coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-communication-identity</artifactId>
<version>1.2.0-beta.1</version> <!-- {x-version-update;com.azure:azure-communication-identity;current} -->
<version>1.2.0-beta.2</version> <!-- {x-version-update;com.azure:azure-communication-identity;current} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
Expand Down
2 changes: 1 addition & 1 deletion eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ com.azure:azure-communication-callingserver;1.0.0-beta.4;1.0.0-beta.5
com.azure:azure-communication-common;1.1.3;1.2.0-beta.1
com.azure:azure-communication-common-perf;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-communication-sms;1.1.2;1.2.0-beta.1
com.azure:azure-communication-identity;1.1.9;1.2.0-beta.1
com.azure:azure-communication-identity;1.1.9;1.2.0-beta.2
com.azure:azure-communication-phonenumbers;1.0.10;1.1.0-beta.6
com.azure:azure-communication-networktraversal;1.1.0-beta.2;1.1.0-beta.3
com.azure:azure-containers-containerregistry;1.0.3;1.1.0-beta.2
Expand Down
13 changes: 10 additions & 3 deletions sdk/communication/azure-communication-identity/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Release History

## 1.2.0-beta.1 (Unreleased)
## 1.2.0-beta.2 (Unreleased)

### Features Added
- Added interfaces from `com.azure.core.client.traits` to `CommunicationIdentityClientBuilder`.
- Added `retryOptions` to `CommunicationIdentityClientBuilder`.

### Breaking Changes

Expand Down Expand Up @@ -60,8 +62,13 @@

#### Dependency Updates

- Upgraded `azure-communication-common` to 1.0.6
- Upgraded `azure-core` to 1.22.0
- Upgraded `azure-core` to `1.22.0`.
- Upgraded `azure-communication-common` to `1.0.6`.

## 1.2.0-beta.1 (2021-10-29)

### Features Added
- Added support for Microsoft 365 Teams identities

## 1.1.3 (2021-10-08)

Expand Down
43 changes: 23 additions & 20 deletions sdk/communication/azure-communication-identity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ add the direct dependency to your project as follows.
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-communication-identity</artifactId>
<version>1.1.1</version>
<version>1.1.4</version>
</dependency>
```

Expand All @@ -69,8 +69,7 @@ A `DefaultAzureCredential` object must be passed to the `CommunicationIdentityCl
`AZURE_CLIENT_SECRET`, `AZURE_CLIENT_ID` and `AZURE_TENANT_ID` environment variables
are needed to create a DefaultAzureCredential object.

<!-- embedme ./src/samples/java/com/azure/communication/identity/ReadmeSamples.java#L55-L61 -->
```java
```java readme-sample-createCommunicationIdentityClientWithAAD
// You can find your endpoint and access key from your resource in the Azure Portal
String endpoint = "https://<RESOURCE_NAME>.communication.azure.com";

Expand All @@ -84,8 +83,7 @@ CommunicationIdentityClient communicationIdentityClient = new CommunicationIdent
Identity uses HMAC authentication with the resource access key.
The access key can be used to create an AzureKeyCredential and provided to the `CommunicationIdentityClientBuilder` via the credential() function. Endpoint and httpClient must also be set via the endpoint() and httpClient() functions respectively.

<!-- embedme ./src/samples/java/com/azure/communication/identity/ReadmeSamples.java#L21-L28 -->
```java
```java readme-sample-createCommunicationIdentityClient
// You can find your endpoint and access key from your resource in the Azure Portal
String endpoint = "https://<RESOURCE_NAME>.communication.azure.com";
AzureKeyCredential keyCredential = new AzureKeyCredential("<access-key>");
Expand All @@ -98,8 +96,8 @@ CommunicationIdentityClient communicationIdentityClient = new CommunicationIdent

### Connection String Authentication
Alternatively, you can provide the entire connection string using the connectionString() function instead of providing the endpoint and access key.
<!-- embedme ./src/samples/java/com/azure/communication/identity/ReadmeSamples.java#L39-L44 -->
```java

```java readme-sample-createCommunicationIdentityClientWithConnectionString
// You can find your connection string from your resource in the Azure Portal
String connectionString = "<connection_string>";

Expand All @@ -118,20 +116,18 @@ CommunicationIdentityClient communicationIdentityClient = new CommunicationIdent
Use the `createUser` function to create a new user. `user.getId()` gets the
unique ID of the user that was created.

<!-- embedme ./src/samples/java/com/azure/communication/identity/ReadmeSamples.java#L73-L74 -->
```java
```java readme-sample-createNewUser
CommunicationUserIdentifier user = communicationIdentityClient.createUser();
System.out.println("User id: " + user.getId());
```

### Getting a token for an existing user
Use the `getToken` function to get a token for an existing user. The function
also takes in a list of `CommunicationIdentityTokenScope`. Scope options include:
also takes in a list of `CommunicationTokenScope`. Scope options include:
- `chat` (Chat)
- `voip` (Voice over IP)

<!-- embedme ./src/samples/java/com/azure/communication/identity/ReadmeSamples.java#L102-L107 -->
```java
```java readme-sample-issueUserToken
// Define a list of communication token scopes
List<CommunicationTokenScope> scopes = Arrays.asList(CommunicationTokenScope.CHAT);

Expand All @@ -142,8 +138,8 @@ System.out.println("Expires at: " + userToken.getExpiresAt());

### Create a new user and token in a single request
For convenience, use `createUserAndToken` to create a new user and issue a token with one function call. This translates into a single web request as opposed to creating a user first and then issuing a token.
<!-- embedme ./src/samples/java/com/azure/communication/identity/ReadmeSamples.java#L85-L90 -->
```java

```java readme-sample-createNewUserAndToken
// Define a list of communication token scopes
List<CommunicationTokenScope> scopes = Arrays.asList(CommunicationTokenScope.CHAT);

Expand All @@ -155,26 +151,33 @@ System.out.println("User token value: " + result.getUserToken().getToken());
### Revoking all tokens for an existing user
Use the `revokeTokens` function to revoke all the issued tokens of a user.

<!-- embedme ./src/samples/java/com/azure/communication/identity/ReadmeSamples.java#L120-L121 -->
```java
```java readme-sample-revokeUserToken
// revoke tokens issued for the specified user
communicationIdentityClient.revokeTokens(user);
```

### Deleting a user
Use the `deleteUser` function to delete a user.

<!-- embedme ./src/samples/java/com/azure/communication/identity/ReadmeSamples.java#L130-L131 -->
```java
```java readme-sample-deleteUser
// delete a previously created user
communicationIdentityClient.deleteUser(user);
```

### Exchanging AAD access token of a Teams User for a Communication Identity access token
Use the `getTokenForTeamsUser` function to exchanges an AAD access token of a Teams User for a new Communication Identity access token.

```java readme-sample-getTokenForTeamsUser
AccessToken accessToken = communicationIdentityClient.getTokenForTeamsUser(teamsUserAadToken);
System.out.println("User token value: " + accessToken.getToken());
System.out.println("Expires at: " + accessToken.getExpiresAt());
```

## Troubleshooting

All user token service operations will throw an exception on failure.
<!-- embedme ./src/samples/java/com/azure/communication/identity/ReadmeSamples.java#L139-L143 -->
```java

```java readme-sample-createUserTroubleshooting
try {
CommunicationUserIdentifier user = communicationIdentityClient.createUser();
} catch (RuntimeException ex) {
Expand Down
22 changes: 3 additions & 19 deletions sdk/communication/azure-communication-identity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<groupId>com.azure</groupId>
<artifactId>azure-communication-identity</artifactId>
<packaging>jar</packaging>
<version>1.2.0-beta.1</version> <!-- {x-version-update;com.azure:azure-communication-identity;current} -->
<version>1.2.0-beta.2</version> <!-- {x-version-update;com.azure:azure-communication-identity;current} -->

<name>Microsoft Azure identity client library for communication</name>
<description>
Expand Down Expand Up @@ -50,8 +50,8 @@
<src.dir>src/main</src.dir>
<test.dir>src/test</test.dir>
<jacoco.min.linecoverage>0.88</jacoco.min.linecoverage>
<jacoco.min.branchcoverage>0.70</jacoco.min.branchcoverage>
<jacoco.skip.coverage.check>false</jacoco.skip.coverage.check>
<jacoco.min.branchcoverage>0.67</jacoco.min.branchcoverage>
<jacoco.skip>false</jacoco.skip>
<!-- Configures the Java 9+ run to perform the required module exports, opens, and reads that are necessary for testing but shouldn't be part of the module-info. -->
<javaModulesSurefireArgLine>
--add-opens com.azure.communication.identity/com.azure.communication.identity=ALL-UNNAMED
Expand Down Expand Up @@ -163,22 +163,6 @@
</rules>
</configuration>
</plugin>
<plugin>
<groupId>org.revapi</groupId>
<artifactId>revapi-maven-plugin</artifactId>
<version>0.14.6</version> <!-- {x-version-update;org.revapi:revapi-maven-plugin;external_dependency} -->
<configuration>
<analysisConfiguration>
<revapi.ignore>
<item>
<code>java.method.added</code>
<class>com.azure.core.util.HttpClientOptions</class>
<justification>Transitive from Core. Not our problem</justification>
</item>
</revapi.ignore>
</analysisConfiguration>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

package com.azure.communication.identity;

import com.azure.communication.identity.implementation.CommunicationIdentitiesImpl;
import com.azure.communication.identity.implementation.CommunicationIdentityClientImpl;
import com.azure.communication.identity.implementation.CommunicationIdentityImpl;
import com.azure.communication.identity.implementation.converters.IdentityErrorConverter;
import com.azure.communication.identity.implementation.models.CommunicationErrorResponseException;
import com.azure.communication.identity.implementation.models.CommunicationIdentityAccessToken;
import com.azure.communication.identity.implementation.models.CommunicationIdentityAccessTokenRequest;
import com.azure.communication.identity.implementation.models.CommunicationIdentityAccessTokenResult;
import com.azure.communication.identity.implementation.models.CommunicationIdentityCreateRequest;
import com.azure.communication.identity.implementation.models.CommunicationIdentityAccessToken;
import com.azure.communication.identity.implementation.models.TeamsUserAccessTokenRequest;
import com.azure.communication.identity.models.CommunicationTokenScope;
import com.azure.communication.identity.models.CommunicationUserIdentifierAndToken;
import com.azure.communication.identity.models.IdentityError;
Expand Down Expand Up @@ -40,11 +41,11 @@
@ServiceClient(builder = CommunicationIdentityClientBuilder.class, isAsync = true)
public final class CommunicationIdentityAsyncClient {

private final CommunicationIdentityImpl client;
private final CommunicationIdentitiesImpl client;
private final ClientLogger logger = new ClientLogger(CommunicationIdentityAsyncClient.class);

CommunicationIdentityAsyncClient(CommunicationIdentityClientImpl communicationIdentityServiceClient) {
client = communicationIdentityServiceClient.getCommunicationIdentity();
client = communicationIdentityServiceClient.getCommunicationIdentities();
}

/**
Expand Down Expand Up @@ -281,4 +282,48 @@ private IdentityErrorResponseException translateException(CommunicationErrorResp
}
return new IdentityErrorResponseException(exception.getMessage(), exception.getResponse(), error);
}

/**
* Exchanges an AAD access token of a Teams User for a new Communication Identity access token.
*
* @param teamsUserAadToken AAD access token of a Teams User to acquire Communication Identity access token.
* @return Communication Identity access token.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<AccessToken> getTokenForTeamsUser(String teamsUserAadToken) {
try {
TeamsUserAccessTokenRequest requestBody = new TeamsUserAccessTokenRequest();
requestBody.setToken(teamsUserAadToken);
return client.exchangeTeamsUserAccessTokenAsync(requestBody)
.onErrorMap(CommunicationErrorResponseException.class, e -> translateException(e))
.flatMap((CommunicationIdentityAccessToken rawToken) -> {
return Mono.just(new AccessToken(rawToken.getToken(), rawToken.getExpiresOn()));
});
} catch (RuntimeException ex) {
return monoError(logger, ex);
}
}

/**
* Exchanges an AAD access token of a Teams User for a new Communication Identity access token.
*
* @param teamsUserAadToken AAD access token of a Teams User to acquire Communication Identity access token.
* @return Communication Identity access token with response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<AccessToken>> getTokenForTeamsUserWithResponse(String teamsUserAadToken) {
try {
TeamsUserAccessTokenRequest requestBody = new TeamsUserAccessTokenRequest();
requestBody.setToken(teamsUserAadToken);
return client.exchangeTeamsUserAccessTokenWithResponseAsync(requestBody)
.onErrorMap(CommunicationErrorResponseException.class, e -> translateException(e))
.flatMap((Response<CommunicationIdentityAccessToken> response) -> {
AccessToken token = new AccessToken(response.getValue().getToken(), response.getValue().getExpiresOn());
return Mono.just(new SimpleResponse<AccessToken>(response, token));
});
} catch (RuntimeException ex) {
return monoError(logger, ex);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import com.azure.communication.identity.implementation.CommunicationIdentitiesImpl;
import com.azure.communication.identity.implementation.CommunicationIdentityClientImpl;
import com.azure.communication.identity.implementation.CommunicationIdentityImpl;
import com.azure.communication.identity.implementation.models.CommunicationIdentityAccessToken;
import com.azure.communication.identity.implementation.models.CommunicationIdentityAccessTokenRequest;
import com.azure.communication.identity.implementation.models.CommunicationIdentityAccessTokenResult;
import com.azure.communication.identity.implementation.models.CommunicationIdentityCreateRequest;
import com.azure.communication.identity.implementation.models.CommunicationIdentityAccessToken;
import com.azure.communication.identity.implementation.models.TeamsUserAccessTokenRequest;
import com.azure.communication.identity.models.CommunicationTokenScope;
import com.azure.communication.identity.models.CommunicationUserIdentifierAndToken;
import com.azure.communication.common.CommunicationUserIdentifier;
Expand All @@ -32,11 +33,11 @@
@ServiceClient(builder = CommunicationIdentityClientBuilder.class, isAsync = false)
public final class CommunicationIdentityClient {

private final CommunicationIdentityImpl client;
private final CommunicationIdentitiesImpl client;
private final ClientLogger logger = new ClientLogger(CommunicationIdentityClient.class);

CommunicationIdentityClient(CommunicationIdentityClientImpl communicationIdentityClient) {
client = communicationIdentityClient.getCommunicationIdentity();
client = communicationIdentityClient.getCommunicationIdentities();
}

/**
Expand Down Expand Up @@ -225,4 +226,45 @@ private CommunicationUserIdentifierAndToken userWithAccessTokenResultConverter(
return new CommunicationUserIdentifierAndToken(user, token);

}

/**
* Exchanges an AAD access token of a Teams User for a new Communication Identity access token.
*
* @param teamsUserAadToken AAD access token of a Teams User to acquire Communication Identity access token.
* @return Communication Identity access token.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public AccessToken getTokenForTeamsUser(String teamsUserAadToken) {
TeamsUserAccessTokenRequest requestBody = new TeamsUserAccessTokenRequest();
requestBody.setToken(teamsUserAadToken);
CommunicationIdentityAccessToken rawToken = client.exchangeTeamsUserAccessToken(requestBody);
return new AccessToken(rawToken.getToken(), rawToken.getExpiresOn());
}

/**
* Exchanges an AAD access token of a Teams User for a new Communication Identity access token.
*
* @param teamsUserAadToken AAD access token of a Teams User to acquire Communication Identity access token.
* @param context the context of the request. Can also be null or
* Context.NONE.
* @return Communication Identity access token with response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<AccessToken> getTokenForTeamsUserWithResponse(String teamsUserAadToken, Context context) {
context = context == null ? Context.NONE : context;
TeamsUserAccessTokenRequest requestBody = new TeamsUserAccessTokenRequest();
requestBody.setToken(teamsUserAadToken);
Response<CommunicationIdentityAccessToken> response = client.exchangeTeamsUserAccessTokenWithResponseAsync(requestBody, context)
.block();
if (response == null || response.getValue() == null) {
throw logger.logExceptionAsError(new IllegalStateException("Service failed to return a response or expected value."));
}

return new SimpleResponse<AccessToken>(
response,
new AccessToken(response.getValue().getToken(), response.getValue().getExpiresOn()));
}



}
Loading

0 comments on commit 7965e36

Please sign in to comment.