Microsoft Graph API-在具有本地帐户身份的Azure AD B2C中创建用户会出现Request_ResourceNotFound错误

问题描述 投票:0回答:1

我的目标是在Azure Active Directory B2C]中创建一个本地帐户,例如[email protected]

我想使用自己的UI,所以我开始研究如何实现API。经过研究,看来最好的方法应该是通过Microsoft Graph。

[我从遵循Manage Azure AD B2C user accounts with Microsoft Graph开始,然后正确创建了一个应用程序(不确定是否需要选择第三个选项,但看起来像是更广泛的选项):]]

enter image description here

具有以下权限(也在@Tony Ju屏幕截图之后更新:]

enter image description here

然后我创建了自己的auth provider

const { AuthenticationContext } = require('adal-node');

class AuthProvider {

    async getAccessToken() {
        return new Promise((resolve, reject) => {
            const tenant = 'tenant';
            const authority = `https://login.microsoftonline.com/${tenant}`;

            const authenticationContext = new AuthenticationContext(authority);

            const resource = 'https://graph.microsoft.com';
            const clientId = 'clientId';
            const clientSecret = 'clientSecret';

            authenticationContext.acquireTokenWithClientCredentials(
                resource,
                clientId,
                clientSecret,
                (err, tokenResponse) => {
                    if (err) {
                        console.error('error!', err);
                        return reject(err);
                    }
                    return resolve(tokenResponse.accessToken);
                },
            );
        });
    }
}

并初始化客户端

require('isomorphic-fetch'); //needed for server side request with the client
const { Client } = require('@microsoft/microsoft-graph-client');

const options = {
    authProvider: new AuthProvider(),
};
const client = Client.initWithMiddleware(options);

[Following the official documentation,我创建了一个本地帐户

const user = {
    displayName: 'John Smith',
    identities: [
        {
            signInType: 'emailAddress',
            issuer: 'MY_ISSUER.onmicrosoft.com',
            issuerAssignedId: '[email protected]',
        },
    ],
    passwordProfile: {
        password: 'df42bfe2-8060-411f-b277-06b819874573',
    },
    passwordPolicies: 'DisablePasswordExpiration',
};

client
    .api('/users')
    .post(user)
    .then(data => console.log(data))
    .catch(e => console.error(e))

并且我得到了这个“ Request_ResourceNotFound”错误

GraphError {
  statusCode: 404,
  code: 'Request_ResourceNotFound',
  message:
   'Resource \'User_30140fa1-ae7e-40b7-ad5a-ef4d0b4cd4dc\' does not exist or one of its queried reference-property objects are not present.',
  requestId: 'fbf4c987-0383-472a-bc22-c94f98710344',
  date: 2020-05-18T13:19:14.000Z,
  body:
   '{"code":"Request_ResourceNotFound","message":"Resource \'User_30140fa1-ae7e-40b7-ad5a-ef4d0b4cd4dc\' does not exist or one of its queried reference-property objects are not present.","innerError":{"request-id":"fbf4c987-0383-472a-bc22-c94f98710344","date":"2020-05-18T15:19:14"}}' }

错误无济于事,我不知道如何继续。基本配置看起来正确,因为我能够获得所有用户以及create a user in the same tenant

我想念的是什么?通过遵循官方文档,感到此类错误很奇怪。我开始认为我需要使用邀请API,但是我只想创建一个用户,而不涉及完整的电子邮件验证流程。另外,我真正需要的是官方文档,我希望它能正常工作。所以也许我这边有些问题。

我的目标是在Azure Active Directory B2C中创建一个本地帐户,例如[email protected]。我想使用自己的UI,所以我开始研究如何实现API。经过研究,看起来...

azure-active-directory microsoft-graph azure-ad-b2c
1个回答
0
投票

您的代码运行完美。我只在您的代码中更新了tenant

clientId
© www.soinside.com 2019 - 2024. All rights reserved.