How to use the @azure/core-amqp.Constants.aadEventHubsScope function in @azure/core-amqp

To help you get started, we’ve selected a few @azure/core-amqp 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 / azure-sdk-for-js / sdk / eventhub / event-hubs / src / linkEntity.ts View on Github external
this._type,
      this.name,
      this.address
    );
    await defaultLock.acquire(this._context.cbsSession.cbsLock, () => {
      return this._context.cbsSession.init();
    });
    let tokenObject: AccessToken;
    let tokenType: TokenType;
    if (this._context.tokenCredential instanceof SharedKeyCredential) {
      tokenObject = this._context.tokenCredential.getToken(this.audience);
      tokenType = TokenType.CbsTokenTypeSas;
      // renew sas token in every 45 minutess
      this._tokenTimeoutInMs = (3600 - 900) * 1000;
    } else {
      const aadToken = await this._context.tokenCredential.getToken(Constants.aadEventHubsScope);
      if (!aadToken) {
        throw new Error(`Failed to get token from the provided "TokenCredential" object`);
      }
      tokenObject = aadToken;
      tokenType = TokenType.CbsTokenTypeJwt;
      this._tokenTimeoutInMs = tokenObject.expiresOnTimestamp - Date.now() - 2 * 60 * 1000;
    }

    logger.verbose(
      "[%s] %s: calling negotiateClaim for audience '%s'.",
      this._context.connectionId,
      this._type,
      this.audience
    );
    // Acquire the lock to negotiate the CBS claim.
    logger.verbose(
github Azure / azure-sdk-for-js / sdk / core / core-amqp / samples / cbsAuthUsingAad.ts View on Github external
async function authenticate(
  audience: string,
  closeConnection: boolean = false
): Promise {
  await connectionContext.cbsSession.init();
  const credential = new DefaultAzureCredential();
  const tokenObject = await credential.getToken(Constants.aadEventHubsScope);
  if (!tokenObject) {
    throw new Error("Aad token cannot be null");
  }
  const result = await connectionContext.cbsSession.negotiateClaim(
    audience,
    tokenObject,
    TokenType.CbsTokenTypeJwt
  );
  console.log("Result is: %O", result);
  if (closeConnection) {
    await connectionContext.connection.close();
    console.log("Successfully closed the connection.");
  }
  return result;
}