How to use the @azure/ms-rest-js.TokenCredentials function in @azure/ms-rest-js

To help you get started, we’ve selected a few @azure/ms-rest-js 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 Azure-Samples / digital-twins-explorer / client / src / services / ApiService.js View on Github external
async initialize() {
    const accessToken = await authService.login();
    if (!accessToken) {
      throw new Error("Failed to acquire access token");
    }

    const tokenCredentials = new TokenCredentials(accessToken);

    const clientConfig = {
      baseUri: `${window.location.origin}/api/proxy`
    };

    // Add token and server url to service instance
    this.client = new AzureDigitalTwinsAPI(tokenCredentials, clientConfig);

    const { appAdtUrl } = await configService.getConfig();
    this.clientOptions = { customHeaders: { "x-adt-host": new URL(appAdtUrl).hostname } };
  }
github Azure / azure-sdk-for-js / test / lroPollStrategyTests.ts View on Github external
it("with no AzureServiceClient.longRunningOperationRetryTimeout value and spam retry-after header", function () {
      const azureServiceClient = new AzureServiceClient(new TokenCredentials("my-fake-token"));
      const previousResponse: HttpOperationResponse = {
        request: new WebResource(),
        status: 200,
        headers: new HttpHeaders({ "retry-after": "spam" })
      };
      assert.strictEqual(getDelayInSeconds(azureServiceClient, previousResponse), 30);
    });
github Azure / azure-sdk-for-js / test / azureServiceClientTests.ts View on Github external
it ("adds user agent header that looks similar to \"ms-rest-azure-js/0.1.0 ms-rest-js/0.1.0 Node/v10.11.0 OS/(x64-Windows_NT-10.0.18267)\"", async () => {
      const client = new AzureServiceClient(new TokenCredentials("my-fake-token"));
      const request = new WebResource("https://microsoft.com");
      await client.sendRequest(request);

      const telemetry = request.headers.get("user-agent")!;
      const parts = telemetry.split(" ");

      assert(parts[0].includes("ms-rest-azure-js/"));
      assert(parts[1].includes("ms-rest-js/"));
      assert(parts[2].includes("Node/"));
      assert(parts[3].includes("OS/"));
    });
  });
github Azure / azure-sdk-for-js / test / azureServiceClientTests.ts View on Github external
it ("adds custom user agent if specified", async () => {
      const client = new AzureServiceClient(new TokenCredentials("fake-token"), { userAgent: "custom-ua" });
      const request = new WebResource("https://microsoft.com");
      await client.sendRequest(request);

      const telemetry = request.headers.get("user-agent")!;
      assert.equal(telemetry, "custom-ua");
    });
github Azure / azure-sdk-for-js / test / azureServiceClientTests.ts View on Github external
function createServiceClient(responses: HttpResponse[]): AzureServiceClient {
  return new AzureServiceClient(new TokenCredentials("my-fake-token"), {
    httpClient: {
      sendRequest(httpRequest: WebResource): Promise {
        const response: HttpResponse | undefined = responses.shift();
        if (!response) {
          throw new Error("Not enough responses provided for test.");
        }
        return Promise.resolve({
          request: httpRequest,
          status: response.status,
          headers: response.headers || new HttpHeaders(),
          bodyAsText: typeof response.body === "string" ? response.body : JSON.stringify(response.body),
          parsedBody: response.body
        });
      }
    },
    longRunningOperationRetryTimeout: 0