diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt index 5bef20bd1c1f5..60030f0c3ba57 100644 --- a/eng/versioning/version_client.txt +++ b/eng/versioning/version_client.txt @@ -80,7 +80,7 @@ com.azure:azure-communication-chat;1.6.8;1.7.0-beta.1 com.azure:azure-communication-common;1.4.8;1.5.0-beta.1 com.azure:azure-communication-common-perf;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-communication-email;1.1.5;1.2.0-beta.2 -com.azure:azure-communication-identity;1.6.13;1.7.0-beta.1 +com.azure:azure-communication-identity;1.6.13;2.0.0 com.azure:azure-communication-jobrouter;1.1.21;2.0.0-beta.1 com.azure:azure-communication-messages;1.1.12;1.2.0-beta.2 com.azure:azure-communication-phonenumbers;1.4.6;1.5.0-beta.1 diff --git a/sdk/communication/azure-communication-identity/CHANGELOG.md b/sdk/communication/azure-communication-identity/CHANGELOG.md index 499ad29c17e87..3d57196c53c8c 100644 --- a/sdk/communication/azure-communication-identity/CHANGELOG.md +++ b/sdk/communication/azure-communication-identity/CHANGELOG.md @@ -1,9 +1,12 @@ # Release History -## 1.7.0-beta.1 (Unreleased) +## 2.0.0 (Unreleased) ### Features Added +- Added support for service version `2026-09-23`, which is now the default. Select it explicitly + with `CommunicationIdentityServiceVersion.V2026_09_23`. + ### Breaking Changes ### Bugs Fixed diff --git a/sdk/communication/azure-communication-identity/pom.xml b/sdk/communication/azure-communication-identity/pom.xml index 96ef7e7943bb3..e4787877783ea 100644 --- a/sdk/communication/azure-communication-identity/pom.xml +++ b/sdk/communication/azure-communication-identity/pom.xml @@ -16,7 +16,7 @@ com.azure azure-communication-identity jar - 1.7.0-beta.1 + 2.0.0 Microsoft Azure identity client library for communication @@ -96,4 +96,45 @@ test + + + + + + org.jacoco + jacoco-maven-plugin + 0.8.15 + + + check + + + **/com/azure/communication/identity/IdentityClientBuilder* + **/com/azure/communication/identity/IdentityOperations*Client* + **/com/azure/communication/identity/IdentityServiceVersion* + **/com/azure/communication/identity/TeamsExtensionOperations*Client* + **/com/azure/communication/identity/TeamsUserOperations*Client* + **/com/azure/communication/identity/implementation/IdentityClientImpl* + **/com/azure/communication/identity/implementation/IdentityOperationsImpl* + **/com/azure/communication/identity/implementation/TeamsExtensionOperationsImpl* + **/com/azure/communication/identity/implementation/TeamsUserOperationsImpl* + **/com/azure/communication/identity/implementation/models/CommunicationIdentity* + **/com/azure/communication/identity/implementation/models/TeamsExtension* + + + + + + + diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/CommunicationIdentityAsyncClient.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/CommunicationIdentityAsyncClient.java index ee3e030484711..69a9c69fa109a 100644 --- a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/CommunicationIdentityAsyncClient.java +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/CommunicationIdentityAsyncClient.java @@ -3,8 +3,7 @@ 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.IdentityClientImpl; import com.azure.communication.identity.implementation.converters.IdentityErrorConverter; import com.azure.communication.identity.implementation.models.CommunicationErrorResponseException; import com.azure.communication.identity.implementation.models.CommunicationIdentityAccessTokenRequest; @@ -19,8 +18,11 @@ import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; import com.azure.core.credential.AccessToken; +import com.azure.core.http.HttpHeaderName; +import com.azure.core.http.rest.RequestOptions; import com.azure.core.http.rest.Response; import com.azure.core.http.rest.SimpleResponse; +import com.azure.core.util.BinaryData; import com.azure.core.util.logging.ClientLogger; import java.time.Duration; @@ -56,11 +58,47 @@ @ServiceClient(builder = CommunicationIdentityClientBuilder.class, isAsync = true) public final class CommunicationIdentityAsyncClient { - private final CommunicationIdentitiesImpl client; + private final IdentityOperationsAsyncClient client; + private final TeamsUserOperationsAsyncClient teamsUserClient; private final ClientLogger logger = new ClientLogger(CommunicationIdentityAsyncClient.class); - CommunicationIdentityAsyncClient(CommunicationIdentityClientImpl communicationIdentityServiceClient) { - client = communicationIdentityServiceClient.getCommunicationIdentities(); + CommunicationIdentityAsyncClient(IdentityClientImpl identityClient) { + client = new IdentityOperationsAsyncClient(identityClient.getIdentityOperations()); + teamsUserClient = new TeamsUserOperationsAsyncClient(identityClient.getTeamsUserOperations()); + } + + /** + * Builds {@link RequestOptions} for the operations that return no content. + * + *

The generated protocol methods for {@code delete} and {@code revokeAccessTokens} declare no + * Accept header, because those operations respond 204 with no body, so azure-core falls back to + * the wildcard. The AutoRest-generated client this replaces sent {@code application/json} on + * every operation regardless of response shape. Setting it here keeps the bytes on the wire + * unchanged for existing callers.

+ */ + private static RequestOptions noContentRequestOptions() { + return new RequestOptions().setHeader(HttpHeaderName.ACCEPT, "application/json"); + } + + /** + * Deserializes the {@link BinaryData} body returned by a generated protocol method, preserving the + * status code and headers of the original response. + */ + private static Response mapResponse(Response response, Class type) { + BinaryData value = response.getValue(); + return new SimpleResponse<>(response, value == null ? null : value.toObject(type)); + } + + /** + * Calls the generated create protocol method. The request body is carried on {@link RequestOptions} + * because the generated signature takes no body parameter. + */ + private Mono> + createWithResponseInternal(CommunicationIdentityCreateRequest body) { + RequestOptions requestOptions = new RequestOptions(); + requestOptions.setBody(BinaryData.fromObject(body)); + return client.createWithResponse(requestOptions) + .map(response -> mapResponse(response, CommunicationIdentityAccessTokenResult.class)); } /** @@ -71,7 +109,7 @@ public final class CommunicationIdentityAsyncClient { @ServiceMethod(returns = ReturnType.SINGLE) public Mono createUser() { try { - return client.createAsync(new CommunicationIdentityCreateRequest()) + return client.create(new CommunicationIdentityCreateRequest()) .onErrorMap(CommunicationErrorResponseException.class, IdentityErrorConverter::translateException) .flatMap((CommunicationIdentityAccessTokenResult result) -> { return Mono.just(new CommunicationUserIdentifier(result.getIdentity().getId())); @@ -89,7 +127,7 @@ public Mono createUser() { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> createUserWithResponse() { try { - return client.createWithResponseAsync(new CommunicationIdentityCreateRequest()) + return createWithResponseInternal(new CommunicationIdentityCreateRequest()) .onErrorMap(CommunicationErrorResponseException.class, IdentityErrorConverter::translateException) .flatMap((Response response) -> { String id = response.getValue().getIdentity().getId(); @@ -118,7 +156,7 @@ public Mono createUserAndToken(Iterable { return Mono.just(userWithAccessTokenResultConverter(result)); @@ -156,7 +194,7 @@ public Mono createUserAndToken(Iterable response) -> { return Mono.just(new SimpleResponse(response, @@ -190,7 +228,8 @@ public Mono createUserAndToken(Iterable deleteUser(CommunicationUserIdentifier communicationUser) { try { Objects.requireNonNull(communicationUser); - return client.deleteAsync(communicationUser.getId()) + return client.deleteWithResponse(communicationUser.getId(), noContentRequestOptions()) + .then() .onErrorMap(CommunicationErrorResponseException.class, IdentityErrorConverter::translateException); } catch (RuntimeException ex) { return monoError(logger, ex); @@ -208,7 +247,7 @@ public Mono deleteUser(CommunicationUserIdentifier communicationUser) { public Mono> deleteUserWithResponse(CommunicationUserIdentifier communicationUser) { try { Objects.requireNonNull(communicationUser); - return client.deleteWithResponseAsync(communicationUser.getId()) + return client.deleteWithResponse(communicationUser.getId(), noContentRequestOptions()) .onErrorMap(CommunicationErrorResponseException.class, IdentityErrorConverter::translateException); } catch (RuntimeException ex) { return monoError(logger, ex); @@ -225,7 +264,8 @@ public Mono> deleteUserWithResponse(CommunicationUserIdentifier c public Mono revokeTokens(CommunicationUserIdentifier communicationUser) { try { Objects.requireNonNull(communicationUser); - return client.revokeAccessTokensAsync(communicationUser.getId()) + return client.revokeAccessTokensWithResponse(communicationUser.getId(), noContentRequestOptions()) + .then() .onErrorMap(CommunicationErrorResponseException.class, IdentityErrorConverter::translateException); } catch (RuntimeException ex) { return monoError(logger, ex); @@ -242,7 +282,7 @@ public Mono revokeTokens(CommunicationUserIdentifier communicationUser) { public Mono> revokeTokensWithResponse(CommunicationUserIdentifier communicationUser) { try { Objects.requireNonNull(communicationUser); - return client.revokeAccessTokensWithResponseAsync(communicationUser.getId()) + return client.revokeAccessTokensWithResponse(communicationUser.getId(), noContentRequestOptions()) .onErrorMap(CommunicationErrorResponseException.class, IdentityErrorConverter::translateException); } catch (RuntimeException ex) { return monoError(logger, ex); @@ -269,7 +309,7 @@ public Mono getToken(CommunicationUserIdentifier communicationUser, CommunicationIdentityAccessTokenRequest tokenRequest = CommunicationIdentityClientUtils .createCommunicationIdentityAccessTokenRequest(scopes, tokenExpiresIn, logger); - return client.issueAccessTokenAsync(communicationUser.getId(), tokenRequest) + return client.issueAccessToken(communicationUser.getId(), tokenRequest) .onErrorMap(CommunicationErrorResponseException.class, IdentityErrorConverter::translateException) .flatMap((CommunicationIdentityAccessToken rawToken) -> { return Mono.just(new AccessToken(rawToken.getToken(), rawToken.getExpiresOn())); @@ -313,7 +353,10 @@ public Mono> getTokenWithResponse(CommunicationUserIdentif CommunicationIdentityAccessTokenRequest tokenRequest = CommunicationIdentityClientUtils .createCommunicationIdentityAccessTokenRequest(scopes, tokenExpiresIn, logger); - return client.issueAccessTokenWithResponseAsync(communicationUser.getId(), tokenRequest) + return client + .issueAccessTokenWithResponse(communicationUser.getId(), BinaryData.fromObject(tokenRequest), + new RequestOptions()) + .map(response -> mapResponse(response, CommunicationIdentityAccessToken.class)) .onErrorMap(CommunicationErrorResponseException.class, IdentityErrorConverter::translateException) .flatMap((Response response) -> { AccessToken token @@ -363,7 +406,7 @@ public Mono> getTokenWithResponse(CommunicationUserIdentif @ServiceMethod(returns = ReturnType.SINGLE) public Mono getTokenForTeamsUser(GetTokenForTeamsUserOptions options) { try { - return client.exchangeTeamsUserAccessTokenAsync(options) + return teamsUserClient.exchangeTeamsUserAccessToken(options) .onErrorMap(CommunicationErrorResponseException.class, IdentityErrorConverter::translateException) .flatMap((CommunicationIdentityAccessToken rawToken) -> { return Mono.just(new AccessToken(rawToken.getToken(), rawToken.getExpiresOn())); @@ -382,7 +425,9 @@ public Mono getTokenForTeamsUser(GetTokenForTeamsUserOptions option @ServiceMethod(returns = ReturnType.SINGLE) public Mono> getTokenForTeamsUserWithResponse(GetTokenForTeamsUserOptions options) { try { - return client.exchangeTeamsUserAccessTokenWithResponseAsync(options) + return teamsUserClient + .exchangeTeamsUserAccessTokenWithResponse(BinaryData.fromObject(options), new RequestOptions()) + .map(response -> mapResponse(response, CommunicationIdentityAccessToken.class)) .onErrorMap(CommunicationErrorResponseException.class, IdentityErrorConverter::translateException) .flatMap((Response response) -> { AccessToken token diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/CommunicationIdentityClient.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/CommunicationIdentityClient.java index efdce3655d8d7..80553af700931 100644 --- a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/CommunicationIdentityClient.java +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/CommunicationIdentityClient.java @@ -4,8 +4,7 @@ package com.azure.communication.identity; import com.azure.communication.common.CommunicationUserIdentifier; -import com.azure.communication.identity.implementation.CommunicationIdentitiesImpl; -import com.azure.communication.identity.implementation.CommunicationIdentityClientImpl; +import com.azure.communication.identity.implementation.IdentityClientImpl; import com.azure.communication.identity.implementation.models.CommunicationIdentityAccessToken; import com.azure.communication.identity.implementation.models.CommunicationIdentityAccessTokenRequest; import com.azure.communication.identity.implementation.models.CommunicationIdentityAccessTokenResult; @@ -17,8 +16,11 @@ import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; import com.azure.core.credential.AccessToken; +import com.azure.core.http.HttpHeaderName; +import com.azure.core.http.rest.RequestOptions; import com.azure.core.http.rest.Response; import com.azure.core.http.rest.SimpleResponse; +import com.azure.core.util.BinaryData; import com.azure.core.util.Context; import com.azure.core.util.logging.ClientLogger; @@ -50,11 +52,61 @@ @ServiceClient(builder = CommunicationIdentityClientBuilder.class, isAsync = false) public final class CommunicationIdentityClient { - private final CommunicationIdentitiesImpl client; + private final IdentityOperationsClient client; + private final TeamsUserOperationsClient teamsUserClient; private final ClientLogger logger = new ClientLogger(CommunicationIdentityClient.class); - CommunicationIdentityClient(CommunicationIdentityClientImpl communicationIdentityClient) { - client = communicationIdentityClient.getCommunicationIdentities(); + CommunicationIdentityClient(IdentityClientImpl identityClient) { + client = new IdentityOperationsClient(identityClient.getIdentityOperations()); + teamsUserClient = new TeamsUserOperationsClient(identityClient.getTeamsUserOperations()); + } + + /** + * Builds the {@link RequestOptions} the generated protocol methods take, carrying over the + * caller-supplied {@link Context}. + */ + private static RequestOptions toRequestOptions(Context context) { + RequestOptions requestOptions = new RequestOptions(); + if (context != null && context != Context.NONE) { + requestOptions.setContext(context); + } + return requestOptions; + } + + /** + * Builds {@link RequestOptions} for the operations that return no content. + * + *

The generated protocol methods for {@code delete} and {@code revokeAccessTokens} declare no + * Accept header, because those operations respond 204 with no body, so azure-core falls back to + * the wildcard. The AutoRest-generated client this replaces sent {@code application/json} on + * every operation regardless of response shape. Setting it here keeps the bytes on the wire + * unchanged for existing callers.

+ */ + private static RequestOptions noContentRequestOptions(Context context) { + return toRequestOptions(context).setHeader(HttpHeaderName.ACCEPT, "application/json"); + } + + /** + * Deserializes the {@link BinaryData} body returned by a generated protocol method, preserving the + * status code and headers of the original response. + */ + private static Response mapResponse(Response response, Class type) { + if (response == null) { + return null; + } + BinaryData value = response.getValue(); + return new SimpleResponse<>(response, value == null ? null : value.toObject(type)); + } + + /** + * Calls the generated create protocol method. The request body is carried on {@link RequestOptions} + * because the generated signature takes no body parameter. + */ + private Response + createWithResponseInternal(CommunicationIdentityCreateRequest body, Context context) { + RequestOptions requestOptions = toRequestOptions(context); + requestOptions.setBody(BinaryData.fromObject(body)); + return mapResponse(client.createWithResponse(requestOptions), CommunicationIdentityAccessTokenResult.class); } /** @@ -78,7 +130,7 @@ public CommunicationUserIdentifier createUser() { public Response createUserWithResponse(Context context) { context = context == null ? Context.NONE : context; Response response - = client.createWithResponse(new CommunicationIdentityCreateRequest(), context); + = createWithResponseInternal(new CommunicationIdentityCreateRequest(), context); if (response == null || response.getValue() == null) { throw logger.logExceptionAsError( @@ -139,7 +191,7 @@ public Response createUserAndTokenWithRespo = CommunicationIdentityClientUtils.createCommunicationIdentityCreateRequest(scopes, tokenExpiresIn, logger); Response response - = client.createWithResponse(communicationIdentityCreateRequest, context); + = createWithResponseInternal(communicationIdentityCreateRequest, context); if (response == null || response.getValue() == null) { throw logger.logExceptionAsError( @@ -171,7 +223,7 @@ public Response createUserAndTokenWithRespo @ServiceMethod(returns = ReturnType.SINGLE) public void deleteUser(CommunicationUserIdentifier communicationUser) { Objects.requireNonNull(communicationUser); - client.delete(communicationUser.getId()); + client.deleteWithResponse(communicationUser.getId(), noContentRequestOptions(null)); } /** @@ -186,7 +238,7 @@ public void deleteUser(CommunicationUserIdentifier communicationUser) { public Response deleteUserWithResponse(CommunicationUserIdentifier communicationUser, Context context) { Objects.requireNonNull(communicationUser); context = context == null ? Context.NONE : context; - return client.deleteWithResponse(communicationUser.getId(), context); + return client.deleteWithResponse(communicationUser.getId(), noContentRequestOptions(context)); } /** @@ -197,7 +249,7 @@ public Response deleteUserWithResponse(CommunicationUserIdentifier communi @ServiceMethod(returns = ReturnType.SINGLE) public void revokeTokens(CommunicationUserIdentifier communicationUser) { Objects.requireNonNull(communicationUser); - client.revokeAccessTokens(communicationUser.getId()); + client.revokeAccessTokensWithResponse(communicationUser.getId(), noContentRequestOptions(null)); } /** @@ -212,7 +264,7 @@ public void revokeTokens(CommunicationUserIdentifier communicationUser) { public Response revokeTokensWithResponse(CommunicationUserIdentifier communicationUser, Context context) { Objects.requireNonNull(communicationUser); context = context == null ? Context.NONE : context; - return client.revokeAccessTokensWithResponse(communicationUser.getId(), context); + return client.revokeAccessTokensWithResponse(communicationUser.getId(), noContentRequestOptions(context)); } /** @@ -273,8 +325,10 @@ public Response getTokenWithResponse(CommunicationUserIdentifier co CommunicationIdentityAccessTokenRequest tokenRequest = CommunicationIdentityClientUtils .createCommunicationIdentityAccessTokenRequest(scopes, tokenExpiresIn, logger); - Response response - = client.issueAccessTokenWithResponse(communicationUser.getId(), tokenRequest, context); + Response response = mapResponse( + client.issueAccessTokenWithResponse(communicationUser.getId(), BinaryData.fromObject(tokenRequest), + toRequestOptions(context)), + CommunicationIdentityAccessToken.class); if (response == null || response.getValue() == null) { throw logger.logExceptionAsError( @@ -318,7 +372,7 @@ public Response getTokenWithResponse(CommunicationUserIdentifier co */ @ServiceMethod(returns = ReturnType.SINGLE) public AccessToken getTokenForTeamsUser(GetTokenForTeamsUserOptions options) { - CommunicationIdentityAccessToken rawToken = client.exchangeTeamsUserAccessToken(options); + CommunicationIdentityAccessToken rawToken = teamsUserClient.exchangeTeamsUserAccessToken(options); return new AccessToken(rawToken.getToken(), rawToken.getExpiresOn()); } @@ -335,7 +389,8 @@ public Response getTokenForTeamsUserWithResponse(GetTokenForTeamsUs Context context) { context = context == null ? Context.NONE : context; Response response - = client.exchangeTeamsUserAccessTokenWithResponse(options, context); + = mapResponse(teamsUserClient.exchangeTeamsUserAccessTokenWithResponse(BinaryData.fromObject(options), + toRequestOptions(context)), CommunicationIdentityAccessToken.class); if (response == null || response.getValue() == null) { throw logger.logExceptionAsError( new IllegalStateException("Service failed to return a response or expected value.")); diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/CommunicationIdentityClientBuilder.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/CommunicationIdentityClientBuilder.java index 67dd22d70c8d6..a9c2e2b2aea46 100644 --- a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/CommunicationIdentityClientBuilder.java +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/CommunicationIdentityClientBuilder.java @@ -5,7 +5,7 @@ import com.azure.communication.common.implementation.CommunicationConnectionString; import com.azure.communication.common.implementation.HmacAuthenticationPolicy; -import com.azure.communication.identity.implementation.CommunicationIdentityClientImpl; +import com.azure.communication.identity.implementation.IdentityClientImpl; import com.azure.core.annotation.ServiceClientBuilder; import com.azure.core.client.traits.AzureKeyCredentialTrait; import com.azure.core.client.traits.ConfigurationTrait; @@ -18,12 +18,14 @@ import com.azure.core.http.HttpClient; import com.azure.core.http.HttpPipeline; import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.HttpPipelineCallContext; import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; import com.azure.core.http.policy.CookiePolicy; import com.azure.core.http.policy.HttpLogDetailLevel; import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.http.policy.HttpLoggingPolicy; import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.HttpPipelineSyncPolicy; import com.azure.core.http.policy.RequestIdPolicy; import com.azure.core.http.policy.RetryOptions; import com.azure.core.http.policy.RetryPolicy; @@ -32,9 +34,10 @@ import com.azure.core.util.Configuration; import com.azure.core.util.CoreUtils; import com.azure.core.util.HttpClientOptions; +import com.azure.core.util.UrlBuilder; import com.azure.core.util.builder.ClientBuilderUtil; import com.azure.core.util.logging.ClientLogger; - +import java.net.MalformedURLException; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -89,6 +92,8 @@ public final class CommunicationIdentityClientBuilder implements private static final String COMMUNICATION_IDENTITY_PROPERTIES = "azure-communication-identity.properties"; + private static final String API_VERSION_QUERY_PARAM = "api-version"; + private final ClientLogger logger = new ClientLogger(CommunicationIdentityClientBuilder.class); private String endpoint; private AzureKeyCredential azureKeyCredential; @@ -364,18 +369,95 @@ public CommunicationIdentityClient buildClient() { return new CommunicationIdentityClient(createServiceImpl()); } - private CommunicationIdentityClientImpl createServiceImpl() { + private IdentityClientImpl createServiceImpl() { Objects.requireNonNull(endpoint); + CommunicationIdentityServiceVersion apiVersion + = serviceVersion != null ? serviceVersion : CommunicationIdentityServiceVersion.getLatest(); + HttpPipeline builderPipeline = this.pipeline; if (this.pipeline == null) { - builderPipeline = createHttpPipeline(httpClient, createHttpPipelineAuthPolicy(), customPolicies); + builderPipeline = createHttpPipeline(httpClient, createHttpPipelineAuthPolicy(), customPolicies, + apiVersion.getVersion()); } - CommunicationIdentityServiceVersion apiVersion - = serviceVersion != null ? serviceVersion : CommunicationIdentityServiceVersion.getLatest(); + return new IdentityClientImpl(builderPipeline, endpoint, mapServiceVersion(apiVersion)); + } + + /** + * Maps the public {@link CommunicationIdentityServiceVersion} onto the generated + * {@link IdentityServiceVersion}. + * + *

The generated client only declares the api-versions present in the TypeSpec {@code Versions} + * enum, which is a subset of the versions this library has shipped. For a value with no generated + * counterpart this returns the newest generated version purely to satisfy the constructor; the + * api-version actually sent is pinned by {@link #createApiVersionPolicy(String)}, so the caller's + * selection is what reaches the service.

+ */ + private IdentityServiceVersion mapServiceVersion(CommunicationIdentityServiceVersion apiVersion) { + for (IdentityServiceVersion generated : IdentityServiceVersion.values()) { + if (generated.getVersion().equals(apiVersion.getVersion())) { + return generated; + } + } + + return IdentityServiceVersion.getLatest(); + } - return new CommunicationIdentityClientImpl(builderPipeline, endpoint, apiVersion.getVersion()); + /** + * Pins the {@code api-version} query parameter to the service version selected on this builder. + * + *

This is the seam that decouples the public {@link CommunicationIdentityServiceVersion} from the + * generated {@link IdentityServiceVersion}. The generated client takes a typed enum rather than a + * string, so without this policy any version absent from that enum could not be reached at all.

+ * + * @param apiVersion the api-version string to send. + * @return a policy that overwrites the api-version query parameter on every request. + */ + private HttpPipelinePolicy createApiVersionPolicy(String apiVersion) { + return new ApiVersionPolicy(apiVersion, logger); + } + + /** + * Overwrites the {@code api-version} query parameter with the version selected on the builder. + * + *

Extends {@link HttpPipelineSyncPolicy} rather than implementing {@link HttpPipelinePolicy} + * directly. That base class implements both the synchronous and the asynchronous entry points + * in terms of a single hook, so the rewrite happens on whichever path the caller used. A policy + * that supplies only {@code process} inherits the interface default for {@code processSync}, + * which wraps the call in a {@code Mono} and blocks on it - an allocation and a subscription on + * every synchronous request, to substitute a string in a URL.

+ * + *

No thread pool is exhausted by that: {@code HttpPipelineNextPolicy.process} recognises + * that it was entered from the synchronous default and returns to the synchronous chain, on + * the caller's own thread. The exception is a caller that invokes the synchronous client from + * a non-blocking thread, where that check inverts - azure-core then logs "The pipeline + * switched from synchronous to asynchronous" and the request completes asynchronously.

+ * + *

The difference is invisible to the test suite. It is a cost rather than a behaviour, so + * no assertion here distinguishes the two forms.

+ */ + private static final class ApiVersionPolicy extends HttpPipelineSyncPolicy { + private final String apiVersion; + private final ClientLogger logger; + + ApiVersionPolicy(String apiVersion, ClientLogger logger) { + this.apiVersion = apiVersion; + this.logger = logger; + } + + @Override + protected void beforeSendingRequest(HttpPipelineCallContext context) { + UrlBuilder urlBuilder = UrlBuilder.parse(context.getHttpRequest().getUrl()); + if (urlBuilder.getQuery().containsKey(API_VERSION_QUERY_PARAM)) { + urlBuilder.setQueryParameter(API_VERSION_QUERY_PARAM, apiVersion); + try { + context.getHttpRequest().setUrl(urlBuilder.toUrl()); + } catch (MalformedURLException ex) { + throw logger.logExceptionAsError(new IllegalStateException("Failed to set api-version.", ex)); + } + } + } } private HttpPipelinePolicy createHttpPipelineAuthPolicy() { @@ -395,10 +477,11 @@ private HttpPipelinePolicy createHttpPipelineAuthPolicy() { } private HttpPipeline createHttpPipeline(HttpClient httpClient, HttpPipelinePolicy authorizationPolicy, - List customPolicies) { + List customPolicies, String apiVersion) { List policies = new ArrayList(); applyRequiredPolicies(policies, authorizationPolicy); + policies.add(createApiVersionPolicy(apiVersion)); if (customPolicies != null && customPolicies.size() > 0) { policies.addAll(customPolicies); diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/CommunicationIdentityClientUtils.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/CommunicationIdentityClientUtils.java index 63fe4e9e4852c..9fe736768412e 100644 --- a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/CommunicationIdentityClientUtils.java +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/CommunicationIdentityClientUtils.java @@ -41,8 +41,7 @@ static CommunicationIdentityAccessTokenRequest createCommunicationIdentityAccess final List scopesInput = StreamSupport.stream(scopes.spliterator(), false).collect(Collectors.toList()); - CommunicationIdentityAccessTokenRequest tokenRequest = new CommunicationIdentityAccessTokenRequest(); - tokenRequest.setScopes(scopesInput); + CommunicationIdentityAccessTokenRequest tokenRequest = new CommunicationIdentityAccessTokenRequest(scopesInput); if (tokenExpiresIn != null) { int expiresInMinutes = getTokenExpirationInMinutes(tokenExpiresIn, logger); diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/CommunicationIdentityServiceVersion.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/CommunicationIdentityServiceVersion.java index 8462d20b868a1..828ae60f4560c 100644 --- a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/CommunicationIdentityServiceVersion.java +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/CommunicationIdentityServiceVersion.java @@ -27,7 +27,17 @@ public enum CommunicationIdentityServiceVersion implements ServiceVersion { /** * Service version {@code 2023-10-01}. */ - V2023_10_01("2023-10-01"); + V2023_10_01("2023-10-01"), + + /** + * Service version {@code 2025-06-30}. + */ + V2025_06_30("2025-06-30"), + + /** + * Service version {@code 2026-09-23}. + */ + V2026_09_23("2026-09-23"); private final String version; @@ -50,6 +60,6 @@ public String getVersion() { * @return the latest {@link CommunicationIdentityServiceVersion} */ public static CommunicationIdentityServiceVersion getLatest() { - return V2023_10_01; + return V2026_09_23; } } diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/IdentityClientBuilder.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/IdentityClientBuilder.java new file mode 100644 index 0000000000000..c59eb643a9cbf --- /dev/null +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/IdentityClientBuilder.java @@ -0,0 +1,355 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.communication.identity; + +import com.azure.communication.identity.implementation.IdentityClientImpl; +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.client.traits.ConfigurationTrait; +import com.azure.core.client.traits.EndpointTrait; +import com.azure.core.client.traits.HttpTrait; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.HttpPipelinePosition; +import com.azure.core.http.policy.AddDatePolicy; +import com.azure.core.http.policy.AddHeadersFromContextPolicy; +import com.azure.core.http.policy.AddHeadersPolicy; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.HttpLoggingPolicy; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.HttpPolicyProviders; +import com.azure.core.http.policy.RequestIdPolicy; +import com.azure.core.http.policy.RetryOptions; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.util.ClientOptions; +import com.azure.core.util.Configuration; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.builder.ClientBuilderUtil; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.serializer.JacksonAdapter; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * A builder for creating a new instance of the IdentityClient type. + */ +@ServiceClientBuilder( + serviceClients = { + IdentityOperationsClient.class, + TeamsUserOperationsClient.class, + TeamsExtensionOperationsClient.class, + IdentityOperationsAsyncClient.class, + TeamsUserOperationsAsyncClient.class, + TeamsExtensionOperationsAsyncClient.class }) +public final class IdentityClientBuilder implements HttpTrait, + ConfigurationTrait, EndpointTrait { + + @Generated + private static final String SDK_NAME = "name"; + + @Generated + private static final String SDK_VERSION = "version"; + + @Generated + private static final Map PROPERTIES + = CoreUtils.getProperties("azure-communication-identity.properties"); + + @Generated + private final List pipelinePolicies; + + /** + * Create an instance of the IdentityClientBuilder. + */ + @Generated + public IdentityClientBuilder() { + this.pipelinePolicies = new ArrayList<>(); + } + + /* + * The HTTP client used to send the request. + */ + @Generated + private HttpClient httpClient; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public IdentityClientBuilder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /* + * The HTTP pipeline to send requests through. + */ + @Generated + private HttpPipeline pipeline; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public IdentityClientBuilder pipeline(HttpPipeline pipeline) { + if (this.pipeline != null && pipeline == null) { + LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured."); + } + this.pipeline = pipeline; + return this; + } + + /* + * The logging configuration for HTTP requests and responses. + */ + @Generated + private HttpLogOptions httpLogOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public IdentityClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) { + this.httpLogOptions = httpLogOptions; + return this; + } + + /* + * The client options such as application ID and custom headers to set on a request. + */ + @Generated + private ClientOptions clientOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public IdentityClientBuilder clientOptions(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + return this; + } + + /* + * The retry options to configure retry policy for failed requests. + */ + @Generated + private RetryOptions retryOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public IdentityClientBuilder retryOptions(RetryOptions retryOptions) { + this.retryOptions = retryOptions; + return this; + } + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public IdentityClientBuilder addPolicy(HttpPipelinePolicy customPolicy) { + Objects.requireNonNull(customPolicy, "'customPolicy' cannot be null."); + pipelinePolicies.add(customPolicy); + return this; + } + + /* + * The configuration store that is used during construction of the service client. + */ + @Generated + private Configuration configuration; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public IdentityClientBuilder configuration(Configuration configuration) { + this.configuration = configuration; + return this; + } + + /* + * The service endpoint + */ + @Generated + private String endpoint; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public IdentityClientBuilder endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + /* + * Service version + */ + @Generated + private IdentityServiceVersion serviceVersion; + + /** + * Sets Service version. + * + * @param serviceVersion the serviceVersion value. + * @return the IdentityClientBuilder. + */ + @Generated + public IdentityClientBuilder serviceVersion(IdentityServiceVersion serviceVersion) { + this.serviceVersion = serviceVersion; + return this; + } + + /* + * The retry policy that will attempt to retry failed requests, if applicable. + */ + @Generated + private RetryPolicy retryPolicy; + + /** + * Sets The retry policy that will attempt to retry failed requests, if applicable. + * + * @param retryPolicy the retryPolicy value. + * @return the IdentityClientBuilder. + */ + @Generated + public IdentityClientBuilder retryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = retryPolicy; + return this; + } + + /** + * Builds an instance of IdentityClientImpl with the provided parameters. + * + * @return an instance of IdentityClientImpl. + */ + @Generated + private IdentityClientImpl buildInnerClient() { + this.validateClient(); + HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline(); + IdentityServiceVersion localServiceVersion + = (serviceVersion != null) ? serviceVersion : IdentityServiceVersion.getLatest(); + IdentityClientImpl client = new IdentityClientImpl(localPipeline, + JacksonAdapter.createDefaultSerializerAdapter(), this.endpoint, localServiceVersion); + return client; + } + + @Generated + private void validateClient() { + // This method is invoked from 'buildInnerClient'/'buildClient' method. + // Developer can customize this method, to validate that the necessary conditions are met for the new client. + Objects.requireNonNull(endpoint, "'endpoint' cannot be null."); + } + + @Generated + private HttpPipeline createHttpPipeline() { + Configuration buildConfiguration + = (configuration == null) ? Configuration.getGlobalConfiguration() : configuration; + HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions; + ClientOptions localClientOptions = this.clientOptions == null ? new ClientOptions() : this.clientOptions; + List policies = new ArrayList<>(); + String clientName = PROPERTIES.getOrDefault(SDK_NAME, "UnknownName"); + String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion"); + String applicationId = CoreUtils.getApplicationId(localClientOptions, localHttpLogOptions); + policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration)); + policies.add(new RequestIdPolicy()); + policies.add(new AddHeadersFromContextPolicy()); + HttpHeaders headers = CoreUtils.createHttpHeadersFromClientOptions(localClientOptions); + if (headers != null) { + policies.add(new AddHeadersPolicy(headers)); + } + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + .forEach(p -> policies.add(p)); + HttpPolicyProviders.addBeforeRetryPolicies(policies); + policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy())); + policies.add(new AddDatePolicy()); + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + .forEach(p -> policies.add(p)); + HttpPolicyProviders.addAfterRetryPolicies(policies); + policies.add(new HttpLoggingPolicy(localHttpLogOptions)); + HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])) + .httpClient(httpClient) + .clientOptions(localClientOptions) + .build(); + return httpPipeline; + } + + /** + * Builds an instance of IdentityOperationsAsyncClient class. + * + * @return an instance of IdentityOperationsAsyncClient. + */ + @Generated + public IdentityOperationsAsyncClient buildIdentityOperationsAsyncClient() { + return new IdentityOperationsAsyncClient(buildInnerClient().getIdentityOperations()); + } + + /** + * Builds an instance of TeamsUserOperationsAsyncClient class. + * + * @return an instance of TeamsUserOperationsAsyncClient. + */ + @Generated + public TeamsUserOperationsAsyncClient buildTeamsUserOperationsAsyncClient() { + return new TeamsUserOperationsAsyncClient(buildInnerClient().getTeamsUserOperations()); + } + + /** + * Builds an instance of TeamsExtensionOperationsAsyncClient class. + * + * @return an instance of TeamsExtensionOperationsAsyncClient. + */ + @Generated + public TeamsExtensionOperationsAsyncClient buildTeamsExtensionOperationsAsyncClient() { + return new TeamsExtensionOperationsAsyncClient(buildInnerClient().getTeamsExtensionOperations()); + } + + /** + * Builds an instance of IdentityOperationsClient class. + * + * @return an instance of IdentityOperationsClient. + */ + @Generated + public IdentityOperationsClient buildIdentityOperationsClient() { + return new IdentityOperationsClient(buildInnerClient().getIdentityOperations()); + } + + /** + * Builds an instance of TeamsUserOperationsClient class. + * + * @return an instance of TeamsUserOperationsClient. + */ + @Generated + public TeamsUserOperationsClient buildTeamsUserOperationsClient() { + return new TeamsUserOperationsClient(buildInnerClient().getTeamsUserOperations()); + } + + /** + * Builds an instance of TeamsExtensionOperationsClient class. + * + * @return an instance of TeamsExtensionOperationsClient. + */ + @Generated + public TeamsExtensionOperationsClient buildTeamsExtensionOperationsClient() { + return new TeamsExtensionOperationsClient(buildInnerClient().getTeamsExtensionOperations()); + } + + private static final ClientLogger LOGGER = new ClientLogger(IdentityClientBuilder.class); +} diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/IdentityOperationsAsyncClient.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/IdentityOperationsAsyncClient.java new file mode 100644 index 0000000000000..2aafca32cb982 --- /dev/null +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/IdentityOperationsAsyncClient.java @@ -0,0 +1,277 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.communication.identity; + +import com.azure.communication.identity.implementation.IdentityOperationsImpl; +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.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.core.util.FluxUtil; +import reactor.core.publisher.Mono; + +/** + * Initializes a new instance of the asynchronous IdentityClient type. + */ +@ServiceClient(builder = IdentityClientBuilder.class, isAsync = true) +public final class IdentityOperationsAsyncClient { + + @Generated + private final IdentityOperationsImpl serviceClient; + + /** + * Initializes an instance of IdentityOperationsAsyncClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + IdentityOperationsAsyncClient(IdentityOperationsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * Create a new identity, and optionally, an access token. + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
Content-TypeStringNoThe content type. Allowed values: + * "application/json".
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     createTokenWithScopes (Optional): [
+     *         String(chat/voip/chat.join/chat.join.limited/voip.join) (Optional)
+     *     ]
+     *     expiresInMinutes: Integer (Optional)
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     identity (Required): {
+     *         id: String (Required)
+     *     }
+     *     accessToken (Optional): {
+     *         token: String (Required)
+     *         expiresOn: OffsetDateTime (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a communication identity with access token along with {@link Response} on successful completion of + * {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Mono> createWithResponse(RequestOptions requestOptions) { + return this.serviceClient.createWithResponseAsync(requestOptions); + } + + /** + * Delete the identity, revoke all tokens for the identity and delete all associated data. + * + * @param id Identifier of the identity to be deleted. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Mono> deleteWithResponse(String id, RequestOptions requestOptions) { + return this.serviceClient.deleteWithResponseAsync(id, requestOptions); + } + + /** + * Revoke all access tokens for the specific identity. + * + * @param id Identifier of the identity. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Mono> revokeAccessTokensWithResponse(String id, RequestOptions requestOptions) { + return this.serviceClient.revokeAccessTokensWithResponseAsync(id, requestOptions); + } + + /** + * Issue a new token for an identity. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     scopes (Required): [
+     *         String(chat/voip/chat.join/chat.join.limited/voip.join) (Required)
+     *     ]
+     *     expiresInMinutes: Integer (Optional)
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     token: String (Required)
+     *     expiresOn: OffsetDateTime (Required)
+     * }
+     * }
+     * 
+ * + * @param id Identifier of the identity to issue token for. + * @param body Requested scopes for the new token. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return an access token along with {@link Response} on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Mono> issueAccessTokenWithResponse(String id, BinaryData body, RequestOptions requestOptions) { + return this.serviceClient.issueAccessTokenWithResponseAsync(id, body, requestOptions); + } + + /** + * Create a new identity, and optionally, an access token. + * + * @param body If specified, creates also a Communication Identity access token associated with the identity and + * containing the requested scopes. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a communication identity with access token on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Mono create(CommunicationIdentityCreateRequest body) { + // Generated convenience method for createWithResponse + RequestOptions requestOptions = new RequestOptions(); + if (body != null) { + requestOptions.setBody(BinaryData.fromObject(body)); + } + return createWithResponse(requestOptions).flatMap(FluxUtil::toMono) + .map(protocolMethodData -> protocolMethodData.toObject(CommunicationIdentityAccessTokenResult.class)); + } + + /** + * Create a new identity, and optionally, an access token. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a communication identity with access token on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Mono create() { + // Generated convenience method for createWithResponse + RequestOptions requestOptions = new RequestOptions(); + return createWithResponse(requestOptions).flatMap(FluxUtil::toMono) + .map(protocolMethodData -> protocolMethodData.toObject(CommunicationIdentityAccessTokenResult.class)); + } + + /** + * Delete the identity, revoke all tokens for the identity and delete all associated data. + * + * @param id Identifier of the identity to be deleted. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return A {@link Mono} that completes when a successful response is received. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Mono delete(String id) { + // Generated convenience method for deleteWithResponse + RequestOptions requestOptions = new RequestOptions(); + return deleteWithResponse(id, requestOptions).flatMap(FluxUtil::toMono); + } + + /** + * Revoke all access tokens for the specific identity. + * + * @param id Identifier of the identity. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return A {@link Mono} that completes when a successful response is received. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Mono revokeAccessTokens(String id) { + // Generated convenience method for revokeAccessTokensWithResponse + RequestOptions requestOptions = new RequestOptions(); + return revokeAccessTokensWithResponse(id, requestOptions).flatMap(FluxUtil::toMono); + } + + /** + * Issue a new token for an identity. + * + * @param id Identifier of the identity to issue token for. + * @param body Requested scopes for the new token. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return an access token on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Mono issueAccessToken(String id, CommunicationIdentityAccessTokenRequest body) { + // Generated convenience method for issueAccessTokenWithResponse + RequestOptions requestOptions = new RequestOptions(); + return issueAccessTokenWithResponse(id, BinaryData.fromObject(body), requestOptions).flatMap(FluxUtil::toMono) + .map(protocolMethodData -> protocolMethodData.toObject(CommunicationIdentityAccessToken.class)); + } +} diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/IdentityOperationsClient.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/IdentityOperationsClient.java new file mode 100644 index 0000000000000..53939d135348b --- /dev/null +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/IdentityOperationsClient.java @@ -0,0 +1,270 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.communication.identity; + +import com.azure.communication.identity.implementation.IdentityOperationsImpl; +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.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; + +/** + * Initializes a new instance of the synchronous IdentityClient type. + */ +@ServiceClient(builder = IdentityClientBuilder.class) +public final class IdentityOperationsClient { + + @Generated + private final IdentityOperationsImpl serviceClient; + + /** + * Initializes an instance of IdentityOperationsClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + IdentityOperationsClient(IdentityOperationsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * Create a new identity, and optionally, an access token. + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
Content-TypeStringNoThe content type. Allowed values: + * "application/json".
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     createTokenWithScopes (Optional): [
+     *         String(chat/voip/chat.join/chat.join.limited/voip.join) (Optional)
+     *     ]
+     *     expiresInMinutes: Integer (Optional)
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     identity (Required): {
+     *         id: String (Required)
+     *     }
+     *     accessToken (Optional): {
+     *         token: String (Required)
+     *         expiresOn: OffsetDateTime (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a communication identity with access token along with {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Response createWithResponse(RequestOptions requestOptions) { + return this.serviceClient.createWithResponse(requestOptions); + } + + /** + * Delete the identity, revoke all tokens for the identity and delete all associated data. + * + * @param id Identifier of the identity to be deleted. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Response deleteWithResponse(String id, RequestOptions requestOptions) { + return this.serviceClient.deleteWithResponse(id, requestOptions); + } + + /** + * Revoke all access tokens for the specific identity. + * + * @param id Identifier of the identity. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Response revokeAccessTokensWithResponse(String id, RequestOptions requestOptions) { + return this.serviceClient.revokeAccessTokensWithResponse(id, requestOptions); + } + + /** + * Issue a new token for an identity. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     scopes (Required): [
+     *         String(chat/voip/chat.join/chat.join.limited/voip.join) (Required)
+     *     ]
+     *     expiresInMinutes: Integer (Optional)
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     token: String (Required)
+     *     expiresOn: OffsetDateTime (Required)
+     * }
+     * }
+     * 
+ * + * @param id Identifier of the identity to issue token for. + * @param body Requested scopes for the new token. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return an access token along with {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Response issueAccessTokenWithResponse(String id, BinaryData body, RequestOptions requestOptions) { + return this.serviceClient.issueAccessTokenWithResponse(id, body, requestOptions); + } + + /** + * Create a new identity, and optionally, an access token. + * + * @param body If specified, creates also a Communication Identity access token associated with the identity and + * containing the requested scopes. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a communication identity with access token. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + CommunicationIdentityAccessTokenResult create(CommunicationIdentityCreateRequest body) { + // Generated convenience method for createWithResponse + RequestOptions requestOptions = new RequestOptions(); + if (body != null) { + requestOptions.setBody(BinaryData.fromObject(body)); + } + return createWithResponse(requestOptions).getValue().toObject(CommunicationIdentityAccessTokenResult.class); + } + + /** + * Create a new identity, and optionally, an access token. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a communication identity with access token. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + CommunicationIdentityAccessTokenResult create() { + // Generated convenience method for createWithResponse + RequestOptions requestOptions = new RequestOptions(); + return createWithResponse(requestOptions).getValue().toObject(CommunicationIdentityAccessTokenResult.class); + } + + /** + * Delete the identity, revoke all tokens for the identity and delete all associated data. + * + * @param id Identifier of the identity to be deleted. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + void delete(String id) { + // Generated convenience method for deleteWithResponse + RequestOptions requestOptions = new RequestOptions(); + deleteWithResponse(id, requestOptions).getValue(); + } + + /** + * Revoke all access tokens for the specific identity. + * + * @param id Identifier of the identity. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + void revokeAccessTokens(String id) { + // Generated convenience method for revokeAccessTokensWithResponse + RequestOptions requestOptions = new RequestOptions(); + revokeAccessTokensWithResponse(id, requestOptions).getValue(); + } + + /** + * Issue a new token for an identity. + * + * @param id Identifier of the identity to issue token for. + * @param body Requested scopes for the new token. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return an access token. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + CommunicationIdentityAccessToken issueAccessToken(String id, CommunicationIdentityAccessTokenRequest body) { + // Generated convenience method for issueAccessTokenWithResponse + RequestOptions requestOptions = new RequestOptions(); + return issueAccessTokenWithResponse(id, BinaryData.fromObject(body), requestOptions).getValue() + .toObject(CommunicationIdentityAccessToken.class); + } +} diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/IdentityServiceVersion.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/IdentityServiceVersion.java new file mode 100644 index 0000000000000..61349939c6f64 --- /dev/null +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/IdentityServiceVersion.java @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.communication.identity; + +import com.azure.core.util.ServiceVersion; + +/** + * Service version of IdentityClient. + */ +public enum IdentityServiceVersion implements ServiceVersion { + /** + * Enum value 2025-06-30. + */ + V2025_06_30("2025-06-30"), + + /** + * Enum value 2026-09-23. + */ + V2026_09_23("2026-09-23"); + + private final String version; + + IdentityServiceVersion(String version) { + this.version = version; + } + + /** + * {@inheritDoc} + */ + @Override + public String getVersion() { + return this.version; + } + + /** + * Gets the latest service version supported by this client library. + * + * @return The latest {@link IdentityServiceVersion}. + */ + public static IdentityServiceVersion getLatest() { + return V2026_09_23; + } +} diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/TeamsExtensionOperationsAsyncClient.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/TeamsExtensionOperationsAsyncClient.java new file mode 100644 index 0000000000000..5606a17792286 --- /dev/null +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/TeamsExtensionOperationsAsyncClient.java @@ -0,0 +1,277 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.communication.identity; + +import com.azure.communication.identity.implementation.TeamsExtensionOperationsImpl; +import com.azure.communication.identity.implementation.models.CommunicationIdentityAccessTokenResult; +import com.azure.communication.identity.implementation.models.TeamsExtensionAssignmentCreateOrUpdateRequest; +import com.azure.communication.identity.implementation.models.TeamsExtensionAssignmentResponse; +import com.azure.communication.identity.implementation.models.TeamsExtensionExchangeTokenRequest; +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.core.util.FluxUtil; +import reactor.core.publisher.Mono; + +/** + * Initializes a new instance of the asynchronous IdentityClient type. + */ +@ServiceClient(builder = IdentityClientBuilder.class, isAsync = true) +public final class TeamsExtensionOperationsAsyncClient { + + @Generated + private final TeamsExtensionOperationsImpl serviceClient; + + /** + * Initializes an instance of TeamsExtensionOperationsAsyncClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + TeamsExtensionOperationsAsyncClient(TeamsExtensionOperationsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * Exchanges a Teams Phone token for an ACS user access token. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *      (Optional): {
+     *         String: BinaryData (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     identity (Required): {
+     *         id: String (Required)
+     *     }
+     *     accessToken (Optional): {
+     *         token: String (Required)
+     *         expiresOn: OffsetDateTime (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param body Request payload for the token exchange. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a communication identity with access token along with {@link Response} on successful completion of + * {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Mono> exchangeTokenWithResponse(BinaryData body, RequestOptions requestOptions) { + return this.serviceClient.exchangeTokenWithResponseAsync(body, requestOptions); + } + + /** + * Get Teams Phone access assignment by object id. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     objectId: String (Required)
+     *     tenantId: String (Required)
+     *     principalType: String(resourceAccount/user) (Required)
+     *     clientIds (Optional): [
+     *         String (Optional)
+     *     ]
+     * }
+     * }
+     * 
+ * + * @param tenantId Tenant Id we want to get the assignment for. + * @param objectId Object Id we want to get the assignment for. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return teams Phone access assignment by object id along with {@link Response} on successful completion of + * {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Mono> getAssignmentWithResponse(String tenantId, String objectId, + RequestOptions requestOptions) { + return this.serviceClient.getAssignmentWithResponseAsync(tenantId, objectId, requestOptions); + } + + /** + * Creates or replaces a Teams Phone access assignment. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     principalType: String(resourceAccount/user) (Required)
+     *     clientIds (Optional): [
+     *         String (Optional)
+     *     ]
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     objectId: String (Required)
+     *     tenantId: String (Required)
+     *     principalType: String(resourceAccount/user) (Required)
+     *     clientIds (Optional): [
+     *         String (Optional)
+     *     ]
+     * }
+     * }
+     * 
+ * + * @param tenantId Tenant Id we want to update the assignment for. + * @param objectId Object Id we want to update the assignment for. + * @param body Values we want to set. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a Teams Extension assignment response along with {@link Response} on successful completion of + * {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Mono> upsertAssignmentWithResponse(String tenantId, String objectId, BinaryData body, + RequestOptions requestOptions) { + return this.serviceClient.upsertAssignmentWithResponseAsync(tenantId, objectId, body, requestOptions); + } + + /** + * Removes a Teams Phone access assignment. + * + * @param tenantId Tenant Id we want to remove the assignment for. + * @param objectId Object Id we want to remove the assignment for. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Mono> deleteAssignmentWithResponse(String tenantId, String objectId, RequestOptions requestOptions) { + return this.serviceClient.deleteAssignmentWithResponseAsync(tenantId, objectId, requestOptions); + } + + /** + * Exchanges a Teams Phone token for an ACS user access token. + * + * @param body Request payload for the token exchange. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a communication identity with access token on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Mono exchangeToken(TeamsExtensionExchangeTokenRequest body) { + // Generated convenience method for exchangeTokenWithResponse + RequestOptions requestOptions = new RequestOptions(); + return exchangeTokenWithResponse(BinaryData.fromObject(body), requestOptions).flatMap(FluxUtil::toMono) + .map(protocolMethodData -> protocolMethodData.toObject(CommunicationIdentityAccessTokenResult.class)); + } + + /** + * Get Teams Phone access assignment by object id. + * + * @param tenantId Tenant Id we want to get the assignment for. + * @param objectId Object Id we want to get the assignment for. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return teams Phone access assignment by object id on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Mono getAssignment(String tenantId, String objectId) { + // Generated convenience method for getAssignmentWithResponse + RequestOptions requestOptions = new RequestOptions(); + return getAssignmentWithResponse(tenantId, objectId, requestOptions).flatMap(FluxUtil::toMono) + .map(protocolMethodData -> protocolMethodData.toObject(TeamsExtensionAssignmentResponse.class)); + } + + /** + * Creates or replaces a Teams Phone access assignment. + * + * @param tenantId Tenant Id we want to update the assignment for. + * @param objectId Object Id we want to update the assignment for. + * @param body Values we want to set. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a Teams Extension assignment response on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Mono upsertAssignment(String tenantId, String objectId, + TeamsExtensionAssignmentCreateOrUpdateRequest body) { + // Generated convenience method for upsertAssignmentWithResponse + RequestOptions requestOptions = new RequestOptions(); + return upsertAssignmentWithResponse(tenantId, objectId, BinaryData.fromObject(body), requestOptions) + .flatMap(FluxUtil::toMono) + .map(protocolMethodData -> protocolMethodData.toObject(TeamsExtensionAssignmentResponse.class)); + } + + /** + * Removes a Teams Phone access assignment. + * + * @param tenantId Tenant Id we want to remove the assignment for. + * @param objectId Object Id we want to remove the assignment for. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return A {@link Mono} that completes when a successful response is received. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Mono deleteAssignment(String tenantId, String objectId) { + // Generated convenience method for deleteAssignmentWithResponse + RequestOptions requestOptions = new RequestOptions(); + return deleteAssignmentWithResponse(tenantId, objectId, requestOptions).flatMap(FluxUtil::toMono); + } +} diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/TeamsExtensionOperationsClient.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/TeamsExtensionOperationsClient.java new file mode 100644 index 0000000000000..da21c1ba39c2c --- /dev/null +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/TeamsExtensionOperationsClient.java @@ -0,0 +1,269 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.communication.identity; + +import com.azure.communication.identity.implementation.TeamsExtensionOperationsImpl; +import com.azure.communication.identity.implementation.models.CommunicationIdentityAccessTokenResult; +import com.azure.communication.identity.implementation.models.TeamsExtensionAssignmentCreateOrUpdateRequest; +import com.azure.communication.identity.implementation.models.TeamsExtensionAssignmentResponse; +import com.azure.communication.identity.implementation.models.TeamsExtensionExchangeTokenRequest; +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; + +/** + * Initializes a new instance of the synchronous IdentityClient type. + */ +@ServiceClient(builder = IdentityClientBuilder.class) +public final class TeamsExtensionOperationsClient { + + @Generated + private final TeamsExtensionOperationsImpl serviceClient; + + /** + * Initializes an instance of TeamsExtensionOperationsClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + TeamsExtensionOperationsClient(TeamsExtensionOperationsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * Exchanges a Teams Phone token for an ACS user access token. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *      (Optional): {
+     *         String: BinaryData (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     identity (Required): {
+     *         id: String (Required)
+     *     }
+     *     accessToken (Optional): {
+     *         token: String (Required)
+     *         expiresOn: OffsetDateTime (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param body Request payload for the token exchange. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a communication identity with access token along with {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Response exchangeTokenWithResponse(BinaryData body, RequestOptions requestOptions) { + return this.serviceClient.exchangeTokenWithResponse(body, requestOptions); + } + + /** + * Get Teams Phone access assignment by object id. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     objectId: String (Required)
+     *     tenantId: String (Required)
+     *     principalType: String(resourceAccount/user) (Required)
+     *     clientIds (Optional): [
+     *         String (Optional)
+     *     ]
+     * }
+     * }
+     * 
+ * + * @param tenantId Tenant Id we want to get the assignment for. + * @param objectId Object Id we want to get the assignment for. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return teams Phone access assignment by object id along with {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Response getAssignmentWithResponse(String tenantId, String objectId, RequestOptions requestOptions) { + return this.serviceClient.getAssignmentWithResponse(tenantId, objectId, requestOptions); + } + + /** + * Creates or replaces a Teams Phone access assignment. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     principalType: String(resourceAccount/user) (Required)
+     *     clientIds (Optional): [
+     *         String (Optional)
+     *     ]
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     objectId: String (Required)
+     *     tenantId: String (Required)
+     *     principalType: String(resourceAccount/user) (Required)
+     *     clientIds (Optional): [
+     *         String (Optional)
+     *     ]
+     * }
+     * }
+     * 
+ * + * @param tenantId Tenant Id we want to update the assignment for. + * @param objectId Object Id we want to update the assignment for. + * @param body Values we want to set. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a Teams Extension assignment response along with {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Response upsertAssignmentWithResponse(String tenantId, String objectId, BinaryData body, + RequestOptions requestOptions) { + return this.serviceClient.upsertAssignmentWithResponse(tenantId, objectId, body, requestOptions); + } + + /** + * Removes a Teams Phone access assignment. + * + * @param tenantId Tenant Id we want to remove the assignment for. + * @param objectId Object Id we want to remove the assignment for. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Response deleteAssignmentWithResponse(String tenantId, String objectId, RequestOptions requestOptions) { + return this.serviceClient.deleteAssignmentWithResponse(tenantId, objectId, requestOptions); + } + + /** + * Exchanges a Teams Phone token for an ACS user access token. + * + * @param body Request payload for the token exchange. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a communication identity with access token. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + CommunicationIdentityAccessTokenResult exchangeToken(TeamsExtensionExchangeTokenRequest body) { + // Generated convenience method for exchangeTokenWithResponse + RequestOptions requestOptions = new RequestOptions(); + return exchangeTokenWithResponse(BinaryData.fromObject(body), requestOptions).getValue() + .toObject(CommunicationIdentityAccessTokenResult.class); + } + + /** + * Get Teams Phone access assignment by object id. + * + * @param tenantId Tenant Id we want to get the assignment for. + * @param objectId Object Id we want to get the assignment for. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return teams Phone access assignment by object id. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + TeamsExtensionAssignmentResponse getAssignment(String tenantId, String objectId) { + // Generated convenience method for getAssignmentWithResponse + RequestOptions requestOptions = new RequestOptions(); + return getAssignmentWithResponse(tenantId, objectId, requestOptions).getValue() + .toObject(TeamsExtensionAssignmentResponse.class); + } + + /** + * Creates or replaces a Teams Phone access assignment. + * + * @param tenantId Tenant Id we want to update the assignment for. + * @param objectId Object Id we want to update the assignment for. + * @param body Values we want to set. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a Teams Extension assignment response. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + TeamsExtensionAssignmentResponse upsertAssignment(String tenantId, String objectId, + TeamsExtensionAssignmentCreateOrUpdateRequest body) { + // Generated convenience method for upsertAssignmentWithResponse + RequestOptions requestOptions = new RequestOptions(); + return upsertAssignmentWithResponse(tenantId, objectId, BinaryData.fromObject(body), requestOptions).getValue() + .toObject(TeamsExtensionAssignmentResponse.class); + } + + /** + * Removes a Teams Phone access assignment. + * + * @param tenantId Tenant Id we want to remove the assignment for. + * @param objectId Object Id we want to remove the assignment for. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + void deleteAssignment(String tenantId, String objectId) { + // Generated convenience method for deleteAssignmentWithResponse + RequestOptions requestOptions = new RequestOptions(); + deleteAssignmentWithResponse(tenantId, objectId, requestOptions).getValue(); + } +} diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/TeamsUserOperationsAsyncClient.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/TeamsUserOperationsAsyncClient.java new file mode 100644 index 0000000000000..e016f32c70b3e --- /dev/null +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/TeamsUserOperationsAsyncClient.java @@ -0,0 +1,105 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.communication.identity; + +import com.azure.communication.identity.implementation.TeamsUserOperationsImpl; +import com.azure.communication.identity.implementation.models.CommunicationIdentityAccessToken; +import com.azure.communication.identity.models.GetTokenForTeamsUserOptions; +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.core.util.FluxUtil; +import reactor.core.publisher.Mono; + +/** + * Initializes a new instance of the asynchronous IdentityClient type. + */ +@ServiceClient(builder = IdentityClientBuilder.class, isAsync = true) +public final class TeamsUserOperationsAsyncClient { + + @Generated + private final TeamsUserOperationsImpl serviceClient; + + /** + * Initializes an instance of TeamsUserOperationsAsyncClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + TeamsUserOperationsAsyncClient(TeamsUserOperationsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * Exchange an Entra ID access token of a Teams user for a new Communication Identity access token with a matching + * expiration time. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     token: String (Required)
+     *     appId: String (Required)
+     *     userId: String (Required)
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     token: String (Required)
+     *     expiresOn: OffsetDateTime (Required)
+     * }
+     * }
+     * 
+ * + * @param body Request payload for the token exchange. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return an access token along with {@link Response} on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Mono> exchangeTeamsUserAccessTokenWithResponse(BinaryData body, + RequestOptions requestOptions) { + return this.serviceClient.exchangeTeamsUserAccessTokenWithResponseAsync(body, requestOptions); + } + + /** + * Exchange an Entra ID access token of a Teams user for a new Communication Identity access token with a matching + * expiration time. + * + * @param body Request payload for the token exchange. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return an access token on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Mono exchangeTeamsUserAccessToken(GetTokenForTeamsUserOptions body) { + // Generated convenience method for exchangeTeamsUserAccessTokenWithResponse + RequestOptions requestOptions = new RequestOptions(); + return exchangeTeamsUserAccessTokenWithResponse(BinaryData.fromObject(body), requestOptions) + .flatMap(FluxUtil::toMono) + .map(protocolMethodData -> protocolMethodData.toObject(CommunicationIdentityAccessToken.class)); + } +} diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/TeamsUserOperationsClient.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/TeamsUserOperationsClient.java new file mode 100644 index 0000000000000..8ece9171e5bc4 --- /dev/null +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/TeamsUserOperationsClient.java @@ -0,0 +1,101 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.communication.identity; + +import com.azure.communication.identity.implementation.TeamsUserOperationsImpl; +import com.azure.communication.identity.implementation.models.CommunicationIdentityAccessToken; +import com.azure.communication.identity.models.GetTokenForTeamsUserOptions; +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; + +/** + * Initializes a new instance of the synchronous IdentityClient type. + */ +@ServiceClient(builder = IdentityClientBuilder.class) +public final class TeamsUserOperationsClient { + + @Generated + private final TeamsUserOperationsImpl serviceClient; + + /** + * Initializes an instance of TeamsUserOperationsClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + TeamsUserOperationsClient(TeamsUserOperationsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * Exchange an Entra ID access token of a Teams user for a new Communication Identity access token with a matching + * expiration time. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     token: String (Required)
+     *     appId: String (Required)
+     *     userId: String (Required)
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     token: String (Required)
+     *     expiresOn: OffsetDateTime (Required)
+     * }
+     * }
+     * 
+ * + * @param body Request payload for the token exchange. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return an access token along with {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + Response exchangeTeamsUserAccessTokenWithResponse(BinaryData body, RequestOptions requestOptions) { + return this.serviceClient.exchangeTeamsUserAccessTokenWithResponse(body, requestOptions); + } + + /** + * Exchange an Entra ID access token of a Teams user for a new Communication Identity access token with a matching + * expiration time. + * + * @param body Request payload for the token exchange. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return an access token. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + CommunicationIdentityAccessToken exchangeTeamsUserAccessToken(GetTokenForTeamsUserOptions body) { + // Generated convenience method for exchangeTeamsUserAccessTokenWithResponse + RequestOptions requestOptions = new RequestOptions(); + return exchangeTeamsUserAccessTokenWithResponse(BinaryData.fromObject(body), requestOptions).getValue() + .toObject(CommunicationIdentityAccessToken.class); + } +} diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/CommunicationIdentitiesImpl.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/CommunicationIdentitiesImpl.java deleted file mode 100644 index 435653819b7fd..0000000000000 --- a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/CommunicationIdentitiesImpl.java +++ /dev/null @@ -1,618 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.communication.identity.implementation; - -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.models.GetTokenForTeamsUserOptions; -import com.azure.core.annotation.BodyParam; -import com.azure.core.annotation.Delete; -import com.azure.core.annotation.ExpectedResponses; -import com.azure.core.annotation.HeaderParam; -import com.azure.core.annotation.Host; -import com.azure.core.annotation.HostParam; -import com.azure.core.annotation.PathParam; -import com.azure.core.annotation.Post; -import com.azure.core.annotation.QueryParam; -import com.azure.core.annotation.ReturnType; -import com.azure.core.annotation.ServiceInterface; -import com.azure.core.annotation.ServiceMethod; -import com.azure.core.annotation.UnexpectedResponseExceptionType; -import com.azure.core.http.rest.Response; -import com.azure.core.http.rest.RestProxy; -import com.azure.core.util.Context; -import com.azure.core.util.FluxUtil; -import reactor.core.publisher.Mono; - -/** - * An instance of this class provides access to all the operations defined in CommunicationIdentities. - */ -public final class CommunicationIdentitiesImpl { - /** - * The proxy service used to perform REST calls. - */ - private final CommunicationIdentitiesService service; - - /** - * The service client containing this operation class. - */ - private final CommunicationIdentityClientImpl client; - - /** - * Initializes an instance of CommunicationIdentitiesImpl. - * - * @param client the instance of the service client containing this operation class. - */ - CommunicationIdentitiesImpl(CommunicationIdentityClientImpl client) { - this.service = RestProxy.create(CommunicationIdentitiesService.class, client.getHttpPipeline(), - client.getSerializerAdapter()); - this.client = client; - } - - /** - * The interface defining all the services for CommunicationIdentityClientCommunicationIdentities to be used by the - * proxy service to perform REST calls. - */ - @Host("{endpoint}") - @ServiceInterface(name = "CommunicationIdentityClientCommunicationIdentities") - public interface CommunicationIdentitiesService { - @Post("/identities") - @ExpectedResponses({ 201 }) - @UnexpectedResponseExceptionType(CommunicationErrorResponseException.class) - Mono> create(@HostParam("endpoint") String endpoint, - @QueryParam("api-version") String apiVersion, - @BodyParam("application/json") CommunicationIdentityCreateRequest body, - @HeaderParam("Accept") String accept, Context context); - - @Post("/identities") - @ExpectedResponses({ 201 }) - @UnexpectedResponseExceptionType(CommunicationErrorResponseException.class) - Response createSync(@HostParam("endpoint") String endpoint, - @QueryParam("api-version") String apiVersion, - @BodyParam("application/json") CommunicationIdentityCreateRequest body, - @HeaderParam("Accept") String accept, Context context); - - @Delete("/identities/{id}") - @ExpectedResponses({ 204 }) - @UnexpectedResponseExceptionType(CommunicationErrorResponseException.class) - Mono> delete(@HostParam("endpoint") String endpoint, @PathParam("id") String id, - @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, Context context); - - @Delete("/identities/{id}") - @ExpectedResponses({ 204 }) - @UnexpectedResponseExceptionType(CommunicationErrorResponseException.class) - Response deleteSync(@HostParam("endpoint") String endpoint, @PathParam("id") String id, - @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, Context context); - - @Post("/identities/{id}/:revokeAccessTokens") - @ExpectedResponses({ 204 }) - @UnexpectedResponseExceptionType(CommunicationErrorResponseException.class) - Mono> revokeAccessTokens(@HostParam("endpoint") String endpoint, @PathParam("id") String id, - @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, Context context); - - @Post("/identities/{id}/:revokeAccessTokens") - @ExpectedResponses({ 204 }) - @UnexpectedResponseExceptionType(CommunicationErrorResponseException.class) - Response revokeAccessTokensSync(@HostParam("endpoint") String endpoint, @PathParam("id") String id, - @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, Context context); - - @Post("/teamsUser/:exchangeAccessToken") - @ExpectedResponses({ 200 }) - @UnexpectedResponseExceptionType(CommunicationErrorResponseException.class) - Mono> exchangeTeamsUserAccessToken( - @HostParam("endpoint") String endpoint, @QueryParam("api-version") String apiVersion, - @BodyParam("application/json") GetTokenForTeamsUserOptions body, @HeaderParam("Accept") String accept, - Context context); - - @Post("/teamsUser/:exchangeAccessToken") - @ExpectedResponses({ 200 }) - @UnexpectedResponseExceptionType(CommunicationErrorResponseException.class) - Response exchangeTeamsUserAccessTokenSync( - @HostParam("endpoint") String endpoint, @QueryParam("api-version") String apiVersion, - @BodyParam("application/json") GetTokenForTeamsUserOptions body, @HeaderParam("Accept") String accept, - Context context); - - @Post("/identities/{id}/:issueAccessToken") - @ExpectedResponses({ 200 }) - @UnexpectedResponseExceptionType(CommunicationErrorResponseException.class) - Mono> issueAccessToken(@HostParam("endpoint") String endpoint, - @PathParam("id") String id, @QueryParam("api-version") String apiVersion, - @BodyParam("application/json") CommunicationIdentityAccessTokenRequest body, - @HeaderParam("Accept") String accept, Context context); - - @Post("/identities/{id}/:issueAccessToken") - @ExpectedResponses({ 200 }) - @UnexpectedResponseExceptionType(CommunicationErrorResponseException.class) - Response issueAccessTokenSync(@HostParam("endpoint") String endpoint, - @PathParam("id") String id, @QueryParam("api-version") String apiVersion, - @BodyParam("application/json") CommunicationIdentityAccessTokenRequest body, - @HeaderParam("Accept") String accept, Context context); - } - - /** - * Create a new identity, and optionally, an access token. - * - * @param body If specified, creates also a Communication Identity access token associated with the identity and - * containing the requested scopes. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return a communication identity with access token along with {@link Response} on successful completion of - * {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> - createWithResponseAsync(CommunicationIdentityCreateRequest body) { - return FluxUtil.withContext(context -> createWithResponseAsync(body, context)); - } - - /** - * Create a new identity, and optionally, an access token. - * - * @param body If specified, creates also a Communication Identity access token associated with the identity and - * containing the requested scopes. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return a communication identity with access token along with {@link Response} on successful completion of - * {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> - createWithResponseAsync(CommunicationIdentityCreateRequest body, Context context) { - final String accept = "application/json"; - return service.create(this.client.getEndpoint(), this.client.getApiVersion(), body, accept, context); - } - - /** - * Create a new identity, and optionally, an access token. - * - * @param body If specified, creates also a Communication Identity access token associated with the identity and - * containing the requested scopes. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return a communication identity with access token on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono createAsync(CommunicationIdentityCreateRequest body) { - return createWithResponseAsync(body).flatMap(res -> Mono.justOrEmpty(res.getValue())); - } - - /** - * Create a new identity, and optionally, an access token. - * - * @param body If specified, creates also a Communication Identity access token associated with the identity and - * containing the requested scopes. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return a communication identity with access token on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono createAsync(CommunicationIdentityCreateRequest body, - Context context) { - return createWithResponseAsync(body, context).flatMap(res -> Mono.justOrEmpty(res.getValue())); - } - - /** - * Create a new identity, and optionally, an access token. - * - * @param body If specified, creates also a Communication Identity access token associated with the identity and - * containing the requested scopes. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return a communication identity with access token along with {@link Response}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Response createWithResponse(CommunicationIdentityCreateRequest body, - Context context) { - final String accept = "application/json"; - return service.createSync(this.client.getEndpoint(), this.client.getApiVersion(), body, accept, context); - } - - /** - * Create a new identity, and optionally, an access token. - * - * @param body If specified, creates also a Communication Identity access token associated with the identity and - * containing the requested scopes. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return a communication identity with access token. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public CommunicationIdentityAccessTokenResult create(CommunicationIdentityCreateRequest body) { - return createWithResponse(body, Context.NONE).getValue(); - } - - /** - * Delete the identity, revoke all tokens for the identity and delete all associated data. - * - * @param id Identifier of the identity to be deleted. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the {@link Response} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> deleteWithResponseAsync(String id) { - return FluxUtil.withContext(context -> deleteWithResponseAsync(id, context)); - } - - /** - * Delete the identity, revoke all tokens for the identity and delete all associated data. - * - * @param id Identifier of the identity to be deleted. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the {@link Response} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> deleteWithResponseAsync(String id, Context context) { - final String accept = "application/json"; - return service.delete(this.client.getEndpoint(), id, this.client.getApiVersion(), accept, context); - } - - /** - * Delete the identity, revoke all tokens for the identity and delete all associated data. - * - * @param id Identifier of the identity to be deleted. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return A {@link Mono} that completes when a successful response is received. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono deleteAsync(String id) { - return deleteWithResponseAsync(id).flatMap(ignored -> Mono.empty()); - } - - /** - * Delete the identity, revoke all tokens for the identity and delete all associated data. - * - * @param id Identifier of the identity to be deleted. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return A {@link Mono} that completes when a successful response is received. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono deleteAsync(String id, Context context) { - return deleteWithResponseAsync(id, context).flatMap(ignored -> Mono.empty()); - } - - /** - * Delete the identity, revoke all tokens for the identity and delete all associated data. - * - * @param id Identifier of the identity to be deleted. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the {@link Response}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Response deleteWithResponse(String id, Context context) { - final String accept = "application/json"; - return service.deleteSync(this.client.getEndpoint(), id, this.client.getApiVersion(), accept, context); - } - - /** - * Delete the identity, revoke all tokens for the identity and delete all associated data. - * - * @param id Identifier of the identity to be deleted. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public void delete(String id) { - deleteWithResponse(id, Context.NONE); - } - - /** - * Revoke all access tokens for the specific identity. - * - * @param id Identifier of the identity. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the {@link Response} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> revokeAccessTokensWithResponseAsync(String id) { - return FluxUtil.withContext(context -> revokeAccessTokensWithResponseAsync(id, context)); - } - - /** - * Revoke all access tokens for the specific identity. - * - * @param id Identifier of the identity. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the {@link Response} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> revokeAccessTokensWithResponseAsync(String id, Context context) { - final String accept = "application/json"; - return service.revokeAccessTokens(this.client.getEndpoint(), id, this.client.getApiVersion(), accept, context); - } - - /** - * Revoke all access tokens for the specific identity. - * - * @param id Identifier of the identity. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return A {@link Mono} that completes when a successful response is received. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono revokeAccessTokensAsync(String id) { - return revokeAccessTokensWithResponseAsync(id).flatMap(ignored -> Mono.empty()); - } - - /** - * Revoke all access tokens for the specific identity. - * - * @param id Identifier of the identity. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return A {@link Mono} that completes when a successful response is received. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono revokeAccessTokensAsync(String id, Context context) { - return revokeAccessTokensWithResponseAsync(id, context).flatMap(ignored -> Mono.empty()); - } - - /** - * Revoke all access tokens for the specific identity. - * - * @param id Identifier of the identity. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the {@link Response}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Response revokeAccessTokensWithResponse(String id, Context context) { - final String accept = "application/json"; - return service.revokeAccessTokensSync(this.client.getEndpoint(), id, this.client.getApiVersion(), accept, - context); - } - - /** - * Revoke all access tokens for the specific identity. - * - * @param id Identifier of the identity. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public void revokeAccessTokens(String id) { - revokeAccessTokensWithResponse(id, Context.NONE); - } - - /** - * Exchange an Azure Active Directory (Azure AD) access token of a Teams user for a new Communication Identity - * access token with a matching expiration time. - * - * @param body Request payload for the token exchange. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return an access token along with {@link Response} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> - exchangeTeamsUserAccessTokenWithResponseAsync(GetTokenForTeamsUserOptions body) { - return FluxUtil.withContext(context -> exchangeTeamsUserAccessTokenWithResponseAsync(body, context)); - } - - /** - * Exchange an Azure Active Directory (Azure AD) access token of a Teams user for a new Communication Identity - * access token with a matching expiration time. - * - * @param body Request payload for the token exchange. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return an access token along with {@link Response} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> - exchangeTeamsUserAccessTokenWithResponseAsync(GetTokenForTeamsUserOptions body, Context context) { - final String accept = "application/json"; - return service.exchangeTeamsUserAccessToken(this.client.getEndpoint(), this.client.getApiVersion(), body, - accept, context); - } - - /** - * Exchange an Azure Active Directory (Azure AD) access token of a Teams user for a new Communication Identity - * access token with a matching expiration time. - * - * @param body Request payload for the token exchange. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return an access token on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono exchangeTeamsUserAccessTokenAsync(GetTokenForTeamsUserOptions body) { - return exchangeTeamsUserAccessTokenWithResponseAsync(body).flatMap(res -> Mono.justOrEmpty(res.getValue())); - } - - /** - * Exchange an Azure Active Directory (Azure AD) access token of a Teams user for a new Communication Identity - * access token with a matching expiration time. - * - * @param body Request payload for the token exchange. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return an access token on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono exchangeTeamsUserAccessTokenAsync(GetTokenForTeamsUserOptions body, - Context context) { - return exchangeTeamsUserAccessTokenWithResponseAsync(body, context) - .flatMap(res -> Mono.justOrEmpty(res.getValue())); - } - - /** - * Exchange an Azure Active Directory (Azure AD) access token of a Teams user for a new Communication Identity - * access token with a matching expiration time. - * - * @param body Request payload for the token exchange. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return an access token along with {@link Response}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Response - exchangeTeamsUserAccessTokenWithResponse(GetTokenForTeamsUserOptions body, Context context) { - final String accept = "application/json"; - return service.exchangeTeamsUserAccessTokenSync(this.client.getEndpoint(), this.client.getApiVersion(), body, - accept, context); - } - - /** - * Exchange an Azure Active Directory (Azure AD) access token of a Teams user for a new Communication Identity - * access token with a matching expiration time. - * - * @param body Request payload for the token exchange. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return an access token. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public CommunicationIdentityAccessToken exchangeTeamsUserAccessToken(GetTokenForTeamsUserOptions body) { - return exchangeTeamsUserAccessTokenWithResponse(body, Context.NONE).getValue(); - } - - /** - * Issue a new token for an identity. - * - * @param id Identifier of the identity to issue token for. - * @param body Requested scopes for the new token. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return an access token along with {@link Response} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> issueAccessTokenWithResponseAsync(String id, - CommunicationIdentityAccessTokenRequest body) { - return FluxUtil.withContext(context -> issueAccessTokenWithResponseAsync(id, body, context)); - } - - /** - * Issue a new token for an identity. - * - * @param id Identifier of the identity to issue token for. - * @param body Requested scopes for the new token. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return an access token along with {@link Response} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> issueAccessTokenWithResponseAsync(String id, - CommunicationIdentityAccessTokenRequest body, Context context) { - final String accept = "application/json"; - return service.issueAccessToken(this.client.getEndpoint(), id, this.client.getApiVersion(), body, accept, - context); - } - - /** - * Issue a new token for an identity. - * - * @param id Identifier of the identity to issue token for. - * @param body Requested scopes for the new token. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return an access token on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono issueAccessTokenAsync(String id, - CommunicationIdentityAccessTokenRequest body) { - return issueAccessTokenWithResponseAsync(id, body).flatMap(res -> Mono.justOrEmpty(res.getValue())); - } - - /** - * Issue a new token for an identity. - * - * @param id Identifier of the identity to issue token for. - * @param body Requested scopes for the new token. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return an access token on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono issueAccessTokenAsync(String id, - CommunicationIdentityAccessTokenRequest body, Context context) { - return issueAccessTokenWithResponseAsync(id, body, context).flatMap(res -> Mono.justOrEmpty(res.getValue())); - } - - /** - * Issue a new token for an identity. - * - * @param id Identifier of the identity to issue token for. - * @param body Requested scopes for the new token. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return an access token along with {@link Response}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Response issueAccessTokenWithResponse(String id, - CommunicationIdentityAccessTokenRequest body, Context context) { - final String accept = "application/json"; - return service.issueAccessTokenSync(this.client.getEndpoint(), id, this.client.getApiVersion(), body, accept, - context); - } - - /** - * Issue a new token for an identity. - * - * @param id Identifier of the identity to issue token for. - * @param body Requested scopes for the new token. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return an access token. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public CommunicationIdentityAccessToken issueAccessToken(String id, CommunicationIdentityAccessTokenRequest body) { - return issueAccessTokenWithResponse(id, body, Context.NONE).getValue(); - } -} diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/CommunicationIdentityClientImpl.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/CommunicationIdentityClientImpl.java deleted file mode 100644 index d5fd7a8c2fdcc..0000000000000 --- a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/CommunicationIdentityClientImpl.java +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.communication.identity.implementation; - -import com.azure.core.http.HttpPipeline; -import com.azure.core.http.HttpPipelineBuilder; -import com.azure.core.http.policy.RetryPolicy; -import com.azure.core.http.policy.UserAgentPolicy; -import com.azure.core.util.serializer.JacksonAdapter; -import com.azure.core.util.serializer.SerializerAdapter; - -/** - * Initializes a new instance of the CommunicationIdentityClient type. - */ -public final class CommunicationIdentityClientImpl { - /** - * The communication resource, for example https://my-resource.communication.azure.com. - */ - private final String endpoint; - - /** - * Gets The communication resource, for example https://my-resource.communication.azure.com. - * - * @return the endpoint value. - */ - public String getEndpoint() { - return this.endpoint; - } - - /** - * Api Version. - */ - private final String apiVersion; - - /** - * Gets Api Version. - * - * @return the apiVersion value. - */ - public String getApiVersion() { - return this.apiVersion; - } - - /** - * The HTTP pipeline to send requests through. - */ - private final HttpPipeline httpPipeline; - - /** - * Gets The HTTP pipeline to send requests through. - * - * @return the httpPipeline value. - */ - public HttpPipeline getHttpPipeline() { - return this.httpPipeline; - } - - /** - * The serializer to serialize an object into a string. - */ - private final SerializerAdapter serializerAdapter; - - /** - * Gets The serializer to serialize an object into a string. - * - * @return the serializerAdapter value. - */ - public SerializerAdapter getSerializerAdapter() { - return this.serializerAdapter; - } - - /** - * The CommunicationIdentitiesImpl object to access its operations. - */ - private final CommunicationIdentitiesImpl communicationIdentities; - - /** - * Gets the CommunicationIdentitiesImpl object to access its operations. - * - * @return the CommunicationIdentitiesImpl object. - */ - public CommunicationIdentitiesImpl getCommunicationIdentities() { - return this.communicationIdentities; - } - - /** - * Initializes an instance of CommunicationIdentityClient client. - * - * @param endpoint The communication resource, for example https://my-resource.communication.azure.com. - * @param apiVersion Api Version. - */ - public CommunicationIdentityClientImpl(String endpoint, String apiVersion) { - this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(), - JacksonAdapter.createDefaultSerializerAdapter(), endpoint, apiVersion); - } - - /** - * Initializes an instance of CommunicationIdentityClient client. - * - * @param httpPipeline The HTTP pipeline to send requests through. - * @param endpoint The communication resource, for example https://my-resource.communication.azure.com. - * @param apiVersion Api Version. - */ - public CommunicationIdentityClientImpl(HttpPipeline httpPipeline, String endpoint, String apiVersion) { - this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint, apiVersion); - } - - /** - * Initializes an instance of CommunicationIdentityClient client. - * - * @param httpPipeline The HTTP pipeline to send requests through. - * @param serializerAdapter The serializer to serialize an object into a string. - * @param endpoint The communication resource, for example https://my-resource.communication.azure.com. - * @param apiVersion Api Version. - */ - public CommunicationIdentityClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, - String endpoint, String apiVersion) { - this.httpPipeline = httpPipeline; - this.serializerAdapter = serializerAdapter; - this.endpoint = endpoint; - this.apiVersion = apiVersion; - this.communicationIdentities = new CommunicationIdentitiesImpl(this); - } -} diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/IdentityClientImpl.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/IdentityClientImpl.java new file mode 100644 index 0000000000000..56f51a74f6856 --- /dev/null +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/IdentityClientImpl.java @@ -0,0 +1,157 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.communication.identity.implementation; + +import com.azure.communication.identity.IdentityServiceVersion; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.util.serializer.JacksonAdapter; +import com.azure.core.util.serializer.SerializerAdapter; + +/** + * Initializes a new instance of the IdentityClient type. + */ +public final class IdentityClientImpl { + /** + * The communication resource, for example https://my-resource.communication.azure.com. + */ + private final String endpoint; + + /** + * Gets The communication resource, for example https://my-resource.communication.azure.com. + * + * @return the endpoint value. + */ + public String getEndpoint() { + return this.endpoint; + } + + /** + * Service version. + */ + private final IdentityServiceVersion serviceVersion; + + /** + * Gets Service version. + * + * @return the serviceVersion value. + */ + public IdentityServiceVersion getServiceVersion() { + return this.serviceVersion; + } + + /** + * The HTTP pipeline to send requests through. + */ + private final HttpPipeline httpPipeline; + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + public HttpPipeline getHttpPipeline() { + return this.httpPipeline; + } + + /** + * The serializer to serialize an object into a string. + */ + private final SerializerAdapter serializerAdapter; + + /** + * Gets The serializer to serialize an object into a string. + * + * @return the serializerAdapter value. + */ + public SerializerAdapter getSerializerAdapter() { + return this.serializerAdapter; + } + + /** + * The IdentityOperationsImpl object to access its operations. + */ + private final IdentityOperationsImpl identityOperations; + + /** + * Gets the IdentityOperationsImpl object to access its operations. + * + * @return the IdentityOperationsImpl object. + */ + public IdentityOperationsImpl getIdentityOperations() { + return this.identityOperations; + } + + /** + * The TeamsUserOperationsImpl object to access its operations. + */ + private final TeamsUserOperationsImpl teamsUserOperations; + + /** + * Gets the TeamsUserOperationsImpl object to access its operations. + * + * @return the TeamsUserOperationsImpl object. + */ + public TeamsUserOperationsImpl getTeamsUserOperations() { + return this.teamsUserOperations; + } + + /** + * The TeamsExtensionOperationsImpl object to access its operations. + */ + private final TeamsExtensionOperationsImpl teamsExtensionOperations; + + /** + * Gets the TeamsExtensionOperationsImpl object to access its operations. + * + * @return the TeamsExtensionOperationsImpl object. + */ + public TeamsExtensionOperationsImpl getTeamsExtensionOperations() { + return this.teamsExtensionOperations; + } + + /** + * Initializes an instance of IdentityClient client. + * + * @param endpoint The communication resource, for example https://my-resource.communication.azure.com. + * @param serviceVersion Service version. + */ + public IdentityClientImpl(String endpoint, IdentityServiceVersion serviceVersion) { + this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(), + JacksonAdapter.createDefaultSerializerAdapter(), endpoint, serviceVersion); + } + + /** + * Initializes an instance of IdentityClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param endpoint The communication resource, for example https://my-resource.communication.azure.com. + * @param serviceVersion Service version. + */ + public IdentityClientImpl(HttpPipeline httpPipeline, String endpoint, IdentityServiceVersion serviceVersion) { + this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint, serviceVersion); + } + + /** + * Initializes an instance of IdentityClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param serializerAdapter The serializer to serialize an object into a string. + * @param endpoint The communication resource, for example https://my-resource.communication.azure.com. + * @param serviceVersion Service version. + */ + public IdentityClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String endpoint, + IdentityServiceVersion serviceVersion) { + this.httpPipeline = httpPipeline; + this.serializerAdapter = serializerAdapter; + this.endpoint = endpoint; + this.serviceVersion = serviceVersion; + this.identityOperations = new IdentityOperationsImpl(this); + this.teamsUserOperations = new TeamsUserOperationsImpl(this); + this.teamsExtensionOperations = new TeamsExtensionOperationsImpl(this); + } +} diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/IdentityOperationsImpl.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/IdentityOperationsImpl.java new file mode 100644 index 0000000000000..038c60de97ee6 --- /dev/null +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/IdentityOperationsImpl.java @@ -0,0 +1,431 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.communication.identity.implementation; + +import com.azure.communication.identity.IdentityServiceVersion; +import com.azure.core.annotation.BodyParam; +import com.azure.core.annotation.Delete; +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.Post; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.HttpHeaderName; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in IdentityOperations. + */ +public final class IdentityOperationsImpl { + /** + * The proxy service used to perform REST calls. + */ + private final IdentityOperationsService service; + + /** + * The service client containing this operation class. + */ + private final IdentityClientImpl client; + + /** + * Initializes an instance of IdentityOperationsImpl. + * + * @param client the instance of the service client containing this operation class. + */ + IdentityOperationsImpl(IdentityClientImpl client) { + this.service = RestProxy.create(IdentityOperationsService.class, client.getHttpPipeline(), + client.getSerializerAdapter()); + this.client = client; + } + + /** + * Gets Service version. + * + * @return the serviceVersion value. + */ + public IdentityServiceVersion getServiceVersion() { + return client.getServiceVersion(); + } + + /** + * The interface defining all the services for IdentityClientIdentityOperations to be used by the proxy service to + * perform REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "IdentityClientIdentityOperations") + public interface IdentityOperationsService { + @Post("/identities") + @ExpectedResponses({ 201 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> create(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, + RequestOptions requestOptions, Context context); + + @Post("/identities") + @ExpectedResponses({ 201 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response createSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, + RequestOptions requestOptions, Context context); + + @Delete("/identities/{id}") + @ExpectedResponses({ 204 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> delete(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("id") String id, RequestOptions requestOptions, + Context context); + + @Delete("/identities/{id}") + @ExpectedResponses({ 204 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response deleteSync(@HostParam("endpoint") String endpoint, @QueryParam("api-version") String apiVersion, + @PathParam("id") String id, RequestOptions requestOptions, Context context); + + @Post("/identities/{id}/:revokeAccessTokens") + @ExpectedResponses({ 204 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> revokeAccessTokens(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("id") String id, RequestOptions requestOptions, + Context context); + + @Post("/identities/{id}/:revokeAccessTokens") + @ExpectedResponses({ 204 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response revokeAccessTokensSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("id") String id, RequestOptions requestOptions, + Context context); + + @Post("/identities/{id}/:issueAccessToken") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> issueAccessToken(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("id") String id, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") BinaryData body, RequestOptions requestOptions, Context context); + + @Post("/identities/{id}/:issueAccessToken") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response issueAccessTokenSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("id") String id, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") BinaryData body, RequestOptions requestOptions, Context context); + } + + /** + * Create a new identity, and optionally, an access token. + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
Content-TypeStringNoThe content type. Allowed values: + * "application/json".
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     createTokenWithScopes (Optional): [
+     *         String(chat/voip/chat.join/chat.join.limited/voip.join) (Optional)
+     *     ]
+     *     expiresInMinutes: Integer (Optional)
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     identity (Required): {
+     *         id: String (Required)
+     *     }
+     *     accessToken (Optional): {
+     *         token: String (Required)
+     *         expiresOn: OffsetDateTime (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a communication identity with access token along with {@link Response} on successful completion of + * {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> createWithResponseAsync(RequestOptions requestOptions) { + final String accept = "application/json"; + RequestOptions requestOptionsLocal = requestOptions == null ? new RequestOptions() : requestOptions; + requestOptionsLocal.addRequestCallback(requestLocal -> { + if (requestLocal.getBody() != null && requestLocal.getHeaders().get(HttpHeaderName.CONTENT_TYPE) == null) { + requestLocal.getHeaders().set(HttpHeaderName.CONTENT_TYPE, "application/json"); + } + }); + return FluxUtil.withContext(context -> service.create(this.client.getEndpoint(), + this.client.getServiceVersion().getVersion(), accept, requestOptionsLocal, context)); + } + + /** + * Create a new identity, and optionally, an access token. + *

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
Content-TypeStringNoThe content type. Allowed values: + * "application/json".
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     createTokenWithScopes (Optional): [
+     *         String(chat/voip/chat.join/chat.join.limited/voip.join) (Optional)
+     *     ]
+     *     expiresInMinutes: Integer (Optional)
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     identity (Required): {
+     *         id: String (Required)
+     *     }
+     *     accessToken (Optional): {
+     *         token: String (Required)
+     *         expiresOn: OffsetDateTime (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a communication identity with access token along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response createWithResponse(RequestOptions requestOptions) { + final String accept = "application/json"; + RequestOptions requestOptionsLocal = requestOptions == null ? new RequestOptions() : requestOptions; + requestOptionsLocal.addRequestCallback(requestLocal -> { + if (requestLocal.getBody() != null && requestLocal.getHeaders().get(HttpHeaderName.CONTENT_TYPE) == null) { + requestLocal.getHeaders().set(HttpHeaderName.CONTENT_TYPE, "application/json"); + } + }); + return service.createSync(this.client.getEndpoint(), this.client.getServiceVersion().getVersion(), accept, + requestOptionsLocal, Context.NONE); + } + + /** + * Delete the identity, revoke all tokens for the identity and delete all associated data. + * + * @param id Identifier of the identity to be deleted. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> deleteWithResponseAsync(String id, RequestOptions requestOptions) { + return FluxUtil.withContext(context -> service.delete(this.client.getEndpoint(), + this.client.getServiceVersion().getVersion(), id, requestOptions, context)); + } + + /** + * Delete the identity, revoke all tokens for the identity and delete all associated data. + * + * @param id Identifier of the identity to be deleted. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response deleteWithResponse(String id, RequestOptions requestOptions) { + return service.deleteSync(this.client.getEndpoint(), this.client.getServiceVersion().getVersion(), id, + requestOptions, Context.NONE); + } + + /** + * Revoke all access tokens for the specific identity. + * + * @param id Identifier of the identity. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> revokeAccessTokensWithResponseAsync(String id, RequestOptions requestOptions) { + return FluxUtil.withContext(context -> service.revokeAccessTokens(this.client.getEndpoint(), + this.client.getServiceVersion().getVersion(), id, requestOptions, context)); + } + + /** + * Revoke all access tokens for the specific identity. + * + * @param id Identifier of the identity. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response revokeAccessTokensWithResponse(String id, RequestOptions requestOptions) { + return service.revokeAccessTokensSync(this.client.getEndpoint(), this.client.getServiceVersion().getVersion(), + id, requestOptions, Context.NONE); + } + + /** + * Issue a new token for an identity. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     scopes (Required): [
+     *         String(chat/voip/chat.join/chat.join.limited/voip.join) (Required)
+     *     ]
+     *     expiresInMinutes: Integer (Optional)
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     token: String (Required)
+     *     expiresOn: OffsetDateTime (Required)
+     * }
+     * }
+     * 
+ * + * @param id Identifier of the identity to issue token for. + * @param body Requested scopes for the new token. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return an access token along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> issueAccessTokenWithResponseAsync(String id, BinaryData body, + RequestOptions requestOptions) { + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.issueAccessToken(this.client.getEndpoint(), + this.client.getServiceVersion().getVersion(), id, contentType, accept, body, requestOptions, context)); + } + + /** + * Issue a new token for an identity. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     scopes (Required): [
+     *         String(chat/voip/chat.join/chat.join.limited/voip.join) (Required)
+     *     ]
+     *     expiresInMinutes: Integer (Optional)
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     token: String (Required)
+     *     expiresOn: OffsetDateTime (Required)
+     * }
+     * }
+     * 
+ * + * @param id Identifier of the identity to issue token for. + * @param body Requested scopes for the new token. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return an access token along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response issueAccessTokenWithResponse(String id, BinaryData body, + RequestOptions requestOptions) { + final String contentType = "application/json"; + final String accept = "application/json"; + return service.issueAccessTokenSync(this.client.getEndpoint(), this.client.getServiceVersion().getVersion(), id, + contentType, accept, body, requestOptions, Context.NONE); + } +} diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/TeamsExtensionOperationsImpl.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/TeamsExtensionOperationsImpl.java new file mode 100644 index 0000000000000..2df9fc1305f01 --- /dev/null +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/TeamsExtensionOperationsImpl.java @@ -0,0 +1,464 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.communication.identity.implementation; + +import com.azure.communication.identity.IdentityServiceVersion; +import com.azure.core.annotation.BodyParam; +import com.azure.core.annotation.Delete; +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.Post; +import com.azure.core.annotation.Put; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in TeamsExtensionOperations. + */ +public final class TeamsExtensionOperationsImpl { + /** + * The proxy service used to perform REST calls. + */ + private final TeamsExtensionOperationsService service; + + /** + * The service client containing this operation class. + */ + private final IdentityClientImpl client; + + /** + * Initializes an instance of TeamsExtensionOperationsImpl. + * + * @param client the instance of the service client containing this operation class. + */ + TeamsExtensionOperationsImpl(IdentityClientImpl client) { + this.service = RestProxy.create(TeamsExtensionOperationsService.class, client.getHttpPipeline(), + client.getSerializerAdapter()); + this.client = client; + } + + /** + * Gets Service version. + * + * @return the serviceVersion value. + */ + public IdentityServiceVersion getServiceVersion() { + return client.getServiceVersion(); + } + + /** + * The interface defining all the services for IdentityClientTeamsExtensionOperations to be used by the proxy + * service to perform REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "IdentityClientTeamsExtensionOperations") + public interface TeamsExtensionOperationsService { + @Post("/access/teamsExtension/:exchangeAccessToken") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> exchangeToken(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @HeaderParam("Content-Type") String contentType, + @HeaderParam("Accept") String accept, @BodyParam("application/json") BinaryData body, + RequestOptions requestOptions, Context context); + + @Post("/access/teamsExtension/:exchangeAccessToken") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response exchangeTokenSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @HeaderParam("Content-Type") String contentType, + @HeaderParam("Accept") String accept, @BodyParam("application/json") BinaryData body, + RequestOptions requestOptions, Context context); + + @Get("/access/teamsExtension/tenants/{tenantId}/assignments/{objectId}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getAssignment(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("tenantId") String tenantId, + @PathParam("objectId") String objectId, @HeaderParam("Accept") String accept, RequestOptions requestOptions, + Context context); + + @Get("/access/teamsExtension/tenants/{tenantId}/assignments/{objectId}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response getAssignmentSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("tenantId") String tenantId, + @PathParam("objectId") String objectId, @HeaderParam("Accept") String accept, RequestOptions requestOptions, + Context context); + + @Put("/access/teamsExtension/tenants/{tenantId}/assignments/{objectId}") + @ExpectedResponses({ 200, 201 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> upsertAssignment(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("tenantId") String tenantId, + @PathParam("objectId") String objectId, @HeaderParam("Content-Type") String contentType, + @HeaderParam("Accept") String accept, @BodyParam("application/json") BinaryData body, + RequestOptions requestOptions, Context context); + + @Put("/access/teamsExtension/tenants/{tenantId}/assignments/{objectId}") + @ExpectedResponses({ 200, 201 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response upsertAssignmentSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("tenantId") String tenantId, + @PathParam("objectId") String objectId, @HeaderParam("Content-Type") String contentType, + @HeaderParam("Accept") String accept, @BodyParam("application/json") BinaryData body, + RequestOptions requestOptions, Context context); + + @Delete("/access/teamsExtension/tenants/{tenantId}/assignments/{objectId}") + @ExpectedResponses({ 204 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> deleteAssignment(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("tenantId") String tenantId, + @PathParam("objectId") String objectId, RequestOptions requestOptions, Context context); + + @Delete("/access/teamsExtension/tenants/{tenantId}/assignments/{objectId}") + @ExpectedResponses({ 204 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response deleteAssignmentSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("tenantId") String tenantId, + @PathParam("objectId") String objectId, RequestOptions requestOptions, Context context); + } + + /** + * Exchanges a Teams Phone token for an ACS user access token. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *      (Optional): {
+     *         String: BinaryData (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     identity (Required): {
+     *         id: String (Required)
+     *     }
+     *     accessToken (Optional): {
+     *         token: String (Required)
+     *         expiresOn: OffsetDateTime (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param body Request payload for the token exchange. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a communication identity with access token along with {@link Response} on successful completion of + * {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> exchangeTokenWithResponseAsync(BinaryData body, RequestOptions requestOptions) { + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.exchangeToken(this.client.getEndpoint(), + this.client.getServiceVersion().getVersion(), contentType, accept, body, requestOptions, context)); + } + + /** + * Exchanges a Teams Phone token for an ACS user access token. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *      (Optional): {
+     *         String: BinaryData (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     identity (Required): {
+     *         id: String (Required)
+     *     }
+     *     accessToken (Optional): {
+     *         token: String (Required)
+     *         expiresOn: OffsetDateTime (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param body Request payload for the token exchange. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a communication identity with access token along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response exchangeTokenWithResponse(BinaryData body, RequestOptions requestOptions) { + final String contentType = "application/json"; + final String accept = "application/json"; + return service.exchangeTokenSync(this.client.getEndpoint(), this.client.getServiceVersion().getVersion(), + contentType, accept, body, requestOptions, Context.NONE); + } + + /** + * Get Teams Phone access assignment by object id. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     objectId: String (Required)
+     *     tenantId: String (Required)
+     *     principalType: String(resourceAccount/user) (Required)
+     *     clientIds (Optional): [
+     *         String (Optional)
+     *     ]
+     * }
+     * }
+     * 
+ * + * @param tenantId Tenant Id we want to get the assignment for. + * @param objectId Object Id we want to get the assignment for. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return teams Phone access assignment by object id along with {@link Response} on successful completion of + * {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getAssignmentWithResponseAsync(String tenantId, String objectId, + RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.getAssignment(this.client.getEndpoint(), + this.client.getServiceVersion().getVersion(), tenantId, objectId, accept, requestOptions, context)); + } + + /** + * Get Teams Phone access assignment by object id. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     objectId: String (Required)
+     *     tenantId: String (Required)
+     *     principalType: String(resourceAccount/user) (Required)
+     *     clientIds (Optional): [
+     *         String (Optional)
+     *     ]
+     * }
+     * }
+     * 
+ * + * @param tenantId Tenant Id we want to get the assignment for. + * @param objectId Object Id we want to get the assignment for. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return teams Phone access assignment by object id along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getAssignmentWithResponse(String tenantId, String objectId, + RequestOptions requestOptions) { + final String accept = "application/json"; + return service.getAssignmentSync(this.client.getEndpoint(), this.client.getServiceVersion().getVersion(), + tenantId, objectId, accept, requestOptions, Context.NONE); + } + + /** + * Creates or replaces a Teams Phone access assignment. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     principalType: String(resourceAccount/user) (Required)
+     *     clientIds (Optional): [
+     *         String (Optional)
+     *     ]
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     objectId: String (Required)
+     *     tenantId: String (Required)
+     *     principalType: String(resourceAccount/user) (Required)
+     *     clientIds (Optional): [
+     *         String (Optional)
+     *     ]
+     * }
+     * }
+     * 
+ * + * @param tenantId Tenant Id we want to update the assignment for. + * @param objectId Object Id we want to update the assignment for. + * @param body Values we want to set. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a Teams Extension assignment response along with {@link Response} on successful completion of + * {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> upsertAssignmentWithResponseAsync(String tenantId, String objectId, + BinaryData body, RequestOptions requestOptions) { + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil.withContext( + context -> service.upsertAssignment(this.client.getEndpoint(), this.client.getServiceVersion().getVersion(), + tenantId, objectId, contentType, accept, body, requestOptions, context)); + } + + /** + * Creates or replaces a Teams Phone access assignment. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     principalType: String(resourceAccount/user) (Required)
+     *     clientIds (Optional): [
+     *         String (Optional)
+     *     ]
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     objectId: String (Required)
+     *     tenantId: String (Required)
+     *     principalType: String(resourceAccount/user) (Required)
+     *     clientIds (Optional): [
+     *         String (Optional)
+     *     ]
+     * }
+     * }
+     * 
+ * + * @param tenantId Tenant Id we want to update the assignment for. + * @param objectId Object Id we want to update the assignment for. + * @param body Values we want to set. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a Teams Extension assignment response along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response upsertAssignmentWithResponse(String tenantId, String objectId, BinaryData body, + RequestOptions requestOptions) { + final String contentType = "application/json"; + final String accept = "application/json"; + return service.upsertAssignmentSync(this.client.getEndpoint(), this.client.getServiceVersion().getVersion(), + tenantId, objectId, contentType, accept, body, requestOptions, Context.NONE); + } + + /** + * Removes a Teams Phone access assignment. + * + * @param tenantId Tenant Id we want to remove the assignment for. + * @param objectId Object Id we want to remove the assignment for. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> deleteAssignmentWithResponseAsync(String tenantId, String objectId, + RequestOptions requestOptions) { + return FluxUtil.withContext(context -> service.deleteAssignment(this.client.getEndpoint(), + this.client.getServiceVersion().getVersion(), tenantId, objectId, requestOptions, context)); + } + + /** + * Removes a Teams Phone access assignment. + * + * @param tenantId Tenant Id we want to remove the assignment for. + * @param objectId Object Id we want to remove the assignment for. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response deleteAssignmentWithResponse(String tenantId, String objectId, + RequestOptions requestOptions) { + return service.deleteAssignmentSync(this.client.getEndpoint(), this.client.getServiceVersion().getVersion(), + tenantId, objectId, requestOptions, Context.NONE); + } +} diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/TeamsUserOperationsImpl.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/TeamsUserOperationsImpl.java new file mode 100644 index 0000000000000..6e9b8431779f2 --- /dev/null +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/TeamsUserOperationsImpl.java @@ -0,0 +1,180 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.communication.identity.implementation; + +import com.azure.communication.identity.IdentityServiceVersion; +import com.azure.core.annotation.BodyParam; +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.Post; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in TeamsUserOperations. + */ +public final class TeamsUserOperationsImpl { + /** + * The proxy service used to perform REST calls. + */ + private final TeamsUserOperationsService service; + + /** + * The service client containing this operation class. + */ + private final IdentityClientImpl client; + + /** + * Initializes an instance of TeamsUserOperationsImpl. + * + * @param client the instance of the service client containing this operation class. + */ + TeamsUserOperationsImpl(IdentityClientImpl client) { + this.service = RestProxy.create(TeamsUserOperationsService.class, client.getHttpPipeline(), + client.getSerializerAdapter()); + this.client = client; + } + + /** + * Gets Service version. + * + * @return the serviceVersion value. + */ + public IdentityServiceVersion getServiceVersion() { + return client.getServiceVersion(); + } + + /** + * The interface defining all the services for IdentityClientTeamsUserOperations to be used by the proxy service to + * perform REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "IdentityClientTeamsUserOperations") + public interface TeamsUserOperationsService { + @Post("/teamsUser/:exchangeAccessToken") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> exchangeTeamsUserAccessToken(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @HeaderParam("Content-Type") String contentType, + @HeaderParam("Accept") String accept, @BodyParam("application/json") BinaryData body, + RequestOptions requestOptions, Context context); + + @Post("/teamsUser/:exchangeAccessToken") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response exchangeTeamsUserAccessTokenSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @HeaderParam("Content-Type") String contentType, + @HeaderParam("Accept") String accept, @BodyParam("application/json") BinaryData body, + RequestOptions requestOptions, Context context); + } + + /** + * Exchange an Entra ID access token of a Teams user for a new Communication Identity access token with a matching + * expiration time. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     token: String (Required)
+     *     appId: String (Required)
+     *     userId: String (Required)
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     token: String (Required)
+     *     expiresOn: OffsetDateTime (Required)
+     * }
+     * }
+     * 
+ * + * @param body Request payload for the token exchange. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return an access token along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> exchangeTeamsUserAccessTokenWithResponseAsync(BinaryData body, + RequestOptions requestOptions) { + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.exchangeTeamsUserAccessToken(this.client.getEndpoint(), + this.client.getServiceVersion().getVersion(), contentType, accept, body, requestOptions, context)); + } + + /** + * Exchange an Entra ID access token of a Teams user for a new Communication Identity access token with a matching + * expiration time. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     token: String (Required)
+     *     appId: String (Required)
+     *     userId: String (Required)
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     token: String (Required)
+     *     expiresOn: OffsetDateTime (Required)
+     * }
+     * }
+     * 
+ * + * @param body Request payload for the token exchange. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return an access token along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response exchangeTeamsUserAccessTokenWithResponse(BinaryData body, + RequestOptions requestOptions) { + final String contentType = "application/json"; + final String accept = "application/json"; + return service.exchangeTeamsUserAccessTokenSync(this.client.getEndpoint(), + this.client.getServiceVersion().getVersion(), contentType, accept, body, requestOptions, Context.NONE); + } +} diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentity.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentity.java index 27c7624df7507..56afed4f09856 100644 --- a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentity.java +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentity.java @@ -1,11 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - +// Code generated by Microsoft (R) TypeSpec Code Generator. package com.azure.communication.identity.implementation.models; -import com.azure.core.annotation.Fluent; import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; import com.azure.json.JsonReader; import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; @@ -15,24 +14,18 @@ /** * A communication identity. */ -@Fluent +@Immutable public final class CommunicationIdentity implements JsonSerializable { + /* * Identifier of the identity. */ @Generated - private String id; - - /** - * Creates an instance of CommunicationIdentity class. - */ - @Generated - public CommunicationIdentity() { - } + private final String id; /** * Get the id property: Identifier of the identity. - * + * * @return the id value. */ @Generated @@ -40,18 +33,6 @@ public String getId() { return this.id; } - /** - * Set the id property: Identifier of the identity. - * - * @param id the id value to set. - * @return the CommunicationIdentity object itself. - */ - @Generated - public CommunicationIdentity setId(String id) { - this.id = id; - return this; - } - /** * {@inheritDoc} */ @@ -65,7 +46,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { /** * Reads an instance of CommunicationIdentity from the JsonReader. - * + * * @param jsonReader The JsonReader being read. * @return An instance of CommunicationIdentity if the JsonReader was pointing to an instance of it, or null if it * was pointing to JSON null. @@ -75,19 +56,27 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { @Generated public static CommunicationIdentity fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { - CommunicationIdentity deserializedCommunicationIdentity = new CommunicationIdentity(); + String id = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("id".equals(fieldName)) { - deserializedCommunicationIdentity.id = reader.getString(); + id = reader.getString(); } else { reader.skipChildren(); } } - - return deserializedCommunicationIdentity; + return new CommunicationIdentity(id); }); } + + /** + * Creates an instance of CommunicationIdentity class. + * + * @param id the id value to set. + */ + @Generated + private CommunicationIdentity(String id) { + this.id = id; + } } diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentityAccessToken.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentityAccessToken.java index c38b0573362a3..409c84d54aba0 100644 --- a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentityAccessToken.java +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentityAccessToken.java @@ -1,11 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - +// Code generated by Microsoft (R) TypeSpec Code Generator. package com.azure.communication.identity.implementation.models; -import com.azure.core.annotation.Fluent; import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; import com.azure.core.util.CoreUtils; import com.azure.json.JsonReader; import com.azure.json.JsonSerializable; @@ -18,30 +17,24 @@ /** * An access token. */ -@Fluent +@Immutable public final class CommunicationIdentityAccessToken implements JsonSerializable { + /* * The access token issued for the identity. */ @Generated - private String token; + private final String token; /* * The expiry time of the token. */ @Generated - private OffsetDateTime expiresOn; - - /** - * Creates an instance of CommunicationIdentityAccessToken class. - */ - @Generated - public CommunicationIdentityAccessToken() { - } + private final OffsetDateTime expiresOn; /** * Get the token property: The access token issued for the identity. - * + * * @return the token value. */ @Generated @@ -49,21 +42,9 @@ public String getToken() { return this.token; } - /** - * Set the token property: The access token issued for the identity. - * - * @param token the token value to set. - * @return the CommunicationIdentityAccessToken object itself. - */ - @Generated - public CommunicationIdentityAccessToken setToken(String token) { - this.token = token; - return this; - } - /** * Get the expiresOn property: The expiry time of the token. - * + * * @return the expiresOn value. */ @Generated @@ -71,18 +52,6 @@ public OffsetDateTime getExpiresOn() { return this.expiresOn; } - /** - * Set the expiresOn property: The expiry time of the token. - * - * @param expiresOn the expiresOn value to set. - * @return the CommunicationIdentityAccessToken object itself. - */ - @Generated - public CommunicationIdentityAccessToken setExpiresOn(OffsetDateTime expiresOn) { - this.expiresOn = expiresOn; - return this; - } - /** * {@inheritDoc} */ @@ -98,7 +67,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { /** * Reads an instance of CommunicationIdentityAccessToken from the JsonReader. - * + * * @param jsonReader The JsonReader being read. * @return An instance of CommunicationIdentityAccessToken if the JsonReader was pointing to an instance of it, or * null if it was pointing to JSON null. @@ -108,23 +77,33 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { @Generated public static CommunicationIdentityAccessToken fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { - CommunicationIdentityAccessToken deserializedCommunicationIdentityAccessToken - = new CommunicationIdentityAccessToken(); + String token = null; + OffsetDateTime expiresOn = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("token".equals(fieldName)) { - deserializedCommunicationIdentityAccessToken.token = reader.getString(); + token = reader.getString(); } else if ("expiresOn".equals(fieldName)) { - deserializedCommunicationIdentityAccessToken.expiresOn = reader + expiresOn = reader .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString())); } else { reader.skipChildren(); } } - - return deserializedCommunicationIdentityAccessToken; + return new CommunicationIdentityAccessToken(token, expiresOn); }); } + + /** + * Creates an instance of CommunicationIdentityAccessToken class. + * + * @param token the token value to set. + * @param expiresOn the expiresOn value to set. + */ + @Generated + private CommunicationIdentityAccessToken(String token, OffsetDateTime expiresOn) { + this.token = token; + this.expiresOn = expiresOn; + } } diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentityAccessTokenRequest.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentityAccessTokenRequest.java index ba34cf196b77e..5806f90a02a40 100644 --- a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentityAccessTokenRequest.java +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentityAccessTokenRequest.java @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - +// Code generated by Microsoft (R) TypeSpec Code Generator. package com.azure.communication.identity.implementation.models; import com.azure.communication.identity.models.CommunicationTokenScope; @@ -15,16 +14,17 @@ import java.util.List; /** - * The CommunicationIdentityAccessTokenRequest model. + * Request to issue a new access token for an identity. */ @Fluent public final class CommunicationIdentityAccessTokenRequest implements JsonSerializable { + /* * List of scopes attached to the token. */ @Generated - private List scopes; + private final List scopes; /* * Optional custom validity period of the token within [60,1440] minutes range. If not provided, the default value @@ -33,16 +33,9 @@ public final class CommunicationIdentityAccessTokenRequest @Generated private Integer expiresInMinutes; - /** - * Creates an instance of CommunicationIdentityAccessTokenRequest class. - */ - @Generated - public CommunicationIdentityAccessTokenRequest() { - } - /** * Get the scopes property: List of scopes attached to the token. - * + * * @return the scopes value. */ @Generated @@ -50,22 +43,10 @@ public List getScopes() { return this.scopes; } - /** - * Set the scopes property: List of scopes attached to the token. - * - * @param scopes the scopes value to set. - * @return the CommunicationIdentityAccessTokenRequest object itself. - */ - @Generated - public CommunicationIdentityAccessTokenRequest setScopes(List scopes) { - this.scopes = scopes; - return this; - } - /** * Get the expiresInMinutes property: Optional custom validity period of the token within [60,1440] minutes range. * If not provided, the default value of 1440 minutes (24 hours) will be used. - * + * * @return the expiresInMinutes value. */ @Generated @@ -76,7 +57,7 @@ public Integer getExpiresInMinutes() { /** * Set the expiresInMinutes property: Optional custom validity period of the token within [60,1440] minutes range. * If not provided, the default value of 1440 minutes (24 hours) will be used. - * + * * @param expiresInMinutes the expiresInMinutes value to set. * @return the CommunicationIdentityAccessTokenRequest object itself. */ @@ -101,7 +82,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { /** * Reads an instance of CommunicationIdentityAccessTokenRequest from the JsonReader. - * + * * @param jsonReader The JsonReader being read. * @return An instance of CommunicationIdentityAccessTokenRequest if the JsonReader was pointing to an instance of * it, or null if it was pointing to JSON null. @@ -111,25 +92,33 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { @Generated public static CommunicationIdentityAccessTokenRequest fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { - CommunicationIdentityAccessTokenRequest deserializedCommunicationIdentityAccessTokenRequest - = new CommunicationIdentityAccessTokenRequest(); + List scopes = null; + Integer expiresInMinutes = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("scopes".equals(fieldName)) { - List scopes - = reader.readArray(reader1 -> CommunicationTokenScope.fromString(reader1.getString())); - deserializedCommunicationIdentityAccessTokenRequest.scopes = scopes; + scopes = reader.readArray(reader1 -> CommunicationTokenScope.fromString(reader1.getString())); } else if ("expiresInMinutes".equals(fieldName)) { - deserializedCommunicationIdentityAccessTokenRequest.expiresInMinutes - = reader.getNullable(JsonReader::getInt); + expiresInMinutes = reader.getNullable(JsonReader::getInt); } else { reader.skipChildren(); } } - + CommunicationIdentityAccessTokenRequest deserializedCommunicationIdentityAccessTokenRequest + = new CommunicationIdentityAccessTokenRequest(scopes); + deserializedCommunicationIdentityAccessTokenRequest.expiresInMinutes = expiresInMinutes; return deserializedCommunicationIdentityAccessTokenRequest; }); } + + /** + * Creates an instance of CommunicationIdentityAccessTokenRequest class. + * + * @param scopes the scopes value to set. + */ + @Generated + public CommunicationIdentityAccessTokenRequest(List scopes) { + this.scopes = scopes; + } } diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentityAccessTokenResult.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentityAccessTokenResult.java index 9828c606da449..6f4df090e0321 100644 --- a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentityAccessTokenResult.java +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentityAccessTokenResult.java @@ -1,11 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - +// Code generated by Microsoft (R) TypeSpec Code Generator. package com.azure.communication.identity.implementation.models; -import com.azure.core.annotation.Fluent; import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; import com.azure.json.JsonReader; import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; @@ -15,14 +14,15 @@ /** * A communication identity with access token. */ -@Fluent +@Immutable public final class CommunicationIdentityAccessTokenResult implements JsonSerializable { + /* - * A communication identity. + * The communication identity. */ @Generated - private CommunicationIdentity identity; + private final CommunicationIdentity identity; /* * An access token. @@ -31,15 +31,8 @@ public final class CommunicationIdentityAccessTokenResult private CommunicationIdentityAccessToken accessToken; /** - * Creates an instance of CommunicationIdentityAccessTokenResult class. - */ - @Generated - public CommunicationIdentityAccessTokenResult() { - } - - /** - * Get the identity property: A communication identity. - * + * Get the identity property: The communication identity. + * * @return the identity value. */ @Generated @@ -47,21 +40,9 @@ public CommunicationIdentity getIdentity() { return this.identity; } - /** - * Set the identity property: A communication identity. - * - * @param identity the identity value to set. - * @return the CommunicationIdentityAccessTokenResult object itself. - */ - @Generated - public CommunicationIdentityAccessTokenResult setIdentity(CommunicationIdentity identity) { - this.identity = identity; - return this; - } - /** * Get the accessToken property: An access token. - * + * * @return the accessToken value. */ @Generated @@ -69,18 +50,6 @@ public CommunicationIdentityAccessToken getAccessToken() { return this.accessToken; } - /** - * Set the accessToken property: An access token. - * - * @param accessToken the accessToken value to set. - * @return the CommunicationIdentityAccessTokenResult object itself. - */ - @Generated - public CommunicationIdentityAccessTokenResult setAccessToken(CommunicationIdentityAccessToken accessToken) { - this.accessToken = accessToken; - return this; - } - /** * {@inheritDoc} */ @@ -95,7 +64,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { /** * Reads an instance of CommunicationIdentityAccessTokenResult from the JsonReader. - * + * * @param jsonReader The JsonReader being read. * @return An instance of CommunicationIdentityAccessTokenResult if the JsonReader was pointing to an instance of * it, or null if it was pointing to JSON null. @@ -105,24 +74,33 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { @Generated public static CommunicationIdentityAccessTokenResult fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { - CommunicationIdentityAccessTokenResult deserializedCommunicationIdentityAccessTokenResult - = new CommunicationIdentityAccessTokenResult(); + CommunicationIdentity identity = null; + CommunicationIdentityAccessToken accessToken = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("identity".equals(fieldName)) { - deserializedCommunicationIdentityAccessTokenResult.identity - = CommunicationIdentity.fromJson(reader); + identity = CommunicationIdentity.fromJson(reader); } else if ("accessToken".equals(fieldName)) { - deserializedCommunicationIdentityAccessTokenResult.accessToken - = CommunicationIdentityAccessToken.fromJson(reader); + accessToken = CommunicationIdentityAccessToken.fromJson(reader); } else { reader.skipChildren(); } } - + CommunicationIdentityAccessTokenResult deserializedCommunicationIdentityAccessTokenResult + = new CommunicationIdentityAccessTokenResult(identity); + deserializedCommunicationIdentityAccessTokenResult.accessToken = accessToken; return deserializedCommunicationIdentityAccessTokenResult; }); } + + /** + * Creates an instance of CommunicationIdentityAccessTokenResult class. + * + * @param identity the identity value to set. + */ + @Generated + private CommunicationIdentityAccessTokenResult(CommunicationIdentity identity) { + this.identity = identity; + } } diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentityCreateRequest.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentityCreateRequest.java index 0784f2555546f..fa701da2958ef 100644 --- a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentityCreateRequest.java +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentityCreateRequest.java @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - +// Code generated by Microsoft (R) TypeSpec Code Generator. package com.azure.communication.identity.implementation.models; import com.azure.communication.identity.models.CommunicationTokenScope; @@ -15,10 +14,11 @@ import java.util.List; /** - * The CommunicationIdentityCreateRequest model. + * Request to create a new identity with optional access token. */ @Fluent public final class CommunicationIdentityCreateRequest implements JsonSerializable { + /* * Also create access token for the created identity. */ @@ -41,7 +41,7 @@ public CommunicationIdentityCreateRequest() { /** * Get the createTokenWithScopes property: Also create access token for the created identity. - * + * * @return the createTokenWithScopes value. */ @Generated @@ -51,7 +51,7 @@ public List getCreateTokenWithScopes() { /** * Set the createTokenWithScopes property: Also create access token for the created identity. - * + * * @param createTokenWithScopes the createTokenWithScopes value to set. * @return the CommunicationIdentityCreateRequest object itself. */ @@ -65,7 +65,7 @@ public List getCreateTokenWithScopes() { /** * Get the expiresInMinutes property: Optional custom validity period of the token within [60,1440] minutes range. * If not provided, the default value of 1440 minutes (24 hours) will be used. - * + * * @return the expiresInMinutes value. */ @Generated @@ -76,7 +76,7 @@ public Integer getExpiresInMinutes() { /** * Set the expiresInMinutes property: Optional custom validity period of the token within [60,1440] minutes range. * If not provided, the default value of 1440 minutes (24 hours) will be used. - * + * * @param expiresInMinutes the expiresInMinutes value to set. * @return the CommunicationIdentityCreateRequest object itself. */ @@ -101,7 +101,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { /** * Reads an instance of CommunicationIdentityCreateRequest from the JsonReader. - * + * * @param jsonReader The JsonReader being read. * @return An instance of CommunicationIdentityCreateRequest if the JsonReader was pointing to an instance of it, or * null if it was pointing to JSON null. @@ -115,7 +115,6 @@ public static CommunicationIdentityCreateRequest fromJson(JsonReader jsonReader) while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("createTokenWithScopes".equals(fieldName)) { List createTokenWithScopes = reader.readArray(reader1 -> CommunicationTokenScope.fromString(reader1.getString())); @@ -127,7 +126,6 @@ public static CommunicationIdentityCreateRequest fromJson(JsonReader jsonReader) reader.skipChildren(); } } - return deserializedCommunicationIdentityCreateRequest; }); } diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/TeamsExtensionAssignmentCreateOrUpdateRequest.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/TeamsExtensionAssignmentCreateOrUpdateRequest.java new file mode 100644 index 0000000000000..bb8192d7cbfb8 --- /dev/null +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/TeamsExtensionAssignmentCreateOrUpdateRequest.java @@ -0,0 +1,119 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.communication.identity.implementation.models; + +import com.azure.core.annotation.Fluent; +import com.azure.core.annotation.Generated; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.List; + +/** + * A request to create or update a Teams Extension assignment. + */ +@Fluent +public final class TeamsExtensionAssignmentCreateOrUpdateRequest + implements JsonSerializable { + + /* + * The type of principal the assignment is for. + */ + @Generated + private final TeamsExtensionPrincipalType principalType; + + /* + * The client IDs for the assignment. + */ + @Generated + private List clientIds; + + /** + * Creates an instance of TeamsExtensionAssignmentCreateOrUpdateRequest class. + * + * @param principalType the principalType value to set. + */ + @Generated + public TeamsExtensionAssignmentCreateOrUpdateRequest(TeamsExtensionPrincipalType principalType) { + this.principalType = principalType; + } + + /** + * Get the principalType property: The type of principal the assignment is for. + * + * @return the principalType value. + */ + @Generated + public TeamsExtensionPrincipalType getPrincipalType() { + return this.principalType; + } + + /** + * Get the clientIds property: The client IDs for the assignment. + * + * @return the clientIds value. + */ + @Generated + public List getClientIds() { + return this.clientIds; + } + + /** + * Set the clientIds property: The client IDs for the assignment. + * + * @param clientIds the clientIds value to set. + * @return the TeamsExtensionAssignmentCreateOrUpdateRequest object itself. + */ + @Generated + public TeamsExtensionAssignmentCreateOrUpdateRequest setClientIds(List clientIds) { + this.clientIds = clientIds; + return this; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("principalType", this.principalType == null ? null : this.principalType.toString()); + jsonWriter.writeArrayField("clientIds", this.clientIds, (writer, element) -> writer.writeString(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of TeamsExtensionAssignmentCreateOrUpdateRequest from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of TeamsExtensionAssignmentCreateOrUpdateRequest if the JsonReader was pointing to an + * instance of it, or null if it was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the TeamsExtensionAssignmentCreateOrUpdateRequest. + */ + @Generated + public static TeamsExtensionAssignmentCreateOrUpdateRequest fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + TeamsExtensionPrincipalType principalType = null; + List clientIds = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("principalType".equals(fieldName)) { + principalType = TeamsExtensionPrincipalType.fromString(reader.getString()); + } else if ("clientIds".equals(fieldName)) { + clientIds = reader.readArray(reader1 -> reader1.getString()); + } else { + reader.skipChildren(); + } + } + TeamsExtensionAssignmentCreateOrUpdateRequest deserializedTeamsExtensionAssignmentCreateOrUpdateRequest + = new TeamsExtensionAssignmentCreateOrUpdateRequest(principalType); + deserializedTeamsExtensionAssignmentCreateOrUpdateRequest.clientIds = clientIds; + return deserializedTeamsExtensionAssignmentCreateOrUpdateRequest; + }); + } +} diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/TeamsExtensionAssignmentResponse.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/TeamsExtensionAssignmentResponse.java new file mode 100644 index 0000000000000..db3ed6797469c --- /dev/null +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/TeamsExtensionAssignmentResponse.java @@ -0,0 +1,151 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.communication.identity.implementation.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.List; + +/** + * A Teams Extension assignment response. + */ +@Immutable +public final class TeamsExtensionAssignmentResponse implements JsonSerializable { + + /* + * The object ID of the assignment. + */ + @Generated + private final String objectId; + + /* + * The tenant ID of the assignment. + */ + @Generated + private final String tenantId; + + /* + * The type of principal the assignment is for. + */ + @Generated + private final TeamsExtensionPrincipalType principalType; + + /* + * The client IDs for the assignment. + */ + @Generated + private List clientIds; + + /** + * Creates an instance of TeamsExtensionAssignmentResponse class. + * + * @param objectId the objectId value to set. + * @param tenantId the tenantId value to set. + * @param principalType the principalType value to set. + */ + @Generated + private TeamsExtensionAssignmentResponse(String objectId, String tenantId, + TeamsExtensionPrincipalType principalType) { + this.objectId = objectId; + this.tenantId = tenantId; + this.principalType = principalType; + } + + /** + * Get the objectId property: The object ID of the assignment. + * + * @return the objectId value. + */ + @Generated + public String getObjectId() { + return this.objectId; + } + + /** + * Get the tenantId property: The tenant ID of the assignment. + * + * @return the tenantId value. + */ + @Generated + public String getTenantId() { + return this.tenantId; + } + + /** + * Get the principalType property: The type of principal the assignment is for. + * + * @return the principalType value. + */ + @Generated + public TeamsExtensionPrincipalType getPrincipalType() { + return this.principalType; + } + + /** + * Get the clientIds property: The client IDs for the assignment. + * + * @return the clientIds value. + */ + @Generated + public List getClientIds() { + return this.clientIds; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("objectId", this.objectId); + jsonWriter.writeStringField("tenantId", this.tenantId); + jsonWriter.writeStringField("principalType", this.principalType == null ? null : this.principalType.toString()); + jsonWriter.writeArrayField("clientIds", this.clientIds, (writer, element) -> writer.writeString(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of TeamsExtensionAssignmentResponse from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of TeamsExtensionAssignmentResponse if the JsonReader was pointing to an instance of it, or + * null if it was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the TeamsExtensionAssignmentResponse. + */ + @Generated + public static TeamsExtensionAssignmentResponse fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String objectId = null; + String tenantId = null; + TeamsExtensionPrincipalType principalType = null; + List clientIds = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("objectId".equals(fieldName)) { + objectId = reader.getString(); + } else if ("tenantId".equals(fieldName)) { + tenantId = reader.getString(); + } else if ("principalType".equals(fieldName)) { + principalType = TeamsExtensionPrincipalType.fromString(reader.getString()); + } else if ("clientIds".equals(fieldName)) { + clientIds = reader.readArray(reader1 -> reader1.getString()); + } else { + reader.skipChildren(); + } + } + TeamsExtensionAssignmentResponse deserializedTeamsExtensionAssignmentResponse + = new TeamsExtensionAssignmentResponse(objectId, tenantId, principalType); + deserializedTeamsExtensionAssignmentResponse.clientIds = clientIds; + return deserializedTeamsExtensionAssignmentResponse; + }); + } +} diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/TeamsExtensionExchangeTokenRequest.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/TeamsExtensionExchangeTokenRequest.java new file mode 100644 index 0000000000000..8c265d14a6acc --- /dev/null +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/TeamsExtensionExchangeTokenRequest.java @@ -0,0 +1,105 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.communication.identity.implementation.models; + +import com.azure.core.annotation.Fluent; +import com.azure.core.annotation.Generated; +import com.azure.core.util.BinaryData; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * A request to exchange a Teams Extension token. + */ +@Fluent +public final class TeamsExtensionExchangeTokenRequest implements JsonSerializable { + + /* + * A request to exchange a Teams Extension token. + */ + @Generated + private Map additionalProperties; + + /** + * Creates an instance of TeamsExtensionExchangeTokenRequest class. + */ + @Generated + public TeamsExtensionExchangeTokenRequest() { + } + + /** + * Get the additionalProperties property: A request to exchange a Teams Extension token. + * + * @return the additionalProperties value. + */ + @Generated + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + /** + * Set the additionalProperties property: A request to exchange a Teams Extension token. + * + * @param additionalProperties the additionalProperties value to set. + * @return the TeamsExtensionExchangeTokenRequest object itself. + */ + @Generated + public TeamsExtensionExchangeTokenRequest setAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + if (additionalProperties != null) { + for (Map.Entry additionalProperty : additionalProperties.entrySet()) { + jsonWriter.writeFieldName(additionalProperty.getKey()); + if (additionalProperty.getValue() == null) { + jsonWriter.writeNull(); + } else { + additionalProperty.getValue().writeTo(jsonWriter); + } + } + } + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of TeamsExtensionExchangeTokenRequest from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of TeamsExtensionExchangeTokenRequest if the JsonReader was pointing to an instance of it, or + * null if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the TeamsExtensionExchangeTokenRequest. + */ + @Generated + public static TeamsExtensionExchangeTokenRequest fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + TeamsExtensionExchangeTokenRequest deserializedTeamsExtensionExchangeTokenRequest + = new TeamsExtensionExchangeTokenRequest(); + Map additionalProperties = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if (additionalProperties == null) { + additionalProperties = new LinkedHashMap<>(); + } + additionalProperties.put(fieldName, + reader.getNullable(nonNullReader -> BinaryData.fromObject(nonNullReader.readUntyped()))); + } + deserializedTeamsExtensionExchangeTokenRequest.additionalProperties = additionalProperties; + return deserializedTeamsExtensionExchangeTokenRequest; + }); + } +} diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/TeamsExtensionPrincipalType.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/TeamsExtensionPrincipalType.java new file mode 100644 index 0000000000000..fa711e345dd22 --- /dev/null +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/TeamsExtensionPrincipalType.java @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.communication.identity.implementation.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * The type of principal the assignment is for. + */ +public final class TeamsExtensionPrincipalType extends ExpandableStringEnum { + + /** + * Resource account principal type. + */ + @Generated + public static final TeamsExtensionPrincipalType RESOURCE_ACCOUNT = fromString("resourceAccount"); + + /** + * User principal type. + */ + @Generated + public static final TeamsExtensionPrincipalType USER = fromString("user"); + + /** + * Creates a new instance of TeamsExtensionPrincipalType value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Generated + @Deprecated + public TeamsExtensionPrincipalType() { + } + + /** + * Creates or finds a TeamsExtensionPrincipalType from its string representation. + * + * @param name a name to look for. + * @return the corresponding TeamsExtensionPrincipalType. + */ + @Generated + public static TeamsExtensionPrincipalType fromString(String name) { + return fromString(name, TeamsExtensionPrincipalType.class); + } + + /** + * Gets known TeamsExtensionPrincipalType values. + * + * @return known TeamsExtensionPrincipalType values. + */ + @Generated + public static Collection values() { + return values(TeamsExtensionPrincipalType.class); + } +} diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/package-info.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/package-info.java index 8961b09dba2c7..87245946f73de 100644 --- a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/package-info.java +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/models/package-info.java @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. // Code generated by Microsoft (R) AutoRest Code Generator. - /** * Package containing the data models for CommunicationIdentityClient. * Azure Communication Identity Service. diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/package-info.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/package-info.java index 267c8244a58bb..fa488fda79c1d 100644 --- a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/package-info.java +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/implementation/package-info.java @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. // Code generated by Microsoft (R) AutoRest Code Generator. - /** * Package containing the implementations for CommunicationIdentityClient. * Azure Communication Identity Service. diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/models/CommunicationTokenScope.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/models/CommunicationTokenScope.java index 338f9192925f7..d74a96698e4a5 100644 --- a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/models/CommunicationTokenScope.java +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/models/CommunicationTokenScope.java @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - +// Code generated by Microsoft (R) TypeSpec Code Generator. package com.azure.communication.identity.models; import com.azure.core.annotation.Generated; @@ -12,6 +11,7 @@ * List of scopes for an access token. */ public final class CommunicationTokenScope extends ExpandableStringEnum { + /** * Use this for full access to Chat APIs. */ @@ -45,7 +45,7 @@ public final class CommunicationTokenScope extends ExpandableStringEnum { /* - * Azure AD access token of a Teams User. + * Entra ID access token of a Teams User to acquire a new Communication Identity access token. */ @Generated - private String teamsUserAadToken; + private final String teamsUserAadToken; /* - * Client ID of an Azure AD application. + * Client ID of an Entra ID application to be verified against the appid claim in the Entra ID access token. */ @Generated - private String clientId; + private final String clientId; /* - * Object ID of an Azure AD user (Teams User). + * Object ID of an Entra ID user (Teams User) to be verified against the oid claim in the Entra ID access token. */ @Generated - private String userObjectId; + private final String userObjectId; /** - * Constructor of {@link GetTokenForTeamsUserOptions}. + * Creates an instance of GetTokenForTeamsUserOptions class. * - * @param teamsUserAadToken Azure AD access token of a Teams User. - * @param clientId Client ID of an Azure AD application to be verified against the appId claim in the Azure AD - * access token. - * @param userObjectId Object ID of an Azure AD user (Teams User) to be verified against the OID claim in the Azure - * AD access token. + * @param teamsUserAadToken the teamsUserAadToken value to set. + * @param clientId the clientId value to set. + * @param userObjectId the userObjectId value to set. */ @Generated public GetTokenForTeamsUserOptions(String teamsUserAadToken, String clientId, String userObjectId) { @@ -56,7 +50,8 @@ public GetTokenForTeamsUserOptions(String teamsUserAadToken, String clientId, St } /** - * Get the teamsUserAadToken property: Azure AD access token of a Teams User. + * Get the teamsUserAadToken property: Entra ID access token of a Teams User to acquire a new Communication Identity + * access token. * * @return the teamsUserAadToken value. */ @@ -66,7 +61,8 @@ public String getTeamsUserAadToken() { } /** - * Get the clientId property: Client ID of an Azure AD application. + * Get the clientId property: Client ID of an Entra ID application to be verified against the appid claim in the + * Entra ID access token. * * @return the clientId value. */ @@ -76,7 +72,8 @@ public String getClientId() { } /** - * Get the userObjectId property: Object ID of an Azure AD user (Teams User). + * Get the userObjectId property: Object ID of an Entra ID user (Teams User) to be verified against the oid claim in + * the Entra ID access token. * * @return the userObjectId value. */ @@ -110,27 +107,23 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { @Generated public static GetTokenForTeamsUserOptions fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { - GetTokenForTeamsUserOptions deserializedGetTokenForTeamsUserOptions = new GetTokenForTeamsUserOptions(); + String teamsUserAadToken = null; + String clientId = null; + String userObjectId = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); if ("token".equals(fieldName)) { - deserializedGetTokenForTeamsUserOptions.teamsUserAadToken = reader.getString(); + teamsUserAadToken = reader.getString(); } else if ("appId".equals(fieldName)) { - deserializedGetTokenForTeamsUserOptions.clientId = reader.getString(); + clientId = reader.getString(); } else if ("userId".equals(fieldName)) { - deserializedGetTokenForTeamsUserOptions.userObjectId = reader.getString(); + userObjectId = reader.getString(); } else { reader.skipChildren(); } } - return deserializedGetTokenForTeamsUserOptions; + return new GetTokenForTeamsUserOptions(teamsUserAadToken, clientId, userObjectId); }); } - - /** - * Private constructor for deserialization - */ - private GetTokenForTeamsUserOptions() { - } } diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/models/package-info.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/models/package-info.java index c7572cc3b7945..4b17d3e95e61a 100644 --- a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/models/package-info.java +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/models/package-info.java @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. // Code generated by Microsoft (R) AutoRest Code Generator. - /** * Package containing the data models for CommunicationIdentityClient. * Azure Communication Identity Service. diff --git a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/package-info.java b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/package-info.java index 08cd22d9a934d..614a6ce9210f0 100644 --- a/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/package-info.java +++ b/sdk/communication/azure-communication-identity/src/main/java/com/azure/communication/identity/package-info.java @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. - -/** Package containing the classes for AzureCommunicationIdentity. Azure Communication Identity Service. */ +/** + * Package containing the classes for AzureCommunicationIdentity. Azure Communication Identity Service. + */ package com.azure.communication.identity; diff --git a/sdk/communication/azure-communication-identity/src/main/java/module-info.java b/sdk/communication/azure-communication-identity/src/main/java/module-info.java index 6a8713742fc28..254444780cbdb 100644 --- a/sdk/communication/azure-communication-identity/src/main/java/module-info.java +++ b/sdk/communication/azure-communication-identity/src/main/java/module-info.java @@ -1,14 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. module com.azure.communication.identity { + requires transitive com.azure.core; requires com.azure.json; requires transitive com.azure.communication.common; - // public API surface area exports com.azure.communication.identity; exports com.azure.communication.identity.models; - opens com.azure.communication.identity.models to com.azure.core; opens com.azure.communication.identity.implementation.models to com.azure.core; + opens com.azure.communication.identity.models to com.azure.core; } diff --git a/sdk/communication/azure-communication-identity/src/main/resources/META-INF/azure-communication-identity_metadata.json b/sdk/communication/azure-communication-identity/src/main/resources/META-INF/azure-communication-identity_metadata.json new file mode 100644 index 0000000000000..123ece6202016 --- /dev/null +++ b/sdk/communication/azure-communication-identity/src/main/resources/META-INF/azure-communication-identity_metadata.json @@ -0,0 +1 @@ +{"flavor":"azure","apiVersions":{"Azure.Communication.Identity":"2026-09-23"},"crossLanguagePackageId":"Azure.Communication.Identity","crossLanguageVersion":"6be142630ab4","crossLanguageDefinitions":{"com.azure.communication.identity.IdentityClientBuilder":"Azure.Communication.Identity","com.azure.communication.identity.IdentityOperationsAsyncClient":"Azure.Communication.Identity.IdentityOperations","com.azure.communication.identity.IdentityOperationsAsyncClient.create":"Azure.Communication.Identity.IdentityOperations.create","com.azure.communication.identity.IdentityOperationsAsyncClient.createWithResponse":"Azure.Communication.Identity.IdentityOperations.create","com.azure.communication.identity.IdentityOperationsAsyncClient.delete":"Azure.Communication.Identity.IdentityOperations.delete","com.azure.communication.identity.IdentityOperationsAsyncClient.deleteWithResponse":"Azure.Communication.Identity.IdentityOperations.delete","com.azure.communication.identity.IdentityOperationsAsyncClient.issueAccessToken":"Azure.Communication.Identity.IdentityOperations.issueAccessToken","com.azure.communication.identity.IdentityOperationsAsyncClient.issueAccessTokenWithResponse":"Azure.Communication.Identity.IdentityOperations.issueAccessToken","com.azure.communication.identity.IdentityOperationsAsyncClient.revokeAccessTokens":"Azure.Communication.Identity.IdentityOperations.revokeAccessTokens","com.azure.communication.identity.IdentityOperationsAsyncClient.revokeAccessTokensWithResponse":"Azure.Communication.Identity.IdentityOperations.revokeAccessTokens","com.azure.communication.identity.IdentityOperationsClient":"Azure.Communication.Identity.IdentityOperations","com.azure.communication.identity.IdentityOperationsClient.create":"Azure.Communication.Identity.IdentityOperations.create","com.azure.communication.identity.IdentityOperationsClient.createWithResponse":"Azure.Communication.Identity.IdentityOperations.create","com.azure.communication.identity.IdentityOperationsClient.delete":"Azure.Communication.Identity.IdentityOperations.delete","com.azure.communication.identity.IdentityOperationsClient.deleteWithResponse":"Azure.Communication.Identity.IdentityOperations.delete","com.azure.communication.identity.IdentityOperationsClient.issueAccessToken":"Azure.Communication.Identity.IdentityOperations.issueAccessToken","com.azure.communication.identity.IdentityOperationsClient.issueAccessTokenWithResponse":"Azure.Communication.Identity.IdentityOperations.issueAccessToken","com.azure.communication.identity.IdentityOperationsClient.revokeAccessTokens":"Azure.Communication.Identity.IdentityOperations.revokeAccessTokens","com.azure.communication.identity.IdentityOperationsClient.revokeAccessTokensWithResponse":"Azure.Communication.Identity.IdentityOperations.revokeAccessTokens","com.azure.communication.identity.TeamsExtensionOperationsAsyncClient":"Azure.Communication.Identity.TeamsExtensionOperations","com.azure.communication.identity.TeamsExtensionOperationsAsyncClient.deleteAssignment":"Azure.Communication.Identity.TeamsExtensionOperations.deleteAssignment","com.azure.communication.identity.TeamsExtensionOperationsAsyncClient.deleteAssignmentWithResponse":"Azure.Communication.Identity.TeamsExtensionOperations.deleteAssignment","com.azure.communication.identity.TeamsExtensionOperationsAsyncClient.exchangeToken":"Azure.Communication.Identity.TeamsExtensionOperations.exchangeToken","com.azure.communication.identity.TeamsExtensionOperationsAsyncClient.exchangeTokenWithResponse":"Azure.Communication.Identity.TeamsExtensionOperations.exchangeToken","com.azure.communication.identity.TeamsExtensionOperationsAsyncClient.getAssignment":"Azure.Communication.Identity.TeamsExtensionOperations.getAssignment","com.azure.communication.identity.TeamsExtensionOperationsAsyncClient.getAssignmentWithResponse":"Azure.Communication.Identity.TeamsExtensionOperations.getAssignment","com.azure.communication.identity.TeamsExtensionOperationsAsyncClient.upsertAssignment":"Azure.Communication.Identity.TeamsExtensionOperations.upsertAssignment","com.azure.communication.identity.TeamsExtensionOperationsAsyncClient.upsertAssignmentWithResponse":"Azure.Communication.Identity.TeamsExtensionOperations.upsertAssignment","com.azure.communication.identity.TeamsExtensionOperationsClient":"Azure.Communication.Identity.TeamsExtensionOperations","com.azure.communication.identity.TeamsExtensionOperationsClient.deleteAssignment":"Azure.Communication.Identity.TeamsExtensionOperations.deleteAssignment","com.azure.communication.identity.TeamsExtensionOperationsClient.deleteAssignmentWithResponse":"Azure.Communication.Identity.TeamsExtensionOperations.deleteAssignment","com.azure.communication.identity.TeamsExtensionOperationsClient.exchangeToken":"Azure.Communication.Identity.TeamsExtensionOperations.exchangeToken","com.azure.communication.identity.TeamsExtensionOperationsClient.exchangeTokenWithResponse":"Azure.Communication.Identity.TeamsExtensionOperations.exchangeToken","com.azure.communication.identity.TeamsExtensionOperationsClient.getAssignment":"Azure.Communication.Identity.TeamsExtensionOperations.getAssignment","com.azure.communication.identity.TeamsExtensionOperationsClient.getAssignmentWithResponse":"Azure.Communication.Identity.TeamsExtensionOperations.getAssignment","com.azure.communication.identity.TeamsExtensionOperationsClient.upsertAssignment":"Azure.Communication.Identity.TeamsExtensionOperations.upsertAssignment","com.azure.communication.identity.TeamsExtensionOperationsClient.upsertAssignmentWithResponse":"Azure.Communication.Identity.TeamsExtensionOperations.upsertAssignment","com.azure.communication.identity.TeamsUserOperationsAsyncClient":"Azure.Communication.Identity.TeamsUserOperations","com.azure.communication.identity.TeamsUserOperationsAsyncClient.exchangeTeamsUserAccessToken":"Azure.Communication.Identity.TeamsUserOperations.exchangeTeamsUserAccessToken","com.azure.communication.identity.TeamsUserOperationsAsyncClient.exchangeTeamsUserAccessTokenWithResponse":"Azure.Communication.Identity.TeamsUserOperations.exchangeTeamsUserAccessToken","com.azure.communication.identity.TeamsUserOperationsClient":"Azure.Communication.Identity.TeamsUserOperations","com.azure.communication.identity.TeamsUserOperationsClient.exchangeTeamsUserAccessToken":"Azure.Communication.Identity.TeamsUserOperations.exchangeTeamsUserAccessToken","com.azure.communication.identity.TeamsUserOperationsClient.exchangeTeamsUserAccessTokenWithResponse":"Azure.Communication.Identity.TeamsUserOperations.exchangeTeamsUserAccessToken","com.azure.communication.identity.implementation.models.CommunicationIdentity":"Azure.Communication.Identity.CommunicationIdentity","com.azure.communication.identity.implementation.models.CommunicationIdentityAccessToken":"Azure.Communication.Identity.CommunicationIdentityAccessToken","com.azure.communication.identity.implementation.models.CommunicationIdentityAccessTokenRequest":"Azure.Communication.Identity.CommunicationIdentityAccessTokenRequest","com.azure.communication.identity.implementation.models.CommunicationIdentityAccessTokenResult":"Azure.Communication.Identity.CommunicationIdentityAccessTokenResult","com.azure.communication.identity.implementation.models.CommunicationIdentityCreateRequest":"Azure.Communication.Identity.CommunicationIdentityCreateRequest","com.azure.communication.identity.implementation.models.TeamsExtensionAssignmentCreateOrUpdateRequest":"Azure.Communication.Identity.TeamsExtensionAssignmentCreateOrUpdateRequest","com.azure.communication.identity.implementation.models.TeamsExtensionAssignmentResponse":"Azure.Communication.Identity.TeamsExtensionAssignmentResponse","com.azure.communication.identity.implementation.models.TeamsExtensionExchangeTokenRequest":"Azure.Communication.Identity.TeamsExtensionExchangeTokenRequest","com.azure.communication.identity.implementation.models.TeamsExtensionPrincipalType":"Azure.Communication.Identity.TeamsExtensionPrincipalType","com.azure.communication.identity.models.CommunicationTokenScope":"Azure.Communication.Identity.CommunicationIdentityTokenScope","com.azure.communication.identity.models.GetTokenForTeamsUserOptions":"Azure.Communication.Identity.TeamsUserExchangeTokenRequest"},"generatedFiles":["src/main/java/com/azure/communication/identity/IdentityClientBuilder.java","src/main/java/com/azure/communication/identity/IdentityOperationsAsyncClient.java","src/main/java/com/azure/communication/identity/IdentityOperationsClient.java","src/main/java/com/azure/communication/identity/IdentityServiceVersion.java","src/main/java/com/azure/communication/identity/TeamsExtensionOperationsAsyncClient.java","src/main/java/com/azure/communication/identity/TeamsExtensionOperationsClient.java","src/main/java/com/azure/communication/identity/TeamsUserOperationsAsyncClient.java","src/main/java/com/azure/communication/identity/TeamsUserOperationsClient.java","src/main/java/com/azure/communication/identity/implementation/IdentityClientImpl.java","src/main/java/com/azure/communication/identity/implementation/IdentityOperationsImpl.java","src/main/java/com/azure/communication/identity/implementation/TeamsExtensionOperationsImpl.java","src/main/java/com/azure/communication/identity/implementation/TeamsUserOperationsImpl.java","src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentity.java","src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentityAccessToken.java","src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentityAccessTokenRequest.java","src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentityAccessTokenResult.java","src/main/java/com/azure/communication/identity/implementation/models/CommunicationIdentityCreateRequest.java","src/main/java/com/azure/communication/identity/implementation/models/TeamsExtensionAssignmentCreateOrUpdateRequest.java","src/main/java/com/azure/communication/identity/implementation/models/TeamsExtensionAssignmentResponse.java","src/main/java/com/azure/communication/identity/implementation/models/TeamsExtensionExchangeTokenRequest.java","src/main/java/com/azure/communication/identity/implementation/models/TeamsExtensionPrincipalType.java","src/main/java/com/azure/communication/identity/implementation/models/package-info.java","src/main/java/com/azure/communication/identity/implementation/package-info.java","src/main/java/com/azure/communication/identity/models/CommunicationTokenScope.java","src/main/java/com/azure/communication/identity/models/GetTokenForTeamsUserOptions.java","src/main/java/com/azure/communication/identity/models/package-info.java","src/main/java/com/azure/communication/identity/package-info.java","src/main/java/module-info.java"]} \ No newline at end of file diff --git a/sdk/communication/azure-communication-identity/src/test/java/com/azure/communication/identity/CommunicationIdentityApiVersionTests.java b/sdk/communication/azure-communication-identity/src/test/java/com/azure/communication/identity/CommunicationIdentityApiVersionTests.java new file mode 100644 index 0000000000000..17b4ff593a5b6 --- /dev/null +++ b/sdk/communication/azure-communication-identity/src/test/java/com/azure/communication/identity/CommunicationIdentityApiVersionTests.java @@ -0,0 +1,171 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +package com.azure.communication.identity; + +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpRequest; +import com.azure.core.http.HttpResponse; +import com.azure.core.util.Context; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * Asserts that the api-version selected on the builder is the one placed on the wire, on both the + * synchronous and the asynchronous path. + * + *

The generated {@code IdentityClientImpl} accepts a typed enum that carries only the two most + * recent service versions, so the builder pins the api-version with a pipeline policy instead. This + * test covers that policy. It captures at the transport layer - a custom {@link HttpClient} is the + * final stage before the network, so what it observes is what would be sent.

+ * + *

The two paths are asserted separately and deliberately. {@code HttpPipelinePolicy} supplies a + * default {@code processSync} implementation, so a policy that only implements the asynchronous + * method still behaves correctly but blocks a thread; conversely a policy that mishandles the + * synchronous path would fail here and nowhere else. The recorded tests cannot make this + * distinction, because a synchronous fault and an asynchronous fault produce identical recording + * mismatches.

+ * + *

Expected values are written as literals rather than read back from + * {@link CommunicationIdentityServiceVersion}, so that the assertion cannot be satisfied by the + * enum agreeing with itself.

+ */ +public class CommunicationIdentityApiVersionTests { + + private static final String FAKE_CONNECTION_STRING + = "endpoint=https://localhost/;accesskey=" + "cHJvYmVwcm9iZXByb2JlcHJvYmVwcm9iZXByb2JlcHJvYmU="; + + /** + * Records the request URL as it reaches the transport, for both the asynchronous and the + * synchronous entry points, and returns a minimal successful response. + */ + private static final class CapturingHttpClient implements HttpClient { + private volatile String url; + + @Override + public Mono send(HttpRequest request) { + this.url = request.getUrl().toString(); + return Mono.just(new EmptyJsonResponse(request)); + } + + @Override + public HttpResponse sendSync(HttpRequest request, Context context) { + this.url = request.getUrl().toString(); + return new EmptyJsonResponse(request); + } + + String capturedApiVersion() { + assertNotNull(url, "no request reached the transport"); + int start = url.indexOf("api-version="); + if (start < 0) { + return "(absent)"; + } + String remainder = url.substring(start + "api-version=".length()); + int ampersand = remainder.indexOf('&'); + return ampersand < 0 ? remainder : remainder.substring(0, ampersand); + } + } + + private static final class EmptyJsonResponse extends HttpResponse { + private static final byte[] BODY = "{}".getBytes(StandardCharsets.UTF_8); + + EmptyJsonResponse(HttpRequest request) { + super(request); + } + + @Override + public int getStatusCode() { + return 200; + } + + @Override + public String getHeaderValue(String name) { + return null; + } + + @Override + public HttpHeaders getHeaders() { + return new HttpHeaders(); + } + + @Override + public Flux getBody() { + return Flux.just(ByteBuffer.wrap(BODY)); + } + + @Override + public Mono getBodyAsByteArray() { + return Mono.just(BODY); + } + + @Override + public Mono getBodyAsString() { + return Mono.just(new String(BODY, StandardCharsets.UTF_8)); + } + + @Override + public Mono getBodyAsString(Charset charset) { + return Mono.just(new String(BODY, charset)); + } + } + + @ParameterizedTest(name = "sync {0} sends api-version={1}") + @CsvSource({ + "V2021_03_07, 2021-03-07", + "V2022_06_01, 2022-06-01", + "V2022_10_01, 2022-10-01", + "V2023_10_01, 2023-10-01", + "V2025_06_30, 2025-06-30", + "V2026_09_23, 2026-09-23" }) + public void syncClientSendsSelectedApiVersion(CommunicationIdentityServiceVersion version, String expected) { + CapturingHttpClient transport = new CapturingHttpClient(); + CommunicationIdentityClient client + = new CommunicationIdentityClientBuilder().connectionString(FAKE_CONNECTION_STRING) + .serviceVersion(version) + .httpClient(transport) + .buildClient(); + + try { + client.createUser(); + } catch (RuntimeException ex) { + // The stub response is not a valid identity payload. The request has already been + // captured by the time it is deserialized, which is all this test asserts on. + } + + assertEquals(expected, transport.capturedApiVersion()); + } + + @ParameterizedTest(name = "async {0} sends api-version={1}") + @CsvSource({ + "V2021_03_07, 2021-03-07", + "V2022_06_01, 2022-06-01", + "V2022_10_01, 2022-10-01", + "V2023_10_01, 2023-10-01", + "V2025_06_30, 2025-06-30", + "V2026_09_23, 2026-09-23" }) + public void asyncClientSendsSelectedApiVersion(CommunicationIdentityServiceVersion version, String expected) { + CapturingHttpClient transport = new CapturingHttpClient(); + CommunicationIdentityAsyncClient client + = new CommunicationIdentityClientBuilder().connectionString(FAKE_CONNECTION_STRING) + .serviceVersion(version) + .httpClient(transport) + .buildAsyncClient(); + + try { + client.createUser().block(); + } catch (RuntimeException ex) { + // As above. + } + + assertEquals(expected, transport.capturedApiVersion()); + } +} diff --git a/sdk/communication/azure-communication-identity/src/test/java/com/azure/communication/identity/CommunicationIdentityClientTestBase.java b/sdk/communication/azure-communication-identity/src/test/java/com/azure/communication/identity/CommunicationIdentityClientTestBase.java index a08df7d4833ca..03462f05c86be 100644 --- a/sdk/communication/azure-communication-identity/src/test/java/com/azure/communication/identity/CommunicationIdentityClientTestBase.java +++ b/sdk/communication/azure-communication-identity/src/test/java/com/azure/communication/identity/CommunicationIdentityClientTestBase.java @@ -41,6 +41,26 @@ public class CommunicationIdentityClientTestBase extends TestProxyTestBase { private static final String REDACTED = "REDACTED"; private static final String URI_IDENTITY_REPLACER_REGEX = "/identities/([^/?]+)"; + + /* + * The existing recordings were captured against api-version 2023-10-01, which was the latest + * version this library supported before it moved to TypeSpec generation. Requests now carry + * 2026-09-23, so playback would fail to match on the request URI alone. + * + * Sanitizers are applied to both the recording and the incoming request, so rewriting the + * recorded value to the current one lets the two sides meet. Only this exact pair is affected: + * any other api-version still fails to match, so a regression that sent, say, 2022-10-01 would + * still be caught. The narrower gap - 2023-10-01 being accepted where 2026-09-23 is expected - + * is covered by CommunicationIdentityApiVersionTests, which asserts the exact api-version + * placed on the wire for every value of CommunicationIdentityServiceVersion, on both the + * synchronous and the asynchronous path. + * + * This is deliberately written in the old-to-new direction so that it retires itself: once the + * recordings are captured against 2026-09-23, the pattern matches nothing and this can be + * deleted. + */ + private static final String RECORDED_API_VERSION = "api-version=2023-10-01"; + private static final String CURRENT_API_VERSION = "api-version=2026-09-23"; protected static final String SYNC_TEST_SUFFIX = "Sync"; protected static final List SCOPES = Arrays.asList(CHAT, VOIP); protected static final String CONNECTION_STRING = Configuration.getGlobalConfiguration() @@ -125,6 +145,8 @@ private void addTestProxyTestSanitizersAndMatchers(InterceptorManager intercepto customSanitizers.add(new TestProxySanitizer("$..userId", null, REDACTED, TestProxySanitizerType.BODY_KEY)); customSanitizers.add( new TestProxySanitizer(URI_IDENTITY_REPLACER_REGEX, "/identities/" + REDACTED, TestProxySanitizerType.URL)); + customSanitizers + .add(new TestProxySanitizer(RECORDED_API_VERSION, CURRENT_API_VERSION, TestProxySanitizerType.URL)); interceptorManager.addSanitizers(customSanitizers); if (interceptorManager.isPlaybackMode()) { diff --git a/sdk/communication/azure-communication-identity/src/test/java/com/azure/communication/identity/CommunicationIdentityRequestHeaderTests.java b/sdk/communication/azure-communication-identity/src/test/java/com/azure/communication/identity/CommunicationIdentityRequestHeaderTests.java new file mode 100644 index 0000000000000..0ff9da76014e9 --- /dev/null +++ b/sdk/communication/azure-communication-identity/src/test/java/com/azure/communication/identity/CommunicationIdentityRequestHeaderTests.java @@ -0,0 +1,194 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +package com.azure.communication.identity; + +import com.azure.communication.common.CommunicationUserIdentifier; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpHeaderName; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpPipelineCallContext; +import com.azure.core.http.HttpPipelineNextPolicy; +import com.azure.core.http.HttpPipelineNextSyncPolicy; +import com.azure.core.http.HttpRequest; +import com.azure.core.http.HttpResponse; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.util.Context; +import org.junit.jupiter.api.Test; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.nio.ByteBuffer; +import java.nio.charset.Charset; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Asserts the {@code Accept} header this client sends, and that a caller can still choose their own. + * + *

The generated protocol methods for the two operations that return no content declare no + * {@code Accept} header, so azure-core would fall back to the wildcard. The AutoRest-generated + * client this replaces sent {@code application/json} on every operation regardless of response + * shape, so the client sets it for those two to keep the bytes on the wire unchanged.

+ * + *

That default must not cap a caller who wants something else: a policy added with + * {@link CommunicationIdentityClientBuilder#addPolicy(HttpPipelinePolicy)} is the supported way to + * customise a request, and its value has to reach the wire.

+ * + *

What makes that hold is ordering rather than a conditional. The client sets the header while + * constructing the request; pipeline policies run afterwards, so a caller's policy overwrites it. + * Setting the same header from inside the pipeline instead - with {@code AddHeadersPolicy}, whose + * {@code setAllHttpHeaders} overwrites - would clobber the caller's choice depending on where it + * sat in the pipeline, and would fail these assertions.

+ * + *

Capture is at the transport layer, so the assertions are on the request that would be sent + * rather than on an intermediate representation.

+ */ +public class CommunicationIdentityRequestHeaderTests { + + private static final String FAKE_CONNECTION_STRING + = "endpoint=https://localhost/;accesskey=" + "cHJvYmVwcm9iZXByb2JlcHJvYmVwcm9iZXByb2JlcHJvYmU="; + + private static final CommunicationUserIdentifier USER = new CommunicationUserIdentifier( + "8:acs:00000000-0000-0000-0000-000000000000_00000000-0000-0000-0000-000000000000"); + + private static final class CapturingHttpClient implements HttpClient { + private volatile String accept; + + @Override + public Mono send(HttpRequest request) { + this.accept = request.getHeaders().getValue(HttpHeaderName.ACCEPT); + return Mono.just(new NoContentResponse(request)); + } + + @Override + public HttpResponse sendSync(HttpRequest request, Context context) { + this.accept = request.getHeaders().getValue(HttpHeaderName.ACCEPT); + return new NoContentResponse(request); + } + } + + private static final class NoContentResponse extends HttpResponse { + NoContentResponse(HttpRequest request) { + super(request); + } + + @Override + public int getStatusCode() { + return 204; + } + + @Override + public String getHeaderValue(String name) { + return null; + } + + @Override + public HttpHeaders getHeaders() { + return new HttpHeaders(); + } + + @Override + public Flux getBody() { + return Flux.empty(); + } + + @Override + public Mono getBodyAsByteArray() { + return Mono.just(new byte[0]); + } + + @Override + public Mono getBodyAsString() { + return Mono.just(""); + } + + @Override + public Mono getBodyAsString(Charset charset) { + return Mono.just(""); + } + } + + /** The supported way for a caller to customise a request. */ + private static HttpPipelinePolicy acceptOverridePolicy() { + return new HttpPipelinePolicy() { + @Override + public Mono process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) { + context.getHttpRequest().getHeaders().set(HttpHeaderName.ACCEPT, "application/custom"); + return next.process(); + } + + @Override + public HttpResponse processSync(HttpPipelineCallContext context, HttpPipelineNextSyncPolicy next) { + context.getHttpRequest().getHeaders().set(HttpHeaderName.ACCEPT, "application/custom"); + return next.processSync(); + } + }; + } + + private static CommunicationIdentityClient clientWithOverride(CapturingHttpClient transport) { + return new CommunicationIdentityClientBuilder().connectionString(FAKE_CONNECTION_STRING) + .httpClient(transport) + .addPolicy(acceptOverridePolicy()) + .buildClient(); + } + + private static CommunicationIdentityClient client(CapturingHttpClient transport) { + return new CommunicationIdentityClientBuilder().connectionString(FAKE_CONNECTION_STRING) + .httpClient(transport) + .buildClient(); + } + + private static CommunicationIdentityAsyncClient asyncClient(CapturingHttpClient transport) { + return new CommunicationIdentityClientBuilder().connectionString(FAKE_CONNECTION_STRING) + .httpClient(transport) + .buildAsyncClient(); + } + + @Test + public void deleteUserSendsJsonAcceptByDefault() { + CapturingHttpClient transport = new CapturingHttpClient(); + client(transport).deleteUserWithResponse(USER, Context.NONE); + + assertEquals("application/json", transport.accept); + } + + @Test + public void revokeTokensSendsJsonAcceptByDefault() { + CapturingHttpClient transport = new CapturingHttpClient(); + client(transport).revokeTokensWithResponse(USER, Context.NONE); + + assertEquals("application/json", transport.accept); + } + + @Test + public void deleteUserSendsJsonAcceptByDefaultAsync() { + CapturingHttpClient transport = new CapturingHttpClient(); + asyncClient(transport).deleteUser(USER).block(); + + assertEquals("application/json", transport.accept); + } + + @Test + public void revokeTokensSendsJsonAcceptByDefaultAsync() { + CapturingHttpClient transport = new CapturingHttpClient(); + asyncClient(transport).revokeTokens(USER).block(); + + assertEquals("application/json", transport.accept); + } + + @Test + public void callerPolicyChoosesAcceptOnDeleteUser() { + CapturingHttpClient transport = new CapturingHttpClient(); + clientWithOverride(transport).deleteUserWithResponse(USER, Context.NONE); + + assertEquals("application/custom", transport.accept); + } + + @Test + public void callerPolicyChoosesAcceptOnRevokeTokens() { + CapturingHttpClient transport = new CapturingHttpClient(); + clientWithOverride(transport).revokeTokensWithResponse(USER, Context.NONE); + + assertEquals("application/custom", transport.accept); + } +} diff --git a/sdk/communication/azure-communication-identity/src/test/java/com/azure/communication/identity/generated/IdentityClientTestBase.java b/sdk/communication/azure-communication-identity/src/test/java/com/azure/communication/identity/generated/IdentityClientTestBase.java new file mode 100644 index 0000000000000..06800bd1a6683 --- /dev/null +++ b/sdk/communication/azure-communication-identity/src/test/java/com/azure/communication/identity/generated/IdentityClientTestBase.java @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.communication.identity.generated; + +// The Java test files under 'generated' package are generated for your reference. +// If you wish to modify these files, please copy them out of the 'generated' package, and modify there. +// See https://aka.ms/azsdk/dpg/java/tests for guide on adding a test. + +import com.azure.communication.identity.IdentityClientBuilder; +import com.azure.communication.identity.IdentityOperationsClient; +import com.azure.communication.identity.TeamsExtensionOperationsClient; +import com.azure.communication.identity.TeamsUserOperationsClient; +import com.azure.core.http.policy.HttpLogDetailLevel; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.test.TestMode; +import com.azure.core.test.TestProxyTestBase; +import com.azure.core.util.Configuration; + +class IdentityClientTestBase extends TestProxyTestBase { + protected IdentityOperationsClient identityOperationsClient; + + protected TeamsUserOperationsClient teamsUserOperationsClient; + + protected TeamsExtensionOperationsClient teamsExtensionOperationsClient; + + @Override + protected void beforeTest() { + IdentityClientBuilder identityOperationsClientbuilder + = new IdentityClientBuilder().endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "endpoint")) + .httpClient(getHttpClientOrUsePlayback(getHttpClients().findFirst().orElse(null))) + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)); + if (getTestMode() == TestMode.RECORD) { + identityOperationsClientbuilder.addPolicy(interceptorManager.getRecordPolicy()); + } + identityOperationsClient = identityOperationsClientbuilder.buildIdentityOperationsClient(); + + IdentityClientBuilder teamsUserOperationsClientbuilder + = new IdentityClientBuilder().endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "endpoint")) + .httpClient(getHttpClientOrUsePlayback(getHttpClients().findFirst().orElse(null))) + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)); + if (getTestMode() == TestMode.RECORD) { + teamsUserOperationsClientbuilder.addPolicy(interceptorManager.getRecordPolicy()); + } + teamsUserOperationsClient = teamsUserOperationsClientbuilder.buildTeamsUserOperationsClient(); + + IdentityClientBuilder teamsExtensionOperationsClientbuilder + = new IdentityClientBuilder().endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "endpoint")) + .httpClient(getHttpClientOrUsePlayback(getHttpClients().findFirst().orElse(null))) + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)); + if (getTestMode() == TestMode.RECORD) { + teamsExtensionOperationsClientbuilder.addPolicy(interceptorManager.getRecordPolicy()); + } + teamsExtensionOperationsClient = teamsExtensionOperationsClientbuilder.buildTeamsExtensionOperationsClient(); + + } +} diff --git a/sdk/communication/azure-communication-identity/swagger/README.md b/sdk/communication/azure-communication-identity/swagger/README.md deleted file mode 100644 index c0a8fe462bf6d..0000000000000 --- a/sdk/communication/azure-communication-identity/swagger/README.md +++ /dev/null @@ -1,80 +0,0 @@ -# Azure Communication Identity library for Java - -> see https://aka.ms/autorest - -This is the AutoRest configuration file for Communication Identity ---- -## Getting Started - -To build the SDK for Communication Identity library, simply [Install AutoRest](https://aka.ms/autorest) and in this folder, run: -> `autorest --java` - -To see additional help and options, run: -> `autorest --help` - -### Setup -```ps -npm install -g autorest -``` - -### Generation -```ps -cd -autorest --java -``` - -### Code generation settings -``` yaml -java: true -output-folder: ..\ -use: '@autorest/java@4.1.62' -tag: package-2023-10 -require: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/5797d78f04cd8ca773be82d2c99a3294009b3f0a/specification/communication/data-plane/Identity/readme.md -add-context-parameter: true -license-header: MICROSOFT_MIT_SMALL -namespace: com.azure.communication.identity -custom-types: CommunicationTokenScope,GetTokenForTeamsUserOptions -custom-types-subpackage: models -models-subpackage: implementation.models -customization-class: src/main/java/TeamsUserExchangeTokenRequestCustomization.java -custom-strongly-typed-header-deserialization: true -generic-response-type: true -sync-methods: all -disable-client-builder: true -generate-client-as-impl: true -service-interface-as-public: true -context-client-method-parameter: true -enable-sync-stack: true -stream-style-serialization: true -directive: -- rename-model: - from: TeamsUserExchangeTokenRequest - to: GetTokenForTeamsUserOptions -``` - -### Rename CommunicationIdentityTokenScope to CommunicationTokenScope -```yaml -directive: - - from: swagger-document - where: $.definitions.CommunicationIdentityTokenScope - transform: > - $["x-ms-enum"].name = "CommunicationTokenScope"; -``` - -### Directive changing GetTokenForTeamsUserOptions to required properties and use x-ms-client-name -```yaml -directive: - - from: swagger-document - where: $.definitions.GetTokenForTeamsUserOptions - transform: > - $.required = [ "token", "appId", "userId" ]; - - $.properties.token["x-ms-client-name"] = "teamsUserAadToken"; - $.properties.token.description = "Azure AD access token of a Teams User."; - - $.properties.appId["x-ms-client-name"] = "clientId"; - $.properties.appId.description = "Client ID of an Azure AD application."; - - $.properties.userId["x-ms-client-name"] = "userObjectId"; - $.properties.userId.description = "Object ID of an Azure AD user (Teams User)."; -``` diff --git a/sdk/communication/azure-communication-identity/swagger/pom.xml b/sdk/communication/azure-communication-identity/swagger/pom.xml deleted file mode 100644 index e5b4d3b312a7a..0000000000000 --- a/sdk/communication/azure-communication-identity/swagger/pom.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - 4.0.0 - - - com.azure - azure-code-customization-parent - 1.0.0-beta.1 - ../../../parents/azure-code-customization-parent - - - Microsoft Azure Communication Services Identity client for Java - This package contains client functionality for Microsoft Azure Communication Services Identity - - com.azure.tools - azure-communication-identity-autorest-customization - 1.2.0-beta.2 - jar - diff --git a/sdk/communication/azure-communication-identity/swagger/src/main/java/TeamsUserExchangeTokenRequestCustomization.java b/sdk/communication/azure-communication-identity/swagger/src/main/java/TeamsUserExchangeTokenRequestCustomization.java deleted file mode 100644 index 8b6d4618122d7..0000000000000 --- a/sdk/communication/azure-communication-identity/swagger/src/main/java/TeamsUserExchangeTokenRequestCustomization.java +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -import com.azure.autorest.customization.Customization; -import com.azure.autorest.customization.LibraryCustomization; -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.Modifier; -import com.github.javaparser.ast.Node; -import com.github.javaparser.javadoc.Javadoc; -import com.github.javaparser.javadoc.description.JavadocDescription; -import org.slf4j.Logger; -/** - * Customizations for ASC Identity CTE swagger code generation. - */ -public class TeamsUserExchangeTokenRequestCustomization extends Customization { - - @Override - public void customize(LibraryCustomization libraryCustomization, Logger logger) { - libraryCustomization.getClass("com.azure.communication.identity.models", "GetTokenForTeamsUserOptions") - .customizeAst(ast -> { - ast.addImport("com.azure.communication.identity.CommunicationIdentityAsyncClient"); - ast.addImport("com.azure.communication.identity.CommunicationIdentityClient"); - - ast.getClassByName("GetTokenForTeamsUserOptions").ifPresent(clazz -> { - clazz.setJavadocComment("Options class for configuring the " - + "{@link CommunicationIdentityAsyncClient#getTokenForTeamsUser(GetTokenForTeamsUserOptions)} " - + "and {@link CommunicationIdentityClient#getTokenForTeamsUser(GetTokenForTeamsUserOptions)} " - + "methods."); - - clazz.getAnnotationByName("Fluent").ifPresent(Node::remove); - clazz.addMarkerAnnotation("Immutable"); - - clazz.getMethodsByName("setTeamsUserAadToken").forEach(Node::remove); - clazz.getMethodsByName("setClientId").forEach(Node::remove); - clazz.getMethodsByName("setUserObjectId").forEach(Node::remove); - - clazz.getDefaultConstructor().ifPresent(ctor -> { - ctor.addParameter("String", "teamsUserAadToken") - .addParameter("String", "clientId") - .addParameter("String", "userObjectId") - .setBody(StaticJavaParser.parseBlock("{ this.teamsUserAadToken = teamsUserAadToken;" - + "this.clientId = clientId; this.userObjectId = userObjectId; }")) - .setJavadocComment(new Javadoc(JavadocDescription.parseText( - "Constructor of {@link GetTokenForTeamsUserOptions}.")) - .addBlockTag("param", "teamsUserAadToken", "Azure AD access token of a Teams User.") - .addBlockTag("param", "clientId", "Client ID of an Azure AD application to be verified against the appId claim in the Azure AD access token.") - .addBlockTag("param", "userObjectId", "Object ID of an Azure AD user (Teams User) to be verified against the OID claim in the Azure AD access token.")); - }); - - clazz.addConstructor(Modifier.Keyword.PRIVATE) - .setJavadocComment("Private constructor for deserialization"); - }); - }); - } -} diff --git a/sdk/communication/azure-communication-identity/tsp-location.yaml b/sdk/communication/azure-communication-identity/tsp-location.yaml new file mode 100644 index 0000000000000..ffe6b6c58998d --- /dev/null +++ b/sdk/communication/azure-communication-identity/tsp-location.yaml @@ -0,0 +1,4 @@ +directory: specification/communication/data-plane/Identity +commit: 1893171028aed5a757fc78c2d4aa439c14df4afc +repo: Azure/azure-rest-api-specs +additionalDirectories: