Esempio n. 1
0
        public async Task <IActionResult> AuthOnPublish([FromBody] AuthOnPublishPayload request)
        {
            var result = await AuthorizeOnPublish(request);

            if (result != null && result is OkAuthOnPublishResult item)
            {
                return(Ok(new
                {
                    Result = "ok",
                    Modifiers = new
                    {
                        item.Topic,
                        item.Qos,
                        item.Payload,
                        item.Retain
                    }
                }));
            }

            return(result.GeneratePublicResult());
        }
Esempio n. 2
0
 /// <summary>
 /// This method is called when client is trying to publish a message to specific topic. You can authorize client and accept or reject this request.
 /// To accept the client to publish the message return complex <see cref="OkAuthOnPublishResult"/> to rewrite the topic and the payload or simple <see cref="OkResult"/>
 /// To ignore authorization return <see cref="NextResult"/>
 /// To reject the client return <see cref="ErrorResult"/>
 /// For more information <see cref="https://docs.vernemq.com/plugin-development/publishflow#auth_on_publish-and-auth_on_publish_m5"/>
 /// </summary>
 /// <param name="authOnRegisterPayload">publish message information</param>
 /// <returns>return value must be one of <see cref="OkResult"/> or <see cref="OkAuthOnPublishResult"/> or <see cref="NextResult"/> or <see cref="ErrorResult"/> </returns>
 protected virtual async Task <HookResult> AuthorizeOnPublish(AuthOnPublishPayload authOnRegisterPayload)
 {
     return(new OkResult());
 }