繁体   English   中英

使用 Microsoft Graph API (PHP) 创建用户

[英]Creating users using the Microsoft Graph API (PHP)

问题

我正在尝试构建一个与Microsoft Graph API集成的应用程序。

我在 Azure 中有一个管理员帐户,并通过门户设置了一个新应用程序。 我已经下载并安装了PHP SDK ,并设法设置了所有内容,以便成功获得用户。

我可以登录应用程序并授予使用我的信息的权限(我请求的权限是Directory.ReadWrite.All ,但即使只是请求User.ReadWrite.All对我不起作用),但是,我的问题似乎是我无法访问其他用户。

以下仅返回我自己的用户:

$graph = new Graph();
$graph->setAccessToken('/* SOMETOKEN */');
$users = $graph->createRequest('GET', '/users')
    ->setReturnType(User::class)
    ->execute();

发布新用户返回 404 错误:

$newUser = new User();
$newUser->setAccountEnabled(true);
$newUser->setGivenName('first_name');
$newUser->setSurname('last_name');
$newUser->setUserPrincipalName('some.email@address.com');

$password = new PasswordProfile();
$password->setPassword('some_password');
$newUser->setPasswordProfile($password);

$user = $graph->createRequest('POST', '/users')
    ->attachBody($newUser)
    ->execute();

回报:

{
    "error": {
        "code": "",
        "message": "No HTTP resource was found that matches the request URI 'https://outlook.office365.com:444/profile/v1.0/users('CID:a8ef4446a149de4d')/profile?api-version=AGSV1-internal'.",
        "innerError": {
            "date": "/* timestamp */",
            "request-id": "/* an id */",
            "client-request-id": "/* an id */"
        }
    }
}

即使尝试使用 Microsoft 的Graph Explorer也会遇到同样的错误。

我是否认为这可能是帐户设置问题?

更新

这是 Graph Explorer 返回的错误消息

{
    "error": {
        "code": "",
        "message": "No HTTP resource was found that matches the request URI 'https://outlook.office365.com:444/profile/v1.0/users('CID:a8ef4446a149de4d')/profile?api-version=AGSV1-internal'.",
        "innerError": {
            "date": "2020-11-30T16:51:41",
            "request-id": "743030b4-8835-4a9f-9e3e-d35919a1c289",
            "client-request-id": "c40cd440-d873-ba38-dce7-8669bc561e64"
        }
    }
}

我已经解决了这个问题。

问题

问题出在许可请求中。 我的应用程序设置为允许个人帐户以及工作/学校帐户。 使用个人帐户登录时,我的用户无法授予*.ReadWrite*.All权限。

当我从身份验证请求中获取令牌时,它只有User.Read权限。

访问所有工作用户所需的步骤

  1. 将 Azure 中的应用更改为仅接受工作/学校帐户
  2. 当我的应用程序尝试进行身份验证时,我需要使用工作/学校帐户登录
  3. 授予User.Read.All的权限现在应该可以工作了
  4. 点击/users端点应该返回所有用户

为了让写入工作,我需要注册一个合作伙伴中心 MPN ID并将其与我在 Azure 中的应用程序相关联。

暂无
暂无

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

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