Azure AMQP Service Bus CBS Autenticação

· Recursos

A partir do sgcWebSockets 2026.1.0 Azure AMQP 1.0 suporta CBS Autenticação using SAS Tokens e JWT.

Azure Service Bus implements Claims-Based Security (CBS) over AMQP para authorize senders e receivers after o initial SASL handshake. O cliente opens um management link para o $cbs node e sends um put-token request containing either um Shared Access Signature (SAS) token ou um JSON Web Token (JWT) issued por Microsoft Entra ID. Once o broker validates o token, o autorização is cached para its lifetime e o application can proceed para criar sender e receiver links against queues, topics, ou inscrições.


Como funciona o Azure CBS

Azure Service Bus implements CBS over AMQP para authorize senders e receivers after o initial SASL handshake. O cliente opens um management link para o $cbs node e sends um put-token request containing either um SAS token ou um JWT issued por Microsoft Entra ID. Once o broker validates o token, o autorização is cached para its lifetime e o application can proceed para criar sender e receiver links against queues, topics, ou inscrições.

The AMQP1 client em sgcWebSockets 2026.1.0 automates this flow through two helper métodos that feel natural para desenvolvedores Delphi:


Both métodos require um active AMQP conexão e accept os seguintes parâmetros:

The following exemplos illustrate como autenticar com CBS before sending messages.

// ... 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);

The next exemplo focuses solely em Microsoft Entra ID (Azure AD) autenticação using JWTs. It shows como request um token com o cliente credentials flow e publish it para $cbs before creating links para enviar ou receber mensagens. 

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);