Autenticación CBS en Azure AMQP Service Bus

· Características

Desde sgcWebSockets 2026.1.0 Azure AMQP 1.0 soporta autenticación CBS usando SAS tokens y JWT.

Azure Service Bus implementa Claims-Based Security (CBS) sobre AMQP para autorizar emisores y receptores tras el handshake SASL inicial. El cliente abre un management link al nodo $cbs y envía una solicitud put-token que contiene un token Shared Access Signature (SAS) o un JSON Web Token (JWT) emitido por Microsoft Entra ID. Una vez que el broker valida el token, la autorización se cachea durante su tiempo de vida y la aplicación puede proceder a crear sender y receiver links contra colas, topics o suscripciones.


Cómo funciona Azure CBS

Azure Service Bus implementa CBS sobre AMQP para autorizar emisores y receptores tras el handshake SASL inicial. El cliente abre un management link al nodo $cbs y envía una solicitud put-token con un token SAS o un JWT emitido por Microsoft Entra ID. Una vez que el broker valida el token, la autorización se cachea durante su tiempo de vida y la aplicación puede crear sender y receiver links contra colas, topics o suscripciones.

El cliente AMQP1 en sgcWebSockets 2026.1.0 automatiza este flujo mediante dos métodos helper que resultan naturales para desarrolladores Delphi:


Ambos métodos requieren una conexión AMQP activa y aceptan los siguientes parámetros:

Los siguientes ejemplos ilustran cómo autenticarse con CBS antes de enviar mensajes.

// ... create TCP client
oClient := TsgcWebSocketClient.Create(nil);
oClient.Specifications.RFC6455 := False;
oClient.Host := 'esegece.servicebus.windows.net';
oClient.Host := 'esegece.servicebus.windows.net';
oClient.Port := 5671;
oClient.TLS := True;
// ... create AMQP1 protocol client
oAMQP1 := TsgcWSClient_AMQP1.Create(nil);
oAMQP1.Specifications.RFC6455 := False;
oAMQP1.AMQPOptions.Authentication.AuthType := amqp1authSASLAnonymous;
oAMQP1.Client := oClient;
// ... connect and publish SAS token through CBS
oClient.Active := True;
// ... wait till the connection is active and send the authentication
oAMQP1.CreateAzureCbsSasToken('cbs', 'esegece', 'queue1',
  'RootManageSharedAccessKey', 'BhJ78+w8kMXhS/eE/nBy0cRzodx9tipbi+ASbAXIaH8=',
  3600, 10000, True);

El siguiente ejemplo se centra exclusivamente en la autenticación con Microsoft Entra ID (Azure AD) usando JWTs. Muestra cómo solicitar un token con el flujo client credentials y publicarlo en $cbs antes de crear links para enviar o recibir mensajes. 

oClient := TsgcWebSocketClient.Create(nil);
oClient.Specifications.RFC6455 := False;
oClient.Host := 'esegece.servicebus.windows.net';
oClient.Host := 'esegece.servicebus.windows.net';
oClient.Port := 5671;
oClient.TLS := True;
// ... create AMQP1 protocol client
oAMQP1 := TsgcWSClient_AMQP1.Create(nil);
oAMQP1.Specifications.RFC6455 := False;
oAMQP1.AMQPOptions.Authentication.AuthType := amqp1authSASLAnonymous;
oAMQP1.Client := oClient;
// ... connect and publish JWT through CBS
oClient.Active := True;
// ... wait till the connection is active and send the authentication
oAMQP1.CreateAzureCbsJWT('cbs', 'esegece', 'queue1',
  '00000000-0000-0000-0000-000000000000', // Tenant ID
  '11111111-1111-1111-1111-111111111111', // Application ID
  'client-secret', 8080, 3600, 10000, True);