Search code examples
erlangmqttemqx

How to extend emqx clientInfo to get more fields during HTTP Authorization


I have emqx running in docker and i`m using a .net api as HTTP Authorization service (https://www.emqx.io/docs/en/latest/access-control/authz/authz.html).

I want to know if there is a way to get more fields into the authorization endpoint of my .net api other than the ones mentioned in https://www.emqx.io/docs/en/latest/access-control/authz/authz.html (clientId, userName, etc.) .

I would like, for example to get a ${password} (exactly like we get out of the box when we setup an HTTP Service to handle authentication (https://www.emqx.io/docs/en/latest/access-control/authn/http.html).

Another example would be to get the payload of a publish request (e.g.: ${payload}).

Is this even possible? Can someone please point me in the right direction?

Regards


Solution

  • As a solution, we decided to not use emqx. We are using mqttnet.Server library where we can easily send the token and any other information on each publish and subscribe in the UserProperties

    on the client side:

        var message = new MqttApplicationMessageBuilder()
            .WithTopic(topic)
            .WithPayload(payload)
            .WithRetainFlag()
            .WithQualityOfServiceLevel(MqttQualityOfServiceLevel.ExactlyOnce)
            .WithUserProperty("token", token)
            .WithUserProperty("otherInfo", otherInfo)
            .Build();
        await _mqttClient.PublishAsync(message);
    

    and for the subscribe:

        var subscribeOptions = _mqttFactory.CreateSubscribeOptionsBuilder()
            .WithTopicFilter(topic, MqttQualityOfServiceLevel.AtLeastOnce)
            .WithUserProperty("token", token)
            .WithUserProperty("otherInfo", otherInfo)
            .Build();
    
        await _mqttClient.SubscribeAsync(subscribeOptions);
    

    The user properties are available on the Server side through:

    for publish, in the InterceptingPublishAsync event handler we get the UserProperties in the

     InterceptingPublishEventArgs.ApplicationMessage.UserProperties
    

    for subscribe, in the InterceptingSubscriptionAsync event handler we get the UserProperties in the

     InterceptingSubscriptionEventArgs.UserProperties