diff --git a/NewLife.Remoting.Extensions/Common/BaseController.cs b/NewLife.Remoting.Extensions/Common/BaseController.cs index 9b1ec49..ad5eb27 100644 --- a/NewLife.Remoting.Extensions/Common/BaseController.cs +++ b/NewLife.Remoting.Extensions/Common/BaseController.cs @@ -8,6 +8,7 @@ using NewLife.Remoting.Extensions.Services; using NewLife.Serialization; using NewLife.Web; +using static NewLife.Remoting.ApiHttpClient; using IWebFilter = Microsoft.AspNetCore.Mvc.Filters.IActionFilter; namespace NewLife.Remoting.Extensions; @@ -57,10 +58,11 @@ void IWebFilter.OnActionExecuting(ActionExecutingContext context) try { - if (context.ActionDescriptor is ControllerActionDescriptor act && !act.MethodInfo.IsDefined(typeof(AllowAnonymousAttribute))) + var rs = !token.IsNullOrEmpty() && OnAuthorize(token); + + if (!rs && context.ActionDescriptor is ControllerActionDescriptor act && !act.MethodInfo.IsDefined(typeof(AllowAnonymousAttribute))) { - var rs = !token.IsNullOrEmpty() && OnAuthorize(token); - if (!rs) throw new ApiException(ApiCode.Forbidden, "认证失败"); + throw new ApiException(ApiCode.Forbidden, "认证失败"); } } catch (Exception ex) diff --git a/Samples/IoTZero/Clients/ClientTest.cs b/Samples/IoTZero/Clients/ClientTest.cs new file mode 100644 index 0000000..5143895 --- /dev/null +++ b/Samples/IoTZero/Clients/ClientTest.cs @@ -0,0 +1,33 @@ +using IoTEdge; +using NewLife.Log; + +namespace IoTZero.Clients; + +/// 客户端测试入口。主程序通过反射调用 +public static class ClientTest +{ + private static ITracer _tracer; + private static HttpDevice _device; + + public static async Task Main(IServiceProvider serviceProvider) + { + await Task.Delay(3_000); + + XTrace.WriteLine("开始IoT客户端测试"); + + _tracer = serviceProvider.GetService(); + + var set = ClientSetting.Current; + + // 产品编码、产品密钥从IoT管理平台获取,设备编码支持自动注册 + var device = new HttpDevice(set) + { + Tracer = _tracer, + Log = XTrace.Log, + }; + + await device.LoginAsync(); + + _device = device; + } +} diff --git a/Samples/IoTZero/IoTZero.csproj b/Samples/IoTZero/IoTZero.csproj index 5ca9251..aa8edb3 100644 --- a/Samples/IoTZero/IoTZero.csproj +++ b/Samples/IoTZero/IoTZero.csproj @@ -40,6 +40,8 @@ + + @@ -48,9 +50,7 @@ - - @@ -66,8 +66,9 @@ - - + + PreserveNewest +