gpt4 book ai didi

.net - 将角色分配给私有(private)应用程序中的客户端 key

转载 作者:行者123 更新时间:2023-12-03 05:41:24 25 4
gpt4 key购买 nike

在本地应用程序中,我们尝试访问我们在 Azure 中作为私有(private)应用程序托管的 API。我们通过 AAD 为用户分配角色,并且角色在应用程序 list 中定义

"appRoles": [    
...
{
"allowedMemberTypes": [
"User",
"Application"
],
"description": "Read Only All",
"displayName": "Read Only All",
"id": "***",
"isEnabled": true,
"lang": null,
"origin": "Application",
"value": "ReadOnlyAll"
}
],

我们已经创建了客户端 key ,同时我们可以按照MSAL client credential flows上的文档连接到公共(public)应用程序。但这样做我们就失去了分配角色的能力。此外,我可以连接到以下 Authenticating to Azure AD in daemon apps with certificates 的私有(private)应用程序但我们收到一条错误,指出客户端应用程序没有分配给服务应用程序的角色。因此,此时我们不知道如何从 Azure 获取 token 并将角色分配给客户端应用程序。

(据我们所知)没有直接的方法可以将客户端应用程序的角色分配给私有(private)应用程序,无论是通过证书和 secret 、API 权限还是授权的客户端应用程序。

总而言之,我的问题是是否可以将角色分配给从 Azure 上托管的服务应用程序读取数据的本地客户端应用程序。

感谢您的帮助!

最佳答案

如果您想将企业应用程序角色分配给您在“应用程序注册”中注册的应用程序,AFAK,我们无法在 Azure 门户上执行此操作,但我们可以通过 Azure AD Powershell 完成此过程,请尝试以下命令:

Connect-AzureAD 

$appObjId = "object id of the app that you want to assign role to"
$roleOwnerAppObjId = "object id of the role owner app"

$sp = Get-AzureADServicePrincipal -ObjectId $roleOwnerAppObjId

$role= $sp.AppRoles | Where-Object { $_.DisplayName -eq "Read Only All" }

New-AzureADServiceAppRoleAssignment -ObjectId $appObjId -PrincipalId $appObjId -ResourceId $sp.ObjectId -Id $role.Id

您可以在此处找到对象 ID: enter image description here

一旦我分配了角色,如您所见,当我请求访问 token 来访问角色所有者应用程序的资源时,将添加角色声明: enter image description here

enter image description here

如果有任何不清楚或误解的地方,请随时告诉我。

关于.net - 将角色分配给私有(private)应用程序中的客户端 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58451779/

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