How to use the typed-rest-client/Handlers.BearerCredentialHandler 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 jfrog / artifactory-vsts-extension / artifactory-tasks-utils / utils.js View on Github external
function createAuthHandlers(artifactoryService) {
    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 mihails-strasuns / setup-dlang / src / utils.ts View on Github external
export async function body_as_text(url: string, token: string = ''): Promise {
    const bearer = token ? [ new BearerCredentialHandler(token) ] : undefined;
    let client = new httpm.HttpClient("mihails-strasuns/setup-dlang", bearer);
    return (await (await client.get(url)).readBody()).trim();
}
github actions / cache / src / cacheHttpClient.ts View on Github external
export async function getCacheEntry(
    keys: string[]
): Promise {
    const cacheUrl = getCacheUrl();
    const token = process.env["ACTIONS_RUNTIME_TOKEN"] || "";
    const bearerCredentialHandler = new BearerCredentialHandler(token);

    const resource = `_apis/artifactcache/cache?keys=${encodeURIComponent(
        keys.join(",")
    )}`;

    const restClient = new RestClient("actions/cache", cacheUrl, [
        bearerCredentialHandler
    ]);

    const response = await restClient.get(
        resource,
        getRequestOptions()
    );
    if (response.statusCode === 204) {
        return null;
    }
github mihails-strasuns / setup-dlang / lib / utils.js View on Github external
return __awaiter(this, void 0, void 0, function* () {
        const bearer = token ? [new Handlers_1.BearerCredentialHandler(token)] : undefined;
        let client = new httpm.HttpClient("mihails-strasuns/setup-dlang", bearer);
        return (yield (yield client.get(url)).readBody()).trim();
    });
}
github actions / cache / src / cacheHttpClient.ts View on Github external
export async function saveCache(
    stream: NodeJS.ReadableStream,
    key: string
): Promise {
    const cacheUrl = getCacheUrl();
    const token = process.env["ACTIONS_RUNTIME_TOKEN"] || "";
    const bearerCredentialHandler = new BearerCredentialHandler(token);

    const resource = `_apis/artifactcache/cache/${encodeURIComponent(key)}`;
    const postUrl = cacheUrl + resource;

    const restClient = new RestClient("actions/cache", undefined, [
        bearerCredentialHandler
    ]);

    const requestOptions = getRequestOptions();
    requestOptions.additionalHeaders = {
        "Content-Type": "application/octet-stream"
    };

    const response = await restClient.uploadStream(
        "POST",
        postUrl,