microsoftgraph / microsoftgraph/msgraph-sdk-java

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

Offen
#2,285 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

status:waiting-for-triage type:feature
Vorherrschende Sprache
Java
Sterne
444
Forks
154
Ø Merge
18 Std. 28 Min.
Gemergte PRs (30 T.)
4

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem GraphServiceClient-Java-Beispiel im Issue und der verknüpften Microsoft Teams-Dokumentation zum Importieren von Nachrichten. Überprüfe die dokumentierten Einschränkungen für POST-Anfragen für Kanalnachrichten mit application-only authentication sowie die verfügbaren delegated-authentication-Optionen für headless services. Als erledigt gilt die Dokumentation eines unterstützten Authentifizierungswegs oder die Bestätigung, dass kein unterstützter Workaround existiert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java
Bereich
api
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
18/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.