使用devops REST API查找描述符标识符 [英] Finding Descriptor Identifier using devops REST API

查看:87
本文介绍了使用devops REST API查找描述符标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在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 } ] }

谢谢.

解决方案

获取以S-1-9开头的描述符.

没有直接休息的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身份团队工程师撰写的博客:

Thank you.

Obtaining the descriptor that starts with S-1-9.

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查找描述符标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆