如何通过Graph API获取用户的操作系统?

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

我正在尝试获取用户用于登录的设备。我可以使用以下查询通过 Graph API 中的审计日志获取用户的详细信息:

https://graph.microsoft.com/v1.0/auditLogs/signIns

    "value": [
        {
            "id": "xxxxx-xxxx-xxxxx",
            "createdDateTime": "2023-03-16T10:31:57Z",
            "userDisplayName": "xxxxx",
            "userPrincipalName": "xxxxx",
            "userId": "xxxx-xxxxx-xxxx",
            "appId": "xxxx-xxxxx-xxxx",
            "appDisplayName": "xxxxx",
            "ipAddress": "xxxx.xxx.xx.xxx",
            "clientAppUsed": "Browser",
            "deviceDetail": {
                "deviceId": "",
                "displayName": "",
                "operatingSystem": "Windows 10",
                "browser": "Edge 111.0.1661",
                "isCompliant": false,
                "isManaged": false,
                "trustType": ""
            },
     ]

我只想在 deviceDetail 下获取操作系统,但我无法在查询中过滤它。谁能帮我找到正确的查询来获取用户的操作系统?谢谢!

operating-system microsoft-graph-api
1个回答
0
投票

要通过 Microsoft Graph API 获取用户的操作系统,您可以使用 deviceManagementManagedDevices 端点。此端点提供有关与用户关联的托管设备的信息,包括他们的操作系统。

这是使用 Microsoft Graph JavaScript 客户端库的示例代码:

// Initialize the Microsoft Graph client
const client = MicrosoftGraph.Client.init({
    authProvider: (done) => {
        // Authenticate using the Microsoft Authentication Library (MSAL)
        // See https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-authentication-javascript
        // for more information on how to authenticate using MSAL
        done(null, accessToken);
    }
});

// Get the managed devices associated with the specified user
client
    .api(`/users/{userId}/deviceManagement/managedDevices`)
    .version('beta')
    .get((err, res) => {
        if (err) {
            console.error(err);
            return;
        }

        // Filter the list of devices to find the device that is currently being used by the user
        const currentDevice = res.value.find(device => device.deviceName === '{deviceName}');

        // Check if the current device was found
        if (currentDevice) {
            console.log(`Operating system: ${currentDevice.operatingSystem}`);
        } else {
            console.log('Current device not found.');
        }
    });

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