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:
- CreateAzureCbsSasToken establece un par de sender/receiver link CBS, genera un SAS token para la entidad de destino y lo publica en $cbs. Úsalo cuando te autentiques con una shared access policy.
- CreateAzureCbsJWT sigue el mismo intercambio CBS pero obtiene un access token de Microsoft Entra ID (Azure AD) mediante el flujo client-credentials antes de enviar el JWT a $cbs.
Ambos métodos requieren una conexión AMQP activa y aceptan los siguientes parámetros:
- aName: identificador del par de CBS links creados internamente.
- aNameSpace y aEntityName: el namespace de Service Bus (sin el sufijo .servicebus.windows.net) y la ruta de cola, topic o suscripción usada para construir el audience del token.
- aKeyName / aKeyValue: nombre y clave de la shared access policy para tokens SAS. El componente firma el token y lo envÃa usando el tipo servicebus.windows.net:sastoken.
- aTenant, aApplicationId, aSecret: directory ID de Microsoft Entra (Azure AD), application (client) ID y client secret usados para solicitar el JWT con el flujo client credentials.
- aListeningPort (JWT): puerto HTTP local para el redirect OAuth 2.0 (por defecto 8080 si no se indica).
- aExpiration y aTimeout: tiempo de vida del token emitido (en segundos) y tiempo máximo de espera (en milisegundos) para la negociación CBS.
- aRaiseIfError: cuando es True, el método lanza una excepción si falla la obtención del token o la respuesta CBS.
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);
