فهرست منبع

开放平台阶段性保存

CrazyIter_Bin 4 سال پیش
والد
کامیت
046f8ba7f1

+ 4 - 2
TEAMModelOS.SDK/Extension/JwtAuthExtension.cs

@@ -44,12 +44,14 @@ namespace TEAMModelOS.SDK.Extension
         }
         public static string CreateAppToken(string issuer, string id,  string salt, string schoolID = "", int expire = 1)
         {
+           
             // 設定要加入到 JWT Token 中的聲明資訊(Claims)  
             var payload = new JwtPayload {
                 { JwtRegisteredClaimNames.Iss, issuer }, //發行者
-                { JwtRegisteredClaimNames.Sub, id }, // 用戶ID                  
+                { JwtRegisteredClaimNames.Sub, id }, // APPID                  
                 { JwtRegisteredClaimNames.Azp,schoolID}, // 學校簡碼,如果有的話
-                { JwtRegisteredClaimNames.Exp,DateTimeOffset.UtcNow.AddHours(expire).ToUnixTimeSeconds().ToString()},  // 到期的時間,必須為數字
+                {"hash",Guid.NewGuid().ToString() }
+                //{ JwtRegisteredClaimNames.Exp,DateTimeOffset.UtcNow.AddHours(expire).ToUnixTimeSeconds().ToString()},  // 到期的時間,必須為數字
                 //{ "name",name}, // 用戶的顯示名稱
                 //{ "picture",picture}, // 用戶頭像
                 //{ "roles",roles}, // 登入者的角色,角色類型 (Admin、Teacher、Student) 

+ 6 - 1
TEAMModelOS.SDK/Models/Cosmos/Api/OpenApi.cs

@@ -26,7 +26,7 @@ namespace TEAMModelOS.SDK.Models
     {
         public OpenApi() {
 
-            PartitionKey = "OpenApi";
+            PartitionKey = "IES5-API";
         } 
         public string name { get; set; }
         public string url { get; set; }
@@ -36,11 +36,16 @@ namespace TEAMModelOS.SDK.Models
     }
 
     public class OpenApp : CosmosEntity {
+        public string icon { get; set; }
         public string name { get; set; }
         public string descr { get; set; }
         public List<string> apis { get; set; } = new List<string>();
         public string school { get; set; }
         public string token { get; set; }
+        /// <summary>
+        /// 0禁用,1正常,2 token封禁
+        /// </summary>
+        public int status { get; set; }
         public OpenApp()
         {
             pk = "OpenApp";

+ 3 - 3
TEAMModelOS/Controllers/Core/OpenApiController.cs

@@ -53,7 +53,7 @@ namespace TEAMModelOS.Controllers.Core
         /// <param name="requert"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin")]
+        //[AuthToken(Roles = "admin")]
         [HttpPost("create-token")]
         public async Task<IActionResult> CreateToken(JsonElement request) {
             try
@@ -67,14 +67,13 @@ namespace TEAMModelOS.Controllers.Core
                     var response = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(id.GetString(), new PartitionKey($"OpenApp-{code}")) ;
                     if (response.Status == 200)
                     {
-                        
                         using var json = await JsonDocument.ParseAsync(response.ContentStream);
                         var info = json.ToObject<OpenApp>();
                         //创建Token
                         var auth_token = JwtAuthExtension.CreateAppToken(_option.HostName, info.id, _option.JwtSecretKey, info.school);
                         info.token = auth_token;
                         info = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync(info, info.id, new PartitionKey($"{info.code}"));
-                        return Ok(auth_token);
+                        return Ok(new { auth_token });
                     }
                     else
                     {
@@ -146,6 +145,7 @@ namespace TEAMModelOS.Controllers.Core
                     {
                         using var json = await JsonDocument.ParseAsync(response.ContentStream);
                         var info = json.ToObject<OpenApp>();
+                        request.token = info.token;
                         request = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync(request, info.id, new PartitionKey($"{info.code}"));
                     }
                     else