microsoftgraph / microsoftgraph/msgraph-sdk-java

POST Message to Teams Channel with Application-only Permissions Not Allowed for Regular Use Cases

未关闭
#2,285 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

status:waiting-for-triage type:feature
主要语言
Java
星标
444
派生
154
平均合并
18 小时 28 分钟
30 天内合并 PR
4

描述

Is your feature request related to a problem? Please describe the problem.

Hello,
I am attempting to use the Microsoft Graph API to send messages to a Microsoft Teams channel using application-only authentication with the following code:

import com.azure.identity.ClientSecretCredential;
import com.azure.identity.ClientSecretCredentialBuilder;
import com.microsoft.graph.models.ChatMessage;
import com.microsoft.graph.models.ItemBody;
import com.microsoft.graph.serviceclient.GraphServiceClient;

public class GraphClientExample {
    public static void main(String[] args) throws Exception {

        final String clientId = "****-2189-4dab-a9b8-28dc0f57b181";
        final String tenantId = "****-4b22-4755-a153-421da388048a";
        final String clientSecret = "F1p8Q~**************";

        final String[] scopes = new String[] { "https://graph.microsoft.com/.default" };

        final ClientSecretCredential credential = new ClientSecretCredentialBuilder()
                .clientId(clientId).tenantId(tenantId).clientSecret(clientSecret).build();

        if (null == scopes || null == credential) {
            throw new Exception("Unexpected error");
        }

        final GraphServiceClient graphClient = new GraphServiceClient(credential, scopes);

        ChatMessage chatMessage = new ChatMessage();
        ItemBody body = new ItemBody();
        body.setContent("Hello World");
        chatMessage.setBody(body);
        ChatMessage result = graphClient.teams().byTeamId("459b419d-9d5e-42cd-b59d-*********").channels().byChannelId("19%********************Gu3neGtMFiU8PSRzeaR-uL5AWU1%40thread.tacv2").messages().post(chatMessage);
    }
}

However, I am encountering the following error:
Message POST is allowed in application-only context only for import purposes. Refer to https://docs.microsoft.com/microsoftteams/platform/graph-api/import-messages/import-external-messages-to-teams for more details.
From what I understand, the Microsoft Teams API restricts POST requests in the application-only context to migration or import purposes. This means I am unable to use application-only authentication to send messages to a Teams channel.

Question:

Is there a recommended way to send messages to Microsoft Teams channels using application-only authentication in scenarios other than data migration?
If delegated permissions are required, is there an alternative method to authenticate using delegated permissions in a headless application or server environment?
Any insights or workarounds would be greatly appreciated!

Thank you!

Describe the solution you'd like.

Question:

Is there a recommended way to send messages to Microsoft Teams channels using application-only authentication in scenarios other than data migration?
If delegated permissions are required, is there an alternative method to authenticate using delegated permissions in a headless application or server environment?
Any insights or workarounds would be greatly appreciated!

Additional context?

No response

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 issue 中的 GraphServiceClient Java 示例以及链接的 Microsoft Teams 导入消息文档开始。验证文档中针对使用 application-only authentication 的频道消息 POST 请求所规定的限制,以及 headless services 可用的 delegated authentication 选项。完成标准是记录一种受支持的身份验证路径,或确认不存在受支持的 workaround。

由索引模型根据 Issue 内容生成。

评估

技术栈
java
领域
api
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
18/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。