Azure AMQP Service Bus CBS-authenticatie

· Functies

Vanaf sgcWebSockets 2026.1.0 ondersteunt Azure AMQP 1.0 CBS-authenticatie met SAS-tokens en JWT.

Azure Service Bus implementeert Claims-Based Security (CBS) over AMQP om senders en receivers te autoriseren na de initiële SASL-handshake. De client opent een management-link naar de $cbs-node en stuurt een put-token-request met een Shared Access Signature (SAS)-token of een JSON Web Token (JWT) uitgegeven door Microsoft Entra ID. Zodra de broker het token valideert, wordt de autorisatie gecached voor de levensduur en kan de toepassing verder met het aanmaken van sender- en receiver-links naar queues, topics of subscriptions.


Hoe Azure CBS werkt

Azure Service Bus implementeert CBS over AMQP om senders en receivers te autoriseren na de initiële SASL-handshake. De client opent een management-link naar de $cbs-node en stuurt een put-token-request met een SAS-token of een JWT uitgegeven door Microsoft Entra ID. Zodra de broker het token valideert, wordt de autorisatie gecached voor de levensduur en kan de toepassing verder met het aanmaken van sender- en receiver-links naar queues, topics of subscriptions.

De AMQP1-client in sgcWebSockets 2026.1.0 automatiseert deze flow via twee hulpmethoden die natuurlijk aanvoelen voor Delphi-ontwikkelaars:


Beide methoden vereisen een actieve AMQP-verbinding en accepteren de volgende parameters:

De volgende voorbeelden tonen hoe je met CBS kunt authenticeren voordat je berichten verstuurt.

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

Het volgende voorbeeld richt zich uitsluitend op Microsoft Entra ID (Azure AD)-authenticatie via JWT's. Het laat zien hoe je een token aanvraagt met de client-credentials-flow en deze publiceert naar $cbs voordat je links aanmaakt om berichten te versturen of te ontvangen. 

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