Microsoft Graph API -401在创建聊天时未经授权

发布于 2025-01-29 18:20:55 字数 3159 浏览 3 评论 0原文

我使用Graph API v1.0来创建一对一的聊天,但是我找到了一些帐户获取401结果。 ' 允许。

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#oauth2PermissionGrants",
    "value": [
        {
            "clientId": "9fc4855b-4d7e-443b-a8f0-282690a55a73",
            "consentType": "Principal",
            "id": "W4XEn35NO0So8CgmkKVacwsSh1fUKDpBhq1AxEmfwg74z92MWfk9ToJPj-kyp8I8",
            "principalId": "8cddcff8-f959-4e3d-824f-8fe932a7c23c",
            "resourceId": "5787120b-28d4-413a-86ad-40c4499fc20e",
            "scope": " offline_access openid profile email User.Read User.ReadWrite User.ReadBasic.All Chat.ReadWrite Chat.Create Presence.Read Presence.Read.All ChatMessage.Read ChatMessage.Send"
        },
        {
            "clientId": "d39356e1-6d20-4d19-ad54-5278e19b94ec",
            "consentType": "Principal",
            "id": "4VaT0yBtGU2tVFJ44ZuU7AsSh1fUKDpBhq1AxEmfwg74z92MWfk9ToJPj-kyp8I8",
            "principalId": "8cddcff8-f959-4e3d-824f-8fe932a7c23c",
            "resourceId": "5787120b-28d4-413a-86ad-40c4499fc20e",
            "scope": " offline_access openid profile email User.Read User.ReadWrite User.ReadBasic.All Chat.ReadWrite Chat.Create Presence.Read Presence.Read.All ChatMessage.Read ChatMessage.Send"
        },
        {
            "clientId": "c81831d1-608e-43fa-abd4-3a09e523cb3c",
            "consentType": "Principal",
            "id": "0TEYyI5g-kOr1DoJ5SPLPAsSh1fUKDpBhq1AxEmfwg74z92MWfk9ToJPj-kyp8I8",
            "principalId": "8cddcff8-f959-4e3d-824f-8fe932a7c23c",
            "resourceId": "5787120b-28d4-413a-86ad-40c4499fc20e",
            "scope": " offline_access openid profile email User.Read User.ReadWrite User.ReadBasic.All Chat.ReadWrite Chat.Create Presence.Read Presence.Read.All ChatMessage.Read ChatMessage.Send Files.Read Files.ReadWrite Files.Read.All Files.ReadWrite.All Sites.Read.All Sites.ReadWrite.All"
        }
    ]
}

当我发布“ https://graph.microsoft.com/v1.0/chats”时 将其设置为这样的身体

{"members":[
        {   "[email protected]":"https://graph.microsoft.com/v1.0/users('8cddcff8-f959-4e3d-824f-8fe932a7c23c')",
            "@odata.type":"#microsoft.graph.aadUserConversationMember",
            "roles":["owner"]},
        {   "[email protected]":"https://graph.microsoft.com/v1.0/users('636f150e-f73c-44d6-be0c-4d543b2b4e5d')",
            "@odata.type":"#microsoft.graph.aadUserConversationMember",
            "roles":["owner"]
        }
    ],
    "chatType":"oneOnOne"
}

响应401身份验证失败。

{
    "error": {
        "code": "Unauthorized",
        "message": "Authentication failed.",
        "innerError": {
            "date": "2022-05-17T08:41:05",
            "request-id": "de03512e-b97d-4229-b1ce-a73a61ed4f3d",
            "client-request-id": "de03512e-b97d-4229-b1ce-a73a61ed4f3d"
        }
    }
}

当我替换另一个帐户的令牌&时, TeamSuserid,然后重试,它返回还可以! 你能帮我检查原因吗?

I using the graph API v1.0 to create the one-to-One chat,but I found some account get 401 results.I check the Permission from the Api '/me/oauth2PermissionGrants',and I can find the 'Chat.Create' permission.

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#oauth2PermissionGrants",
    "value": [
        {
            "clientId": "9fc4855b-4d7e-443b-a8f0-282690a55a73",
            "consentType": "Principal",
            "id": "W4XEn35NO0So8CgmkKVacwsSh1fUKDpBhq1AxEmfwg74z92MWfk9ToJPj-kyp8I8",
            "principalId": "8cddcff8-f959-4e3d-824f-8fe932a7c23c",
            "resourceId": "5787120b-28d4-413a-86ad-40c4499fc20e",
            "scope": " offline_access openid profile email User.Read User.ReadWrite User.ReadBasic.All Chat.ReadWrite Chat.Create Presence.Read Presence.Read.All ChatMessage.Read ChatMessage.Send"
        },
        {
            "clientId": "d39356e1-6d20-4d19-ad54-5278e19b94ec",
            "consentType": "Principal",
            "id": "4VaT0yBtGU2tVFJ44ZuU7AsSh1fUKDpBhq1AxEmfwg74z92MWfk9ToJPj-kyp8I8",
            "principalId": "8cddcff8-f959-4e3d-824f-8fe932a7c23c",
            "resourceId": "5787120b-28d4-413a-86ad-40c4499fc20e",
            "scope": " offline_access openid profile email User.Read User.ReadWrite User.ReadBasic.All Chat.ReadWrite Chat.Create Presence.Read Presence.Read.All ChatMessage.Read ChatMessage.Send"
        },
        {
            "clientId": "c81831d1-608e-43fa-abd4-3a09e523cb3c",
            "consentType": "Principal",
            "id": "0TEYyI5g-kOr1DoJ5SPLPAsSh1fUKDpBhq1AxEmfwg74z92MWfk9ToJPj-kyp8I8",
            "principalId": "8cddcff8-f959-4e3d-824f-8fe932a7c23c",
            "resourceId": "5787120b-28d4-413a-86ad-40c4499fc20e",
            "scope": " offline_access openid profile email User.Read User.ReadWrite User.ReadBasic.All Chat.ReadWrite Chat.Create Presence.Read Presence.Read.All ChatMessage.Read ChatMessage.Send Files.Read Files.ReadWrite Files.Read.All Files.ReadWrite.All Sites.Read.All Sites.ReadWrite.All"
        }
    ]
}

When I post "https://graph.microsoft.com/v1.0/chats",
set the body like this

{"members":[
        {   "[email protected]":"https://graph.microsoft.com/v1.0/users('8cddcff8-f959-4e3d-824f-8fe932a7c23c')",
            "@odata.type":"#microsoft.graph.aadUserConversationMember",
            "roles":["owner"]},
        {   "[email protected]":"https://graph.microsoft.com/v1.0/users('636f150e-f73c-44d6-be0c-4d543b2b4e5d')",
            "@odata.type":"#microsoft.graph.aadUserConversationMember",
            "roles":["owner"]
        }
    ],
    "chatType":"oneOnOne"
}

It response 401 Authentication failed

{
    "error": {
        "code": "Unauthorized",
        "message": "Authentication failed.",
        "innerError": {
            "date": "2022-05-17T08:41:05",
            "request-id": "de03512e-b97d-4229-b1ce-a73a61ed4f3d",
            "client-request-id": "de03512e-b97d-4229-b1ce-a73a61ed4f3d"
        }
    }
}

When I replace another account's token & teamsUserId and try again ,It returns Ok!
Can you help me check the reason?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无风消散 2025-02-05 18:20:55

首先检查您的应用ID机密并确认
其次检查您要添加的用户是否已授权您的应用程序。
第三检查访问令牌您需要根据您发送到图的令牌的范围和权限
如果您使用的是应用程序令牌,请使用默认范围,并检查您是否添加了CHAT。

First of all check your app id secret and confirm
secondly check that the users you are trying to add have authorized your application.
thirdly check for access token you need scopes and permission according to the token you are sending to the graph
If you are using application token , use default scope and check whether you have added the chat.create application permission else if you are using token on behalf of user you need delegated permission for chat.create application

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文