lith 1 năm trước cách đây
mục cha
commit
0667fb4095

+ 33 - 33
dotnet/Gateway/App.Gateway/App.Gateway.csproj

@@ -1,37 +1,37 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
-	<PropertyGroup>
-		<publish>Gateway</publish>
-		<docker>sers-gateway</docker>
-	</PropertyGroup>
-
-	<PropertyGroup>
-		<OutputType>Exe</OutputType>
-		<TargetFramework>net6.0</TargetFramework>
-		<Version>2.1.21-temp</Version>
-		<PackageProjectUrl>https://github.com/serset/Sers</PackageProjectUrl>
-	</PropertyGroup>
-
-
-	<ItemGroup>
-		<Content Include="appsettings.json">
-			<CopyToOutputDirectory>Always</CopyToOutputDirectory>
-		</Content>
-
-		<Content Include="contentTypeMap.json">
-			<CopyToOutputDirectory>Always</CopyToOutputDirectory>
-		</Content>
-	</ItemGroup>
-
-	<ItemGroup>
-		<PackageReference Include="Microsoft.AspNetCore.App" />
-
-		<ProjectReference Include="..\..\Library\Sers\Sers.CL\Ipc\Sers.CL.Ipc.SharedMemory\Sers.CL.Ipc.SharedMemory.csproj" />
-		<ProjectReference Include="..\..\Library\Sers\Sers.CL\WebSocket\Sers.CL.WebSocket\Sers.CL.WebSocket.csproj" />
-		<ProjectReference Include="..\..\Library\Sers\Sers.CL\Zmq\FullDuplex\Sers.CL.Zmq.FullDuplex\Sers.CL.Zmq.FullDuplex.csproj" />
-		<ProjectReference Include="..\..\Library\Sers\Sers.CL\Zmq\ThreadWait\Sers.CL.ClrZmq.ThreadWait\Sers.CL.ClrZmq.ThreadWait.csproj" />
-		<ProjectReference Include="..\..\Library\Sers\Sers.Core\Sers.Core.Module.Api.ApiEvent.BeforeCallApi.JsonWebToken\Sers.Core.Module.Api.ApiEvent.BeforeCallApi.JsonWebToken.csproj" />
-		<ProjectReference Include="..\..\Library\Sers\Sers.Gateway\Sers.Gateway\Sers.Gateway.csproj" />
-	</ItemGroup>
+    <PropertyGroup>
+        <publish>Gateway</publish>
+        <docker>sers-gateway</docker>
+    </PropertyGroup>
+
+    <PropertyGroup>
+        <OutputType>Exe</OutputType>
+        <TargetFramework>net6.0</TargetFramework>
+        <Version>2.1.21-temp</Version>
+        <PackageProjectUrl>https://github.com/serset/Sers</PackageProjectUrl>
+    </PropertyGroup>
+
+
+    <ItemGroup>
+        <Content Include="appsettings.json">
+            <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+        </Content>
+
+        <Content Include="contentTypeMap.json">
+            <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+        </Content>
+    </ItemGroup>
+
+    <ItemGroup>
+        <PackageReference Include="Microsoft.AspNetCore.App" />
+
+        <ProjectReference Include="..\..\Library\Sers\Sers.CL\Ipc\Sers.CL.Ipc.SharedMemory\Sers.CL.Ipc.SharedMemory.csproj" />
+        <ProjectReference Include="..\..\Library\Sers\Sers.CL\WebSocket\Sers.CL.WebSocket\Sers.CL.WebSocket.csproj" />
+        <ProjectReference Include="..\..\Library\Sers\Sers.CL\Zmq\FullDuplex\Sers.CL.Zmq.FullDuplex\Sers.CL.Zmq.FullDuplex.csproj" />
+        <ProjectReference Include="..\..\Library\Sers\Sers.CL\Zmq\ThreadWait\Sers.CL.ClrZmq.ThreadWait\Sers.CL.ClrZmq.ThreadWait.csproj" />
+        <ProjectReference Include="..\..\Library\Sers\Sers.Core\Sers.Core.Module.Api.ApiEvent.BeforeCallApi.JsonWebToken\Sers.Core.Module.Api.ApiEvent.BeforeCallApi.JsonWebToken.csproj" />
+        <ProjectReference Include="..\..\Library\Sers\Sers.Gateway\Sers.Gateway\Sers.Gateway.csproj" />
+    </ItemGroup>
 
 </Project>

+ 2 - 2
dotnet/Gateway/App.Gateway/appsettings.json

@@ -160,12 +160,12 @@
           /* 在此Assembly中加载类 */
           "assemblyFile": "Sers.Core.Module.Api.ApiEvent.BeforeCallApi.JsonWebToken.dll",
           /* 动态加载的类名,必须继承接口 Sers.Core.Module.Api.ApiEvent.BeforeCallApi.IBeforeCallApi */
-          //"className": "JsonWebToken",
+          //"className": "Sers.Core.Module.Api.ApiEvent.BeforeCallApi.JsonWebToken.JsonWebToken",
           //在调用接口前,会获取 rpcData.http.headers.Authorization(格式为 "Bearer xxxxxx"),或cookie中的token, 并把jwt中的Claims信息放到 rpcData.user.userInfo
 
           "Secret": "default",
           // if token is valid,will set rpcData.caller.source to CallerSource
-          "//CallerSource": "Internal",
+          "CallerSource": "Internal",
           "//Issuer": "",
           "//Audience": [ "common" ]
         },

+ 4 - 4
dotnet/Library/Sers/Sers.Core/Sers.Core.Module.Api.ApiEvent.BeforeCallApi.JsonWebToken/JsonWebToken.cs

@@ -26,10 +26,10 @@ namespace Sers.Core.Module.Api.ApiEvent.BeforeCallApi.JsonWebToken
 
         public void Init(JObject config)
         {
-            Secret = config["Secret"].Value<String>();
-            CallerSource = config["CallerSource"].Value<String>();
-            Issuer = config["Issuer"].Value<String>();
-            Audience = config["Audience"].ToObject<List<string>>();
+            Secret = config["Secret"]?.Value<String>();
+            CallerSource = config["CallerSource"]?.Value<String>();
+            Issuer = config["Issuer"]?.Value<String>();
+            Audience = config["Audience"]?.Value<List<string>>();
         }
 
 

+ 6 - 6
dotnet/Library/Sers/Sers.Core/Sers.Core/Module/Api/ApiEvent/EventBuilder.cs

@@ -26,7 +26,7 @@ namespace Sers.Core.Module.Api.ApiEvent
         {
             if (events == null || events.Count == 0) return null;
 
-            Action<RpcContextData, ApiMessage> BeforeCallApi = null;           
+            Action<RpcContextData, ApiMessage> BeforeCallApi = null;
 
             foreach (JObject config in events)
             {
@@ -76,7 +76,7 @@ namespace Sers.Core.Module.Api.ApiEvent
                     return null;
                 }
 
-                return ObjectLoader.CreateInstance(className, assemblyFile: assemblyFile) as IBeforeCallApi;                
+                return ObjectLoader.CreateInstance(className, assemblyFile: assemblyFile) as IBeforeCallApi;
             }
             #endregion
         }
@@ -92,8 +92,8 @@ namespace Sers.Core.Module.Api.ApiEvent
         /// <param name="events"></param>
         /// <returns></returns>
         public static IEnumerable<IApiScopeEvent> LoadEvent_OnCreateScope(JArray events)
-        {       
-            if (events == null || events.Count == 0) yield break;     
+        {
+            if (events == null || events.Count == 0) yield break;
 
             IApiScopeEvent item;
             foreach (JObject config in events)
@@ -116,7 +116,7 @@ namespace Sers.Core.Module.Api.ApiEvent
                 //(x.x.3) return
                 yield return item;
             }
-        
+
 
             #region GetInstance
             IApiScopeEvent GetInstance(JObject config)
@@ -129,7 +129,7 @@ namespace Sers.Core.Module.Api.ApiEvent
                 if (string.IsNullOrEmpty(className)) return null;
 
                 //(x.2)CreateInstance
-                return ObjectLoader.CreateInstance(className, assemblyFile: assemblyFile) as IApiScopeEvent; 
+                return ObjectLoader.CreateInstance(className, assemblyFile: assemblyFile) as IApiScopeEvent;
             }
             #endregion
         }

+ 2 - 2
dotnet/ServiceCenter/App.Gover.Gateway/appsettings.json

@@ -160,12 +160,12 @@
           /* 在此Assembly中加载类 */
           "assemblyFile": "Sers.Core.Module.Api.ApiEvent.BeforeCallApi.JsonWebToken.dll",
           /* 动态加载的类名,必须继承接口 Sers.Core.Module.Api.ApiEvent.BeforeCallApi.IBeforeCallApi */
-          //"className": "JsonWebToken",
+          //"className": "Sers.Core.Module.Api.ApiEvent.BeforeCallApi.JsonWebToken.JsonWebToken",
           //在调用接口前,会获取 rpcData.http.headers.Authorization(格式为 "Bearer xxxxxx"),或cookie中的token, 并把jwt中的Claims信息放到 rpcData.user.userInfo
 
           "Secret": "default",
           // if token is valid,will set rpcData.caller.source to CallerSource
-          "//CallerSource": "Internal",
+          "CallerSource": "Internal",
           "//Issuer": "",
           "//Audience": [ "common" ]
         },

+ 8 - 0
dotnet/ServiceCenter/App.Gover.Gateway/wwwroot/_gover_/Scripts/Vit.SSO/AuthService.Env.js

@@ -1,7 +1,15 @@
 let AuthService_Config = {
     autoLogin: false,
+    onLoginSuccess: (accessToken) => {
+        // {access_token:'xx',expires_time:'1686857267655'}
+
+        //set token to cookie
+        let expires = new Date(parseInt(accessToken.expires_time));
+        document.cookie = "Authorization=" + escape(accessToken.access_token) + ";path=/;expires=" + expires.toGMTString();
+    },
     //audience: 'common',
     loginUrl: '/_gover_/Scripts/Vit.SSO/login.html',
+    //indexUrl: '/',
     ssoBaseUrl: 'https://sso.lith.cloud:4'
 };
 

+ 15 - 2
dotnet/ServiceCenter/App.Gover.Gateway/wwwroot/_gover_/Scripts/Vit.SSO/AuthService.js

@@ -54,6 +54,8 @@
                 expires_time: localStorage.getItem('jwt_token_expires_time')
             };
         };
+
+        //{access_token:'xx',expires_time:'1686857267655'}
         this.getToken = function () {
             var expires_time = parseInt(localStorage.getItem('jwt_token_expires_time'));
             if (expires_time) {
@@ -77,8 +79,9 @@
     function AuthService() {
         this.audience;
         this.loginUrl = '/login.html';
+        this.indexUrl = '/';
         this.ssoBaseUrl = 'https://sso.lith.cloud';
-
+        this.onLoginSuccess = null;
 
         this.accessToken = null;
         let self = this;
@@ -95,6 +98,8 @@
             if (redirect_uri) {
                 localStorage.removeItem('jwt_redirect_uri');
                 window.location.href = redirect_uri;
+            } else {
+                window.location.href = self.indexUrl;
             }
         };
 
@@ -107,6 +112,11 @@
                 var expires_time = authStore.getQueryString('expires_time');
                 this.accessToken = authStore.cacheToken({ access_token, expires_time });
                 if (this.accessToken) {
+                    try {
+                        if (this.onLoginSuccess) this.onLoginSuccess(this.accessToken);
+                    } catch (e) {
+                        console.log(e);
+                    }
                     jumpToPrevUrl();
                     return this.accessToken;
                 }
@@ -123,7 +133,8 @@
         this.logoff = function (redirect_uri) {
             this.accessToken = null;
             authStore.clearToken();
-            window.location.href = self.ssoBaseUrl + '/logoff.html?redirect_uri=' + encodeURIComponent(redirect_uri || location.href);
+            if (!redirect_uri) redirect_uri = new URL(this.indexUrl, location.origin).toString();
+            window.location.href = self.ssoBaseUrl + '/logoff.html?redirect_uri=' + encodeURIComponent(redirect_uri);
         };
 
 
@@ -146,6 +157,8 @@
         let config = (typeof (AuthService_Config) == 'object') ? AuthService_Config : {};
 
         if (config.loginUrl) authService.loginUrl = config.loginUrl;
+        if (config.indexUrl) authService.indexUrl = config.indexUrl;
+        if (config.onLoginSuccess) authService.onLoginSuccess = config.onLoginSuccess;
         if (config.ssoBaseUrl) authService.ssoBaseUrl = config.ssoBaseUrl;
         if (config.audience) authService.audience = config.audience;
 

+ 2 - 0
dotnet/ServiceCenter/App.Gover.Gateway/wwwroot/_gover_/index.html

@@ -137,6 +137,8 @@
                         <h4>login</h4>
                         <ul>
                             <li><a href="index.html">login</a></li>
+                            <li><a href="Scripts/Vit.SSO/login.html">Vit.SSO login</a></li>
+                            <li><a href="Scripts/Vit.SSO/logoff.html">Vit.SSO logoff</a></li>
                         </ul>
                     </div>
 

+ 19 - 5
dotnet/ServiceCenter/App.ServiceCenter/appsettings.json

@@ -312,12 +312,12 @@
           /* 在此Assembly中加载类 */
           "assemblyFile": "Sers.Core.Module.Api.ApiEvent.BeforeCallApi.JsonWebToken.dll",
           /* 动态加载的类名,必须继承接口 Sers.Core.Module.Api.ApiEvent.BeforeCallApi.IBeforeCallApi */
-          //"className": "JsonWebToken",
+          //"className": "Sers.Core.Module.Api.ApiEvent.BeforeCallApi.JsonWebToken.JsonWebToken",
           //在调用接口前,会获取 rpcData.http.headers.Authorization(格式为 "Bearer xxxxxx"),或cookie中的token, 并把jwt中的Claims信息放到 rpcData.user.userInfo
 
           "Secret": "default",
           // if token is valid,will set rpcData.caller.source to CallerSource
-          "//CallerSource": "Internal",
+          "CallerSource": "Internal",
           "//Issuer": "",
           "//Audience": [ "common" ]
         },
@@ -397,12 +397,12 @@
           /* 在此Assembly中加载类 */
           "assemblyFile": "Sers.Core.Module.Api.ApiEvent.BeforeCallApi.JsonWebToken.dll",
           /* 动态加载的类名,必须继承接口 Sers.Core.Module.Api.ApiEvent.BeforeCallApi.IBeforeCallApi */
-          //"className": "JsonWebToken",
+          //"className": "Sers.Core.Module.Api.ApiEvent.BeforeCallApi.JsonWebToken.JsonWebToken",
           //在调用接口前,会获取 rpcData.http.headers.Authorization(格式为 "Bearer xxxxxx"),或cookie中的token, 并把jwt中的Claims信息放到 rpcData.user.userInfo
 
           "Secret": "default",
           // if token is valid,will set rpcData.caller.source to CallerSource
-          "//CallerSource": "Internal",
+          "CallerSource": "Internal",
           "//Issuer": "",
           "//Audience": [ "common" ]
         },
@@ -700,9 +700,23 @@
           "api_httpMethod": "POST"
         },
 
+        {
+          /* 在此Assembly中加载类 */
+          "assemblyFile": "Sers.Core.Module.Api.ApiEvent.BeforeCallApi.JsonWebToken.dll",
+          /* 动态加载的类名,必须继承接口 Sers.Core.Module.Api.ApiEvent.BeforeCallApi.IBeforeCallApi */
+          //"className": "Sers.Core.Module.Api.ApiEvent.BeforeCallApi.JsonWebToken.JsonWebToken",
+          //在调用接口前,会获取 rpcData.http.headers.Authorization(格式为 "Bearer xxxxxx"),或cookie中的token, 并把jwt中的Claims信息放到 rpcData.user.userInfo
+
+          "Secret": "default",
+          // if token is valid,will set rpcData.caller.source to CallerSource
+          "CallerSource": "Internal",
+          "//Issuer": "",
+          "//Audience": [ "common" ]
+        },
+
         {
           //AccountInCookie 在调用接口前,会获取 rpcData.http.headers.Cookie(格式为 "user=xxx;c=7")中的user,在账号列表中比对userToken,回写 CallerSource(rpcData.caller.source) 和 userInfo(rpcData.user.userInfo)
-          "className": "AccountInCookie",
+          //"className": "AccountInCookie",
           "account": [
             {
               "userToken": "admin_123456",