gpt4 book ai didi

c# - MS graph API Oauth2PermissionGrants 无法授予角色

转载 作者:行者123 更新时间:2023-12-02 07:58:24 27 4
gpt4 key购买 nike

使用下面的代码我可以第一次批准给予管理员同意。但是当我第二次调用代码时。代码返回错误。

示例:

我可以在第一个请求时授予 User.Read.All 访问权限。但是,当我想向管理员授予第二个角色 AccessReview.Read.All 的同意时,请求会出现以下错误

代码

 IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create("Client ID")
.WithClientSecret("Client Secret")
.WithTenantId("Tenant ID")
.Build();



string scopes = "https://graph.microsoft.com/.default";
ClientCredentialProvider authProvider = new ClientCredentialProvider(app, scopes);
Beta.GraphServiceClient graphClient = new Beta.GraphServiceClient(authProvider);

Beta.OAuth2PermissionGrant test = new Beta.OAuth2PermissionGrant { ClientId = model.clientId, ConsentType = model.consentType, ExpiryTime = model.expiryTime, ResourceId = model.resourceId, Scope = model.scope };
var response = await graphClient.Oauth2PermissionGrants
.Request()
.AddAsync(test);

return response.ToString();

错误

Status Code: Conflict
Microsoft.Graph.ServiceException: Code: Request_MultipleObjectsWithSameKeyValue
Message: Permission entry already exists.
Inner error:
AdditionalData:
request-id: b9e44bc2-7588-4390-a3ca-9abdc213d930
date: 2020-04-23T19:43:03
ClientRequestId: b9e44bc2-7588-4390-a3ca-9abdc213d930

最佳答案

您不能两次添加相同的权限授予,正如错误消息所示,权限条目已存在。如果想更新权限授予,可以使用update方法:

var oAuth2PermissionGrant = new OAuth2PermissionGrant
{
Scope = "scope-value"
};

await graphClient.OAuth2Permissiongrants["{id}"]
.Request()
.UpdateAsync(oAuth2PermissionGrant);

引用:

https://learn.microsoft.com/en-us/graph/api/oauth2permissiongrant-update?view=graph-rest-beta&tabs=http

关于c# - MS graph API Oauth2PermissionGrants 无法授予角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61395852/

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