Azure AMQP Service Bus CBS 認証

· 機能

sgcWebSockets 2026.1.0 より、Azure AMQP 1.0 が SAS トークンと JWT を使用した CBS 認証をサポートしました。

Azure Service Bus は SASL ハンドシェイク後に送信者と受信者を認可するため、AMQP 上でクレームベースセキュリティ(CBS)を実装しています。クライアントは $cbs ノードへの管理リンクを開き、Shared Access Signature(SAS)トークンまたは Microsoft Entra ID が発行した JSON Web Token(JWT)を含む put-token リクエストを送信します。ブローカーがトークンを検証すると、認可はその有効期間中キャッシュされ、アプリケーションはキュー、トピック、またはサブスクリプションへの送信者・受信者リンクを作成できます。


Azure CBS の仕組み

Azure Service Bus は SASL ハンドシェイク後に送信者と受信者を認可するため、AMQP 上で CBS を実装しています。クライアントは $cbs ノードへの管理リンクを開き、SAS トークンまたは Microsoft Entra ID が発行した JWT を含む put-token リクエストを送信します。ブローカーがトークンを検証すると、認可はその有効期間中キャッシュされ、アプリケーションはキュー、トピック、またはサブスクリプションへのリンクを作成できます。

sgcWebSockets 2026.1.0 の AMQP1 クライアントは、Delphi 開発者に自然な 2 つのヘルパーメソッドでこのフローを自動化します:


両メソッドはアクティブな AMQP 接続を必要とし、次のパラメーターを受け付けます:

以下の例は、メッセージを送信する前に CBS で認証する方法を示しています。

// ... 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 example focuses solely on Microsoft Entra ID (Azure AD) authentication using JWTs. It shows how to request a token with the client credentials flow and publish it to $cbs before creating links to send or receive messages. 

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