Azure DevOps Extension管理用户权利

时间:2019-03-26 10:36:06

标签: azure-devops azure-devops-rest-api azure-devops-extensions

我正在尝试为Azure DevOps平台创建扩展,以管理用户权利。但是,当使用npm sdk“ vss-web-extension-sdk”时,用户权利Api不可用(https://docs.microsoft.com/en-us/rest/api/azure/devops/memberentitlementmanagement/user%20entitlements?view=azure-devops-rest-5.0)。现在,我不确定如何使用扩展程序来管理用户权利。

我已经尝试通过从Javascript提取Api手动调用Api,但是却收到跨域读取阻止(CORB)错误。 Cross-Origin Read Blocking (CORB) blocked cross-origin response https://vsaex.dev.azure.com/*****/_apis/userentitlements?api-version=5.0-preview.2 with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.

无效的代码:

export function api<T>(url: string, options?: RequestInit): Promise<T> {
    return fetch(url, options)
        .then((response: Response) => {
            if (!response.ok) {
                throw new Error(response.statusText)
            }

            return response
                .json()
                .then(data => data as T);
        }
    );
}

----

const pat = base64Encode(`:${(document.getElementById("pat") as HTMLInputElement).value}`);

api<{ members: { accessLevel: { licenseDisplayName: string } }[] }>(
`https://vsaex.dev.azure.com/${VSS.getWebContext().account.name}/_apis/userentitlements?api-version=5.0-preview.2`, 
   { 
      method: 'GET', 
      headers: new Headers({ 
         'Authorization': `Basic ${pat}`
      }),
      mode: 'no-cors',
      credentials: 'include'
   }
).then(
   ({ members }) => {
      console.log(members);
   }
).catch(
   (err) => {
      console.error(err);
   }
);

0 个答案:

没有答案