简体   繁体   English

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

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

I want to get all Azure DevOps PAT list in my Azure function app.我想在我的 Azure function 应用程序中获取所有 Azure DevOps PAT 列表。 I am using Node.Js in Azure function app.我在 Azure function 应用程序中使用 Node.Js。

To get the Azure DevOps PAT list, I'm using this REST API .为了获得 Azure DevOps PAT 列表,我使用了这个REST API

So for Authentication I'm using MSAL library .因此,对于身份验证,我使用的是MSAL 库 So after getting the auth token, when I'm using it to call the Azure DevOps PAT list REST API then I'm not getting the PAT list.因此,在获得授权令牌后,当我使用它调用 Azure DevOps PAT 列表 REST API 时,我没有获得 PAT 列表。 See below for my function app code.请参阅下面我的 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
    };
}

I am not getting the list of PAT but getting the below output:我没有得到 PAT 列表,但得到以下 output:

Anonymous Sign out Microsoft Inte.net Explorer's Enhanced Security Configuration is currently enabled on your environment.匿名注销Microsoft Inte.net Explorer 的增强安全配置当前已在您的环境中启用。 This enhanced level of security prevents our web integration experiences from displaying or performing correctly.这种增强的安全级别会阻止我们的 web 集成体验正确显示或执行。 To continue with your operation please disable this configuration or contact your administrator.要继续您的操作,请禁用此配置或联系您的管理员。

Why am I not getting the PAT list?为什么我没有收到 PAT 列表?

Please show the reference status of your request, from the description, it seems you are using PAT.请显示您的请求的参考状态,从描述来看,您似乎正在使用 PAT。

PAT is basic auth. PAT 是基本授权。 But in your code you mentioned // 'Bearer <token>'但是在你的代码中你提到了// 'Bearer <token>'

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

相关问题 如何使用 C# 从 Azure Devops 中的 Artifacts/Nuget Feed 获取所有包及其版本的列表? - How to get the list of all the packages with their versions from Artifacts/Nuget Feed in Azure Devops using C#? 如何在node.js中集成Azure语音API - How to integrate Azure Voice API in node.js Azure Cosmos DB ChangeFeed Node.js - Azure Cosmos DB ChangeFeed with Node.js 在 Node.js 中验证 Azure OAuth 令牌 - Verify Azure OAuth token in Node.js 登录后如何获取用户名?我正在尝试使用 MSAL (@azure/msal-angular) 进行 Azure 登录 - How to get username after logged in?.I am trying with MSAL (@azure/msal-angular) for Azure Signin 令牌认证(而不是 PAT 令牌)到 Azure DevOps REST API 通过 Azure DevOps 管道 - Token authentication (instead of PAT token) to Azure DevOps REST API via Azure DevOps Pipeline 使用 node.js 代码在其上创建 Azure 物联网集线器和设备 - Creating Azure iot-hub and device on it using node.js code Azure node.js 中的 Azure 与 Cosmos DB 绑定不会将属性注入 sqlQuery - Azure function in node.js with Cosmos DB binding doesn't get properties injected into sqlQuery 如何从 node.js package.json 文件克隆 Azure Dev Ops 存储库? - How to clone a Azure Dev Ops repo from node.js package.json file? 如何从 Node.js 中的 S3 getObject 获取响应? - How to get response from S3 getObject in Node.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM