MS 图 API 无法授予应用程序角色
MS graph API cannot grant Application roles
我无法使用图表 API 授予应用程序角色。下面是代码
代码
IConfidentialClientApplication app = ConfidentialClientFactory.SpnAuthenticate(_configuration["ClientId"],
_configuration["ClientSecret"],
_configuration["TenantId"]);
ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication: app);
Beta.GraphServiceClient graphClient = new Beta.GraphServiceClient(authProvider);
var appRoleAssignment = new Beta.AppRoleAssignment
{
AppRoleId = model.appRoleId,
ResourceId = model.resourceId,
ResourceDisplayName = "resourceDisplayName-value"
};
var respone = await graphClient.ServicePrincipals[model.servicePrincipalId].AppRoleAssignments
.Request()
.AddAsync(appRoleAssignment);
错误
Status Code: BadRequest
Microsoft.Graph.ServiceException: Code: Request_BadRequest
Message: Not a valid reference update.
Inner error:
AdditionalData:
request-id: 9e94e7e1-b4bf-415e-8aee-7d6d199dbe1b
date: 2020-04-26T06:43:59
ClientRequestId: 9e94e7e1-b4bf-415e-8aee-7d6d199dbe1b
应用角色分配功能属性
appRoleId
creationTimestamp
PrincipalDisplayName
principalId
principalDisplayName
resourceDisplayName
ResourceId
谁能帮我找出正确的代码?
我发现了问题。谢谢@juunas
更新代码:
IConfidentialClientApplication app = ConfidentialClientFactory.SpnAuthenticate(_configuration["ClientId"],_configuration["ClientSecret"],_configuration["TenantId"]);
ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication: app);
Beta.GraphServiceClient graphClient = new Beta.GraphServiceClient(authProvider);
var appRoleAssignment = new Beta.AppRoleAssignment
{
AppRoleId = model.appRoleId,
ResourceId = model.resourceId,
ResourceDisplayName = "resourceDisplayName-value",
PrincipalId = model.servicePrincipalId
};
var respone = await graphClient.ServicePrincipals[model.servicePrincipalId].AppRoleAssignments
.Request()
.AddAsync(appRoleAssignment);
我无法使用图表 API 授予应用程序角色。下面是代码
代码
IConfidentialClientApplication app = ConfidentialClientFactory.SpnAuthenticate(_configuration["ClientId"],
_configuration["ClientSecret"],
_configuration["TenantId"]);
ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication: app);
Beta.GraphServiceClient graphClient = new Beta.GraphServiceClient(authProvider);
var appRoleAssignment = new Beta.AppRoleAssignment
{
AppRoleId = model.appRoleId,
ResourceId = model.resourceId,
ResourceDisplayName = "resourceDisplayName-value"
};
var respone = await graphClient.ServicePrincipals[model.servicePrincipalId].AppRoleAssignments
.Request()
.AddAsync(appRoleAssignment);
错误
Status Code: BadRequest
Microsoft.Graph.ServiceException: Code: Request_BadRequest
Message: Not a valid reference update.
Inner error:
AdditionalData:
request-id: 9e94e7e1-b4bf-415e-8aee-7d6d199dbe1b
date: 2020-04-26T06:43:59
ClientRequestId: 9e94e7e1-b4bf-415e-8aee-7d6d199dbe1b
应用角色分配功能属性
appRoleId
creationTimestamp
PrincipalDisplayName
principalId
principalDisplayName
resourceDisplayName
ResourceId
谁能帮我找出正确的代码?
我发现了问题。谢谢@juunas
更新代码:
IConfidentialClientApplication app = ConfidentialClientFactory.SpnAuthenticate(_configuration["ClientId"],_configuration["ClientSecret"],_configuration["TenantId"]);
ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication: app);
Beta.GraphServiceClient graphClient = new Beta.GraphServiceClient(authProvider);
var appRoleAssignment = new Beta.AppRoleAssignment
{
AppRoleId = model.appRoleId,
ResourceId = model.resourceId,
ResourceDisplayName = "resourceDisplayName-value",
PrincipalId = model.servicePrincipalId
};
var respone = await graphClient.ServicePrincipals[model.servicePrincipalId].AppRoleAssignments
.Request()
.AddAsync(appRoleAssignment);