Skip to content

Commit

Permalink
[fix]AppClient本身不需要登录,而已通过TokenHttpFilter过滤器直接请求OAuth登录来获取令牌
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Jun 26, 2024
1 parent afeb50e commit 9862527
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 33 deletions.
2 changes: 1 addition & 1 deletion ClientTest/ClientTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NewLife.Redis" Version="5.7.2024.602" />
<PackageReference Include="NewLife.Redis" Version="5.7.2024.617-beta1504" />
<PackageReference Include="NewLife.UnitTest" Version="1.0.2024.102-beta0146" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
Expand Down
2 changes: 1 addition & 1 deletion Plugins/MySqlAgent/MySqlAgent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NewLife.XCode" Version="11.13.2024.606" />
<PackageReference Include="NewLife.XCode" Version="11.13.2024.625-beta1600" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Samples/TestA/TestA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NewLife.Core" Version="10.10.2024.507" />
<PackageReference Include="NewLife.Core" Version="10.10.2024.625-beta1559" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Samples/TestB/TestB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NewLife.Core" Version="10.10.2024.507" />
<PackageReference Include="NewLife.Core" Version="10.10.2024.625-beta1559" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion StarAgent/StarAgent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NewLife.Agent" Version="10.9.2024.621-beta0040" />
<PackageReference Include="NewLife.Agent" Version="10.9.2024.624-beta1712" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Stardust.Data/Stardust.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NewLife.XCode" Version="11.13.2024.606" />
<PackageReference Include="NewLife.XCode" Version="11.13.2024.625-beta1600" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion Stardust.Server/Controllers/AppController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using NewLife.Serialization;
using Stardust.Data;
using Stardust.Data.Configs;
using Stardust.Data.Nodes;
using Stardust.Models;
using Stardust.Server.Services;
using WebSocket = System.Net.WebSockets.WebSocket;
Expand Down
2 changes: 1 addition & 1 deletion Stardust.Web/Stardust.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NewLife.Cube.Core" Version="6.1.2024.614-beta1002" />
<PackageReference Include="NewLife.Cube.Core" Version="6.1.2024.625-beta1720" />
<PackageReference Include="NewLife.Redis" Version="5.7.2024.617-beta1504" />
</ItemGroup>

Expand Down
51 changes: 36 additions & 15 deletions Stardust/AppClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ public class AppClient : ClientBase, IRegistry
/// <summary>实例化</summary>
public AppClient()
{
Features = Features.Login | Features.Ping | Features.Notify;
Features = Features.Ping | Features.Notify;
SetActions("App/");
Actions[Features.Login] = "App/Register";

// 加载已保存数据
var dic = LoadConsumeServicese();
Expand Down Expand Up @@ -125,10 +124,12 @@ public void Start()
{
try
{
Code = AppId;

if (AppId != "StarServer")
{
// 等待注册到平台
var task = TaskEx.Run(Login);
var task = TaskEx.Run(Register);
task.Wait(1_000);
}
}
Expand All @@ -138,6 +139,7 @@ public void Start()
}

StartTimer();
Attach(this);
}

/// <summary>创建Http客户端</summary>
Expand All @@ -156,21 +158,40 @@ protected override ApiHttpClient CreateHttp(String urls)
return client;
}

/// <summary>构建登录请求</summary>
/// <summary>注册</summary>
/// <returns></returns>
public override ILoginRequest BuildLoginRequest()
public async Task<Object?> Register()
{
var inf = new AppModel
try
{
AppId = AppId,
AppName = AppName,
ClientId = ClientId,
Version = _version,
NodeCode = NodeCode,
IP = AgentInfo.GetIps()
};
var inf = new AppModel
{
AppId = AppId,
AppName = AppName,
ClientId = ClientId,
Version = _version,
NodeCode = NodeCode,
IP = AgentInfo.GetIps()
};

return inf;
var rs = await InvokeAsync<String>("App/Register", inf);
WriteLog("接入星尘服务端:{0}", rs);

Logined = true;
//if (Filter is NewLife.Http.TokenHttpFilter thf) Token = thf.Token?.AccessToken;

return rs;
}
catch (Exception ex)
{
if (ex is HttpRequestException)
Log?.Info("注册异常[{0}] {1}", (Client as ApiHttpClient)?.Source, ex.GetTrue()?.Message);
else
Log?.Info(ex.ToString());

//throw;
return null;
}
}

/// <summary>构建心跳请求</summary>
Expand Down Expand Up @@ -215,7 +236,7 @@ protected override async Task OnPing(Object state)
{
if (!NetworkInterface.GetIsNetworkAvailable()) return;

var rs = await Login();
var rs = await Register();
if (rs == null) return;
}

Expand Down
5 changes: 1 addition & 4 deletions Stardust/Models/AppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Stardust.Models;

/// <summary>应用模型</summary>
public class AppModel : ILoginRequest
public class AppModel
{
/// <summary>应用标识</summary>
public String AppId { get; set; } = null!;
Expand All @@ -22,7 +22,4 @@ public class AppModel : ILoginRequest

/// <summary>节点编码</summary>
public String? NodeCode { get; set; }

String? ILoginRequest.Code { get => AppId; set => AppId = value!; }
String? ILoginRequest.Secret { get; set; }
}
2 changes: 0 additions & 2 deletions Stardust/Monitors/StarTracer.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Net.Http;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Reflection;
using NewLife;
using NewLife.Data;
using NewLife.Http;
using NewLife.Log;
using NewLife.Reflection;
Expand Down
4 changes: 2 additions & 2 deletions Stardust/StarFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ private void InitTracer()
AppName = AppName,
//Secret = Secret,
ClientId = ClientId,
Client = _client.Client,
Client = _client,

Log = Log
};
Expand Down Expand Up @@ -366,7 +366,7 @@ public IConfigProvider? Config
AppId = AppId!,
//Secret = Secret,
ClientId = ClientId,
Client = _client.Client,
Client = _client,
};
//if (!ClientId.IsNullOrEmpty()) config.ClientId = ClientId;
config.Attach(_client);
Expand Down
2 changes: 1 addition & 1 deletion Stardust/Stardust.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NewLife.Remoting" Version="3.0.2024.625-beta1714" />
<PackageReference Include="NewLife.Remoting" Version="3.0.2024.626-beta1337" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'!='net40'">
<PackageReference Include="NewLife.Core" Version="10.10.2024.0625-beta1559" />
Expand Down
2 changes: 1 addition & 1 deletion Test/Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Win32.SystemEvents" Version="8.0.0" />
<PackageReference Include="NewLife.Core" Version="10.10.2024.601" />
<PackageReference Include="NewLife.Core" Version="10.10.2024.625-beta1559" />
<PackageReference Include="SSH.NET" Version="2024.0.0" />
</ItemGroup>

Expand Down

0 comments on commit 9862527

Please sign in to comment.