0

In ZeroMQ, more precisely cppzmq in my case, when you use ZAP, it is handled completely transparently for the user.

However, as documented in the RFC: https://rfc.zeromq.org/spec/27/, the Auth server can send back a user ID and some metadata in the response:

The reply message SHALL consist of the following message frames:

  • An address delimiter frame, which SHALL have a length of zero.
  • The version frame, which SHALL contain the three octets “1.0”.
  • The request id, which MAY contain an opaque binary blob.
  • The status code, which SHALL contain a string.
  • The status text, which MAY contain a string.
  • The user id, which SHALL contain a string.
  • The metadata, which MAY contain a blob.

A little bit further down, it precises the meaning of user id:

user id: this MAY provide the user identity in case of a 200 status, for use by applications. For other statuses, it SHALL be empty.

My question is the following: how can you retrieve the user ID from the response with cppzmq?

Small code example to show what I mean:

void client() {
  zmq::context_t context;
  zmq::socket_t socket (context, zmq::socket_type::req);
  socket.set(zmq::sockopt::zap_domain, "global");
  socket.set(zmq::sockopt::plain_username, "user");
  socket.set(zmq::sockopt::plain_password, "password");

  socket.connect("tcp://127.0.0.1:4242");
  ...
  std::string auth_user_id = /* magic function here */;

}
Antoine Viallon
  • 314
  • 4
  • 12

1 Answers1

0

A minimal empty reference implementation is provided in the RFC repository at https://github.com/zeromq/rfc/blob/master/src/spec_27.c. This implementation demonstrates a server talking to a proxy handler over inproc://, talking to an external terminal handler over TCP. The terminal handler implements a PLAIN authentication mechanism.

he shouyong
  • 159
  • 3
  • Thanks for your answer, but I am not sure you understood my question... I can use Authentication just fine, and it works. My problem is getting the Auth answer _metadata_ from the authentication request. – Antoine Viallon Dec 09 '21 at 12:05