IoTSharp / MQTTnet.AspNetCore.Routing

Easily create Controllers and Actions to process incoming MQTT messages using a familiar paradigm and MQTTnet

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Authorized Publish and View Model Binding From Message Payload

seikosantana opened this issue · comments

This repository seems to be the most actively developed of all forks, so i think there may be a few ways where the library can be improved more.

Describe the feature request

For the routes, i think it will be nice to have something like ASP.NET Core's [Authorize] attribute which client validation method can be specified, and some way to deserialize the json payload in a action parameter decorated with [FromPayload] automatically if Authorize is successful or not present

Describe the solution you'd like

in ASP.NET Core we can have

[Route("{someNumber:int}"]
public async Task<IActionResult> SomeAction(int someNumber, [FromForm] SomeModel viewModel) {
  return Ok();
}

I think it's nice and streamlined way for the part to do stuff in a manner that is very similar to AspNet Core, so I'd imagine something like

[Authorize(Policy = "AuthorizedDevices")]
[MqttRoute("{someNumber:int}"]
public async Task SomeAction(int someNumber, [FromPayload] SomeModel viewModel) {
  // do something
  await Ok();
  return;
}

FromPayload is good idea!

I'm looking to implement it. Not a very experienced C# programmer but will give it a try.

I have tried to implement FromPayload in this pull request #5 . Would you mind to take a look at it?

lgtm .

Thanks a lot.

However, for the Authorize part, i don't see where it can fit without too many changes. Maybe for now will leave the Authorized part.

Will this changes be pushed to the NuGet package?

I test the related project and then push it to Nuget

Okay then, I think this issue can now be closed