简体   繁体   English

通过 Microsoft Graph API 创建用户

[英]Creating a user via Microsoft Graph API

I am trying to perform this curl request我正在尝试执行此 curl 请求

curl --location --request POST 'https://graph.microsoft.com/v1.0/users' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {BEARER_TOKEN}' \
--data-raw '{
  "accountEnabled": true,
  "displayName": "displayName-value",
  "mailNickname": "mailNickname-value",
  "userPrincipalName": "test666@mytennant.com",
  "passwordProfile" : {
    "forceChangePasswordNextSignIn": true,
    "password": "password"
  }
}'

I keep getting我不断得到

{
    "error": {
        "code": "Authorization_RequestDenied",
        "message": "Insufficient privileges to complete the operation.",
        "innerError": {
            "date": "2020-10-23T14:01:06",
            "request-id": "caf9e0be-88fc-4a4e-a6eb-fed1ccedb90c",
            "client-request-id": "caf9e0be-88fc-4a4e-a6eb-fed1ccedb90c"
        }
    }
}

I have the following permissions set on the app registration我在应用注册时设置了以下权限在此处输入图片说明

Can someone please help me figure out what's wrong here?有人可以帮我弄清楚这里出了什么问题吗?

Based on the error you are provided it seems to be you are not having right permission to create the user.根据您提供的错误,您似乎没有创建用户的正确权限。

In the token, you are missing the permissions, so before making the graph request you need to have the token with在令牌中,您缺少权限,因此在发出图形请求之前,您需要将令牌与

User.ReadWrite.All, Directory.ReadWrite.All.

在此处输入图片说明

I made the below request, without having the required permission then I received the same error as you can see below我提出了以下请求,但没有获得所需的许可,然后我收到了与您在下面看到的相同的错误在此处输入图片说明

Then later I added the permissions and requested for the new token, then made the graph call.后来我添加了权限并请求了新令牌,然后进行了图形调用。 Now I was successfully able to create the user现在我成功地创建了用户在此处输入图片说明 在此处输入图片说明

Curl卷曲

curl --location --request POST 'https://graph.microsoft.com/v1.0/users' \
--header 'Authorization: Bearer token' \
--header 'Content-Type: application/json' \
--data-raw '{​​​​ "accountEnabled": true, "displayName": "displayName-value", "mailNickname": "mailNickname-value", "userPrincipalName": "upn-value1@xx.live", "passwordProfile" : {​​​​ "forceChangePasswordNextSignIn": true, "password": "xx@123" }​​​​ }​​​​'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM