Autenticazione CBS di Azure AMQP Service Bus

· Funzionalità

Da sgcWebSockets 2026.1.0 Azure AMQP 1.0 supporta l'autenticazione CBS tramite SAS Token e JWT.

Azure Service Bus implementa Claims-Based Security (CBS) su AMQP per autorizzare mittenti e destinatari dopo l'handshake SASL iniziale. Il client apre un link di management verso il nodo $cbs e invia una richiesta put-token contenente un token Shared Access Signature (SAS) oppure un JSON Web Token (JWT) emesso da Microsoft Entra ID. Una volta che il broker convalida il token, l'autorizzazione viene memorizzata in cache per la sua durata e l'applicazione può procedere a creare link mittente e destinatario verso code, topic o sottoscrizioni.


Come funziona Azure CBS

Azure Service Bus implementa CBS su AMQP per autorizzare mittenti e destinatari dopo l'handshake SASL iniziale. Il client apre un link di management verso il nodo $cbs e invia una richiesta put-token contenente un token SAS oppure un JWT emesso da Microsoft Entra ID. Una volta che il broker convalida il token, l'autorizzazione viene memorizzata in cache per la sua durata e l'applicazione può procedere a creare link mittente e destinatario verso code, topic o sottoscrizioni.

Il client AMQP1 in sgcWebSockets 2026.1.0 automatizza questo flusso attraverso due metodi helper naturali per gli sviluppatori Delphi:


Entrambi i metodi richiedono una connessione AMQP attiva e accettano i seguenti parametri:

Gli esempi seguenti illustrano come autenticarsi con CBS prima di inviare messaggi.

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

Il prossimo esempio si concentra esclusivamente sull'autenticazione Microsoft Entra ID (Azure AD) tramite JWT. Mostra come richiedere un token con il flusso client credentials e pubblicarlo su $cbs prima di creare i link per inviare o ricevere messaggi. 

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