How to use the typed-rest-client/Handlers.PersonalAccessTokenCredentialHandler function in typed-rest-client

To help you get started, we’ve selected a few typed-rest-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / typed-rest-client / samples / handlers.ts View on Github external
export async function run() {
    cm.banner('Handler Samples');

    const username = "";
    const password = "";
    const workstation = "";
    const domain = "";
    const url = "";

    const basicHandler: hm.BasicCredentialHandler = new hm.BasicCredentialHandler(username, password);
    const patHandler: hm.PersonalAccessTokenCredentialHandler = new hm.PersonalAccessTokenCredentialHandler('scbfb44vxzku5l4xgc3qfazn3lpk4awflfryc76esaiq7aypcbhs');
    const ntlmHandler: hm.NtlmCredentialHandler = new hm.NtlmCredentialHandler(username, password, workstation, domain);

    // These handlers would then be passed to the constructors of the http or rest modules

    // const httpClient: httpm.HttpClient = new httpm.HttpClient('vsts-node-api', [ntlmHandler]);
    // const response: httpm.HttpClientResponse = await httpClient.get(url);
    // console.log("response code: " + response.message.statusCode);
}
github microsoft / azure-pipelines-tasks / ci / filter-tasks.js View on Github external
var getTasksToBuildForCI = async function() {
    // Returns a list of tasks that have different version numbers than their current published version. 
    var packageInfo;
    try {
        var packageToken = process.env['PACKAGE_TOKEN'];
        if (!packageToken) {
            console.log(`##vso[task.logissue type=warning;sourcepath=ci/filter-task.js;linenumber=21;]Failed to get info from package endpoint because no token was provided. Try setting the PACKAGE_TOKEN environment variable.`);
            return makeOptions.tasks;
        }
        var handler = new httpHandler.PersonalAccessTokenCredentialHandler(packageToken);
        var client = new restClient.RestClient('azure-pipelines-tasks-ci', '', [handler]);
        var packageEndpoint = process.env['PACKAGE_ENDPOINT'];
        if (!packageEndpoint) {
            console.log(`##vso[task.logissue type=warning;sourcepath=ci/filter-task.js;linenumber=28;]Failed to get info from package endpoint because no endpoint was specified. Try setting the PACKAGE_ENDPOINT environment variable.`);
            return makeOptions.tasks;
        }
        packageInfo = await client.get(packageEndpoint);
        if (packageInfo.statusCode !== 200) {
            console.log(`##vso[task.logissue type=warning;sourcepath=ci/filter-task.js;linenumber=33;]Failed to get info from package endpoint, returned with status code ${packageInfo.statusCode}`);
            return makeOptions.tasks;
        }
    }
    catch (err) {
        // If unable to reach rest client, build everything.
        console.log(`##vso[task.logissue type=warning;sourcepath=ci/filter-task.js;linenumber=39;]Failed to get info from package endpoint, client failed with error ${err.message}`);
        return makeOptions.tasks;
github microsoft / typed-rest-client / test / httptests.ts View on Github external
'X-TFS-FedAuthRedirect': 'Suppress'
            }})
            .get('/')
            .reply(200, {
                success: true,
                source: "nock"
            });
        //Set nock for request without credentials or with incorrect credentials
        nock('http://microsoft.com')
            .get('/')
            .reply(200, {
                success: false,
                source: "nock"
            });
        let ph: hm.PersonalAccessTokenCredentialHandler = 
            new hm.PersonalAccessTokenCredentialHandler(token);
        let http: httpm.HttpClient = new httpm.HttpClient('typed-rest-client-tests', [ph]);
        let res: httpm.HttpClientResponse = await http.get('http://microsoft.com');
        assert(res.message.statusCode == 200, "status code should be 200");
        let body: string = await res.readBody();      
        let obj: any = JSON.parse(body);
        assert(obj.source === "nock", "http get request should be intercepted by nock");
        assert(obj.success, "Authentication should succeed");
    });
github microsoft / typed-rest-client / test / units / httptests.ts View on Github external
'X-TFS-FedAuthRedirect': 'Suppress'
            }})
            .get('/')
            .reply(200, {
                success: true,
                source: "nock"
            });
        //Set nock for request without credentials or with incorrect credentials
        nock('http://microsoft.com')
            .get('/')
            .reply(200, {
                success: false,
                source: "nock"
            });
        let ph: hm.PersonalAccessTokenCredentialHandler =
            new hm.PersonalAccessTokenCredentialHandler(token);
        let http: httpm.HttpClient = new httpm.HttpClient('typed-rest-client-tests', [ph]);
        let res: httpm.HttpClientResponse = await http.get('http://microsoft.com');
        assert(res.message.statusCode == 200, "status code should be 200");
        let body: string = await res.readBody();
        let obj: any = JSON.parse(body);
        assert(obj.source === "nock", "http get request should be intercepted by nock");
        assert(obj.success, "Authentication should succeed");
    });