繁体   English   中英

如何在 MSAL 的帮助下使用 Node.js 获取 Azure DevOps PAT 列表

[英]How to get Azure DevOps PAT list with the help of MSAL using Node.js

我想在我的 Azure function 应用程序中获取所有 Azure DevOps PAT 列表。 我在 Azure function 应用程序中使用 Node.Js。

为了获得 Azure DevOps PAT 列表,我使用了这个REST API

因此,对于身份验证,我使用的是MSAL 库 因此,在获得授权令牌后,当我使用它调用 Azure DevOps PAT 列表 REST API 时,我没有获得 PAT 列表。 请参阅下面我的 function 应用程序代码。

'use strict';

const config = require('../config');
const rp = require('request-promise');
const msal = require('@azure/msal-node');

module.exports = async function (context, req) {
    const clientId = 'config.DEFAULT_CLIENT_ID';
    const clientSecret = 'config.DEFAULT_CLIENT_SECRET';
    const tenantId = 'config.DEFAULT_TENANT_ID';
 
    let authorityHostUrl = 'https://login.windows.net';
    let authorityUrl = authorityHostUrl + '/' + tenantId;

    const configuration = {
        auth: {
            clientId: clientId,
            authority: authorityUrl,
            clientSecret: clientSecret
        }
    };

    // Create msal application object
    const cca = new msal.ConfidentialClientApplication(configuration);
    // With client credentials flows permissions need to be granted in the portal by a tenant administrator.
    // The scope is always in the format "<resource>/.default"
    const clientCredentialRequest = {
        scopes: ["499b84ac-1321-427f-aa17-267ca6975798/.default"], // replace with your resource
    };

    const credentials = await cca.acquireTokenByClientCredential(clientCredentialRequest);

    const tokenType = credentials.tokenType;
    const token = credentials.accessToken;
    const apiToken = `${tokenType} ${token}`;  // 'Bearer <token>'

    let url = `https://vssps.dev.azure.com/{organization}/_apis/tokens/pats?api-version=6.1-preview.1`;
    const header = {
        Authorization: `${apiToken}`
    };

    const result = await rp({
        url: url,
        json: true,
        headers: header,
        mode: 'cors',
        cache: 'no-cache',
        method: 'GET'
    });

    context.res = {
        body: result
    };
}

我没有得到 PAT 列表,但得到以下 output:

匿名注销Microsoft Inte.net Explorer 的增强安全配置当前已在您的环境中启用。 这种增强的安全级别会阻止我们的 web 集成体验正确显示或执行。 要继续您的操作,请禁用此配置或联系您的管理员。

为什么我没有收到 PAT 列表?

请显示您的请求的参考状态,从描述来看,您似乎正在使用 PAT。

PAT 是基本授权。 但是在你的代码中你提到了// 'Bearer <token>'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM