How to use the typed-rest-client/Handlers.BasicCredentialHandler 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 jfrog / artifactory-vsts-extension / artifactory-tasks-utils / utils.js View on Github external
let artifactoryUser = tl.getEndpointAuthorizationParameter(artifactoryService, "username", true);
    let artifactoryPassword = tl.getEndpointAuthorizationParameter(artifactoryService, "password", true);
    let artifactoryAccessToken = tl.getEndpointAuthorizationParameter(artifactoryService, "apitoken", true);

    // Check if Artifactory should be accessed using access-token.
    if (artifactoryAccessToken) {
        return [new clientHandlers.BearerCredentialHandler(artifactoryAccessToken)]
    }

    // Check if Artifactory should be accessed anonymously.
    if (artifactoryUser === "") {
        return [];
    }

    // Use basic authentication.
    return [new clientHandlers.BasicCredentialHandler(artifactoryUser, artifactoryPassword)];
}
github microsoft / typed-rest-client / test / httptests.ts View on Github external
.basicAuth({
                user: 'johndoe',
                pass: 'password'
            })
            .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 bh: hm.BasicCredentialHandler = new hm.BasicCredentialHandler('johndoe', 'password');
        let http: httpm.HttpClient = new httpm.HttpClient('typed-rest-client-tests', [bh]);
        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
.basicAuth({
                user: 'johndoe',
                pass: 'password'
            })
            .reply(200, {
                success: false,
                source: "nock"
            });
        //Set nock for request without credentials
        nock('http://microsoft.com')
            .get('/')
            .reply(200, {
                success: true,
                source: "nock"
            });
        let bh: hm.BasicCredentialHandler = new hm.BasicCredentialHandler('johndoe', 'password');
        let http: httpm.HttpClient = new httpm.HttpClient('typed-rest-client-tests', [bh], {presignedUrlPatterns: [/microsoft/i]});
        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");
    });