gpt4 book ai didi

c# - Microsoft Graph 异常 : New password credentials must be generated using service actions

转载 作者:行者123 更新时间:2023-12-03 08:34:26 33 4
gpt4 key购买 nike

如何在创建应用程序时使用 Microsoft Graph 客户端 SDK 添加客户端 key ?

定义如下应用程序失败,并出现必须使用服务操作生成新密码凭据。异常:

var application new Application
{
DisplayName = "My app name",
PasswordCredentials = new List<PasswordCredential>
{
new PasswordCredential
{
SecretText = secretKey,
DisplayName = "Default Secret",
EndDateTime = DateTimeOffset.MaxValue,
KeyId = Guid.NewGuid(),
StartDateTime = DateTimeOffset.Now,
CustomKeyIdentifier = null,
Hint = secretKey.Substring(4)
}
}
};

await graphClient.Applications.Request().AddAsync(application);

我找到了有关如何使用 HTTP POST 执行此操作的信息,但没有找到有关使用 Microsoft Graph 客户端 SDK 时的信息。

最佳答案

找到了,只需在 documentation 中仔细查找即可.

var createdApplication = await graphClient.Applications.Request().AddAsync(application);

var passwordCredential = new PasswordCredential
{
DisplayName = "Password friendly name",
EndDateTime = DateTimeOffset.Parse("31/12/2299"), // Max allowed as far as I can tell
KeyId = Guid.NewGuid(),
StartDateTime = DateTimeOffset.Now,
CustomKeyIdentifier = null,
};

var passwordCredential = await graphClient.Applications[createdApplication.Id]
.AddPassword(passwordCredential)
.Request()
.PostAsync();

返回值passwordCredential保存 secret 文本。

关于c# - Microsoft Graph 异常 : New password credentials must be generated using service actions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64369597/

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