问题描述
我正在尝试在dev.azure.com{organization}/_apis/accesscontrolentries/{namespaceId}?api-version=5.1
上发帖.
我需要帮助来获取以S-1-9
开头的描述符.
{ "token": "", "merge": true, "accessControlEntries": [ { "descriptor": "Microsoft.TeamFoundation.Identity;S-1-9-**********-**********-**********-**********-**********-*-**********-**********-**********-**********", "allow": 128, "deny": 0 } ] }
谢谢.
没有直接休息的api来获取以S-1-9开头的描述符.您需要首先使用以下api获取user descriptor(SID)
:
GET https://vssps.dev.azure.com/{org name}/_apis/graph/users?api-version=5.1-preview.1
我有一个关于如何从响应正文中获取答案的答案,有关更多详细信息,请参考此答案./p>
现在,我们得到的描述符基于base64
.要实现您想要的功能,只需解码此SID.
这里有一个由我们的Azure身份团队工程师撰写的博客: C#解码脚本.只需位于相应部分即可实现此解码脚本:
public static string Base64Decode(string base64EncodedData)
{
var lengthMod4 = base64EncodedData.Length % 4;
if (lengthMod4 != 0)
{
//fix Invalid length for a Base-64 char array or string
base64EncodedData += new string('=', 4 - lengthMod4);
}
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
}
public static string Base64Encode(string plainText)
{
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
return System.Convert.ToBase64String(plainTextBytes);
}
I am trying to make a post to the dev.azure.com{organization}/_apis/accesscontrolentries/{namespaceId}?api-version=5.1
.
I need help on obtaining the descriptor that starts with S-1-9
.
{ "token": "", "merge": true, "accessControlEntries": [ { "descriptor": "Microsoft.TeamFoundation.Identity;S-1-9-**********-**********-**********-**********-**********-*-**********-**********-**********-**********", "allow": 128, "deny": 0 } ] }
Thank you.
There’s no directly rest api to get this descriptor which start with S-1-9. You need to use the follow api get the user descriptor(SID)
firstly:
GET https://vssps.dev.azure.com/{org name}/_apis/graph/users?api-version=5.1-preview.1
I have one answer about how to obtain it from response body, please refer to this answer for more details.
Now the descriptor we get is based on base64
. To achieve what you want, just decode this SID.
Here has a blog which written by our Azure Identity Team engineer: C# Decode script. Just located to the corresponding part to achieve this decode script:
public static string Base64Decode(string base64EncodedData)
{
var lengthMod4 = base64EncodedData.Length % 4;
if (lengthMod4 != 0)
{
//fix Invalid length for a Base-64 char array or string
base64EncodedData += new string('=', 4 - lengthMod4);
}
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
}
public static string Base64Encode(string plainText)
{
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
return System.Convert.ToBase64String(plainTextBytes);
}
这篇关于使用devops REST API查找描述符标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!