Azure Graph API 邀请返回 400 错误请求

标签 azure azure-active-directory microsoft-graph-api invitation

我有一个 Azure PowerShell 函数应用程序,它可以为他们创建用户、其资源和 RBAC,并向该用户发送邀请电子邮件。它已经工作了 2 年多没有变化。 3-4 周前,它停止发送邀请电子邮件。我查明了罪魁祸首的请求并在 Postman 中模拟了它。看起来我这边没有明显的变化,邀请图 API 开始发送 400 错误请求作为响应。 以下是我的 API 调用的片段。 请求不记名 token :

curl --location --request POST 'https://login.microsoftonline.com/{{myTenantId}}/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' ' \
--header 'Cookie: brcap=0; fpc=AtYZMK7Wg2BCiTPI8GyfoR-8f7k3AQAAAJ-AsNgOAAAA; stsservicecookie=estsfd; x-ms-gateway-slice=estsfd' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'client_id={{myClientId}}' \
--data-urlencode 'client_secret={{clientSecret}}' \
--data-urlencode 'resource=https://graph.microsoft.com' \
--data-urlencode 'username={{username}}' \
--data-urlencode 'password={{userSecret}}'

此调用返回 200 OK 和以下响应:

{
    "token_type": "Bearer",
    "scope": "Directory.AccessAsUser.All User.Invite.All User.Read",
    "expires_in": "3599",
    "ext_expires_in": "3599",
    "expires_on": "1630701785",
    "not_before": "1630697885",
    "resource": "https://graph.microsoft.com",
    "access_token": "eyJ0eXAiOiJKV1QiLCJu....

然后我使用此 token 通过以下请求发送新用户邀请:

curl --location --request POST 'https://graph.microsoft.com/v1.0/invitations' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{token}}' \
--data-urlencode 'invitedUserEmailAddress={{userEmailAddress}}' \
--data-urlencode 'invitedUserDisplayName={{userName}}' \
--data-urlencode 'inviteRedirectUrl=https://portal.azure.com' \
--data-urlencode 'sendInvitationMessage=true'

这将返回 400 Bad Request 和以下错误详细信息:

{"error":{"code":"UnknownError","message":"Bad Request","innerError":{"date":"2021-09-03T14:33:51","request-id":"f5cffbdd-af17-445b-bb3f-85a59bac6f31","client-request-id":"f5cffbdd-af17-445b-bb3f-85a59bac6f31"}}}

用于获取承载 token 的应用注册具有 User.Invite.All API 权限,并且用户已分配有全局管理员角色。

我通过 Azure 支持调查了这个问题,但到目前为止我们还没有解决方案。任何如何修复它的建议将不胜感激。

最佳答案

您正在传递 url 编码变量,the documentation请注意,您需要发送 JSON 正文。我猜想支持 url 编码变量首先就是一个错误,现在已经修复了。

您的第二个脚本应如下所示:

curl --location --request POST 'https://graph.microsoft.com/v1.0/invitations' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{token}}' \
--data-raw '{"invitedUserEmailAddress": "{{userEmailAddress}}", "inviteRedirectUrl": "https://portal.azure.com"}'

注意:在 Windows 上,使用 cURL 时您可能需要使用双引号并转义 JSON 正文。

关于Azure Graph API 邀请返回 400 错误请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69050052/

相关文章:

azure - 如何使用 Oauth 2.0 将 Windows Azure 配置为身份提供者

sql-server - SQL Server 到服务总线

azure-active-directory - Azure AD 应用注册 : "AADSTS90094: The grant requires admin permission" error for permission that has "REQUIRES ADMIN" set to "No"

powershell - 如何通过命令行使用有限用户帐户更新 Azure 上的云服务

azure - 我可以查看有关我的 Azure 函数如何扩展的图表或事件日志吗?

azure - 如何通过 Graph API 为 Azure AD 创建新的 native 应用程序

azure - 如何获取Azure帐户租户ID?

python - 使用 Python 进行 MSAL 身份验证显示未经授权的客户端?

javascript - 如何使用 redux-observable 正确获取二进制图像?

java - 图形 REST API -- 阅读电子邮件 (Java) -- NoPermissionsInAccessToken