diff --git a/connectors/microsoft-teams/element-templates/hybrid/microsoft-teams-outbound-connector-hybrid.json b/connectors/microsoft-teams/element-templates/hybrid/microsoft-teams-outbound-connector-hybrid.json index a24cd4c9bf..507fec2ebc 100644 --- a/connectors/microsoft-teams/element-templates/hybrid/microsoft-teams-outbound-connector-hybrid.json +++ b/connectors/microsoft-teams/element-templates/hybrid/microsoft-teams-outbound-connector-hybrid.json @@ -226,11 +226,8 @@ }, { "id" : "authentication.refresh.clientSecret", "label" : "Client secret", - "description" : "The secret value of the Azure AD application", - "optional" : false, - "constraints" : { - "notEmpty" : true - }, + "description" : "The secret value of the Azure AD application; optional, depends on whether the client is public or private", + "optional" : true, "feel" : "optional", "group" : "authentication", "binding" : { @@ -386,6 +383,10 @@ }, "condition" : { "allMatch" : [ { + "property" : "data.createChat.chatType", + "equals" : "group", + "type" : "simple" + }, { "property" : "data.chatMethod", "equals" : "createChat", "type" : "simple" diff --git a/connectors/microsoft-teams/element-templates/microsoft-teams-outbound-connector.json b/connectors/microsoft-teams/element-templates/microsoft-teams-outbound-connector.json index da99204c46..e60a902743 100644 --- a/connectors/microsoft-teams/element-templates/microsoft-teams-outbound-connector.json +++ b/connectors/microsoft-teams/element-templates/microsoft-teams-outbound-connector.json @@ -221,11 +221,8 @@ }, { "id" : "authentication.refresh.clientSecret", "label" : "Client secret", - "description" : "The secret value of the Azure AD application", - "optional" : false, - "constraints" : { - "notEmpty" : true - }, + "description" : "The secret value of the Azure AD application; optional, depends on whether the client is public or private", + "optional" : true, "feel" : "optional", "group" : "authentication", "binding" : { @@ -381,6 +378,10 @@ }, "condition" : { "allMatch" : [ { + "property" : "data.createChat.chatType", + "equals" : "group", + "type" : "simple" + }, { "property" : "data.chatMethod", "equals" : "createChat", "type" : "simple" diff --git a/connectors/microsoft-teams/src/main/java/io/camunda/connector/model/Member.java b/connectors/microsoft-teams/src/main/java/io/camunda/connector/model/Member.java index 58b0247973..04f2fbadae 100644 --- a/connectors/microsoft-teams/src/main/java/io/camunda/connector/model/Member.java +++ b/connectors/microsoft-teams/src/main/java/io/camunda/connector/model/Member.java @@ -6,6 +6,7 @@ */ package io.camunda.connector.model; +import com.fasterxml.jackson.annotation.JsonAlias; import jakarta.validation.constraints.AssertTrue; import jakarta.validation.constraints.NotNull; import java.util.List; @@ -15,11 +16,13 @@ public class Member { public static final String USER_DATA_BIND = "user@odata.bind"; - public static final String USER_DATA_TYPE = "@odata.type"; public static final List OWNER_ROLES = List.of("owner"); private String userId; + + @JsonAlias(value = {"userPrincipalName", "principalName"}) private String userPrincipalName; + @NotNull private List roles; @AssertTrue(message = "Missing one of properties : [userId, userPrincipalName]") diff --git a/connectors/microsoft-teams/src/main/java/io/camunda/connector/model/authentication/RefreshTokenAuthentication.java b/connectors/microsoft-teams/src/main/java/io/camunda/connector/model/authentication/RefreshTokenAuthentication.java index 2d3108e164..40a4d18d4a 100644 --- a/connectors/microsoft-teams/src/main/java/io/camunda/connector/model/authentication/RefreshTokenAuthentication.java +++ b/connectors/microsoft-teams/src/main/java/io/camunda/connector/model/authentication/RefreshTokenAuthentication.java @@ -29,12 +29,13 @@ public record RefreshTokenAuthentication( label = "Tenant ID", description = "The tenant ID of the application") String tenantId, - @NotBlank - @TemplateProperty( + @TemplateProperty( group = "authentication", id = "refresh.clientSecret", label = "Client secret", - description = "The secret value of the Azure AD application") + optional = true, + description = + "The secret value of the Azure AD application; optional, depends on whether the client is public or private") String clientSecret) implements MSTeamsAuthentication { diff --git a/connectors/microsoft-teams/src/main/java/io/camunda/connector/model/request/data/CreateChat.java b/connectors/microsoft-teams/src/main/java/io/camunda/connector/model/request/data/CreateChat.java index e02d765b2c..25babfdecc 100644 --- a/connectors/microsoft-teams/src/main/java/io/camunda/connector/model/request/data/CreateChat.java +++ b/connectors/microsoft-teams/src/main/java/io/camunda/connector/model/request/data/CreateChat.java @@ -36,6 +36,10 @@ public record CreateChat( id = "createChat.topic", label = "Topic", optional = true, + condition = + @TemplateProperty.PropertyCondition( + property = "data.createChat.chatType", + equals = "group"), description = "Set topic of chat (optional)") String topic, @NotNull diff --git a/connectors/microsoft-teams/src/main/java/io/camunda/connector/suppliers/GraphServiceClientSupplier.java b/connectors/microsoft-teams/src/main/java/io/camunda/connector/suppliers/GraphServiceClientSupplier.java index 5b8a6813f6..c3163cbfee 100644 --- a/connectors/microsoft-teams/src/main/java/io/camunda/connector/suppliers/GraphServiceClientSupplier.java +++ b/connectors/microsoft-teams/src/main/java/io/camunda/connector/suppliers/GraphServiceClientSupplier.java @@ -22,8 +22,8 @@ import okhttp3.FormBody; import okhttp3.OkHttpClient; import okhttp3.Request; -import okhttp3.RequestBody; import okhttp3.Response; +import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; import reactor.core.publisher.Mono; @@ -79,29 +79,31 @@ public GraphServiceClient buildAndGetGraphServiceClient(final String token) { @NotNull private Request buildRequest(final RefreshTokenAuthentication authentication) { - RequestBody formBody = + + FormBody.Builder formBodyBuilder = new FormBody.Builder() .add(CLIENT_ID, authentication.clientId()) .add(GRANT_TYPE, REFRESH_TOKEN) - .add(CLIENT_SECRET, authentication.clientSecret()) - .add(REFRESH_TOKEN, authentication.token()) - .build(); + .add(REFRESH_TOKEN, authentication.token()); + if (StringUtils.isNoneBlank(authentication.clientSecret())) { + formBodyBuilder.add(CLIENT_SECRET, authentication.clientSecret()); + } return new Request.Builder() .url(String.format(URL, authentication.tenantId())) .header(CONTENT_TYPE, X_WWW_FORM_URLENCODED) - .post(formBody) + .post(formBodyBuilder.build()) .build(); } private String getAccessToken(final Request request) { - try (Response execute = okHttpClient.newCall(request).execute()) { - if (execute.isSuccessful()) { + try (Response response = okHttpClient.newCall(request).execute()) { + if (response.isSuccessful()) { return ObjectMapperSupplier.objectMapper() - .readTree(execute.body().string()) + .readTree(response.body().string()) .get(ACCESS_TOKEN) .asText(); } else { - throw new RuntimeException(execute.message()); + throw new RuntimeException(response.message()); } } catch (JsonProcessingException e) { throw new RuntimeException("Error while parse refresh token response", e);