我目前正在开发一个与 Graph API 通信的应用程序。我没有任何后端,只有一个 SPA。我使用 npm 包@microsoft/microsoft-graph-client。
该应用程序应该能够更改 givenName,AD 用户的姓氏。
一开始我创建了一个新的 AuthCodeMSALBrowserAuthenticationProvider 实例并将其与图形客户端一起使用,我不确定使用的范围是否正确:
const authProvider = new AuthCodeMSALBrowserAuthenticationProvider(
this.msalService.instance as PublicClientApplication,
{
account: this.msalService.instance.getActiveAccount()!,
scopes: ['User.ReadWrite.All'],
interactionType: InteractionType.Redirect,
}
);
this.graphClient = Client.initWithMiddleware({
authProvider: authProvider,
defaultVersion: 'beta',
});
我的电话看起来像这样
const result = await this.authService.graphClient
.api(`/users/${userId}`)
.patch({
givenName: firstname,
surname: lastname
});
但是,我收到“权限不足”错误消息。
Could not update user with id 8639e42f-de7f-485a-9b18-ccd67d7b0146 {
"statusCode": 403,
"code": "Authorization_RequestDenied",
"requestId": "xy",
"date": "2022-02-03T11:45:48.000Z",
"body": "{\"code\":\"Authorization_RequestDenied\",\"message\":\"Insufficient privileges to complete the operation.\",\"innerError\":{\"date\":\"2022-02-03T12:45:48\",\"request-id\":\"xy\",\"client-request-id\":\"xy\"}}"
}