gpt4 book ai didi

azure - Azure AD 中用户数据更改的通知

转载 作者:行者123 更新时间:2023-12-04 03:55:57 24 4
gpt4 key购买 nike

我在 Azure AD 中创建了一个订阅,用于在删除用​​户时接收通知。但当我删除或更新用户时,我没有收到任何通知。我收到了 201 代码,所以一切正常。我已经等了超过 24 小时了!

{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#subscriptions/$entity",
"id": "5bfc6bc2-a4bd-4e03-b420-7f5f72158dab",
"resource": "users",
"applicationId": "4547857b-a6ce-424f-8f71-d1f0c8050c59",
"changeType": "updated,deleted",
"clientState": null,
"notificationUrl": "https://8ffa2519154d.ngrok.io/azure/notifications",
"expirationDateTime": "2020-09-16T11:05:00Z",
"creatorId": "78f2eabd-f0a5-4350-b541-ef9edb47ae80",
"latestSupportedTlsVersion": "v1_2"
}

最佳答案

如果您想设置用户数据变更通知,请参阅以下步骤。

  1. 创建一个网络钩子(Hook)。我将 Azure 功能节点 httptrigger 起诉为 webhook

a.定义INotification.ts来接收通知数据

export interface INotificationResourceData {
id: string;
"@odata.type": string;
"@odata.id": string;
"@odata.etag": string;
}

export interface INotification {
subscriptionId: string;
subscriptionExpirationDateTime: string;
tenantId: string;
changeType: string;
clientState: string;
resource: string;
resourceData: INotificationResourceData;
}

export interface INotificationsPayload {
value: INotification[];
}

b.功能代码

import { AzureFunction, Context, HttpRequest } from "@azure/functions";
import { INotificationsPayload } from "../entities/INotification";

const httpTrigger: AzureFunction = async function (
context: Context,
req: HttpRequest
): Promise<void> {
context.log("HTTP trigger function processed a request.");
// Validate the subscription creation
if (req.query.validationToken) {
context.log("Validating new subscription...");
context.log("Validation token:");
context.log(req.query.validationToken);
context.res = {
headers: {
"Content-Type": "text/plain",
},
body: req.query.validationToken,
};
} else {
context.log("Received new notification from Microsoft Graph...");
context.log("Notifications: ");
const payload = req.body as INotificationsPayload;
payload.value.forEach((n, i) => {
const resourceData = JSON.stringify(n.resourceData);
context.log(` Notification #${i} `);
context.log(`----------------------------------------------------------`);
context.log(`Subscription Id : ${n.subscriptionId}`);
context.log(`Expiration : ${n.subscriptionExpirationDateTime}`);
context.log(`Change Type : ${n.changeType}`);
context.log(`Client State : ${n.clientState}`);
context.log(`Resource : ${n.resource}`);
context.log(`Resource Data : ${resourceData}`);
context.log(`----------------------------------------------------------`);
});
context.res = { body: "" };
}
};

export default httpTrigger;

  • 创建订阅。例如,为用户资源创建订阅
  • Post  https://graph.microsoft.com/v1.0/subscriptions

    Body:
    {
    "changeType": "updated,deleted",
    "notificationUrl": "https://2f148f1102ab.ngrok.io/api/Webhook",
    "resource": "/users",
    "expirationDateTime":"2020-09-17T10:27:03.4541718Z",
    "clientState": "secretClientValue",
    "latestSupportedTlsVersion": "v1_2"
    }

    当我们创建订阅时,它将通过向我们的 webhook 发送 post 请求来验证通知端点。 enter image description here回复: enter image description here

  • 测试
  • 使用 Microsoft graph 更新用户

    Patch https://graph.microsoft.com/v1.0/users/2632566d-711d-4f07-a595-afd426361b2c
    Body
    {

    "country":"US"
    }

    更新成功后,我收到如下通知 enter image description here

    更多详情请引用herehere

    关于azure - Azure AD 中用户数据更改的通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63906217/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com