简体   繁体   中英

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. I am using Node.Js in Azure function app.

To get the Azure DevOps PAT list, I'm using this REST API .

So for Authentication I'm using MSAL library . 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. See below for my function app code.

'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:

Anonymous Sign out Microsoft Inte.net Explorer's Enhanced Security Configuration is currently enabled on your environment. This enhanced level of security prevents our web integration experiences from displaying or performing correctly. To continue with your operation please disable this configuration or contact your administrator.

Why am I not getting the PAT list?

Please show the reference status of your request, from the description, it seems you are using PAT.

PAT is basic auth. But in your code you mentioned // 'Bearer <token>'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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