CrazyIter_Bin 1 year ago
parent
commit
e102d7f4fc

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

@@ -15,7 +15,7 @@ namespace TEAMModelOS.SDK.Extension
 {
     public static class JwtAuthExtension
     {
-        public static string CreateAuthToken(string issuer, string id, string name, string picture, string salt, string scope, string Website, string areaId = "", string schoolID = "", string standard = "", string[] roles = null, string[] permissions = null, int expire = 1)
+        public static string CreateAuthToken(string issuer, string id, string name, string picture, string salt, string scope, string Website, string areaId = "", string schoolID = "", string standard = "", string[] roles = null, string[] permissions = null, int expire = 1,int year=-1)
         {
             // 設定要加入到 JWT Token 中的聲明資訊(Claims)  
             var payload = new JwtPayload {
@@ -32,7 +32,10 @@ namespace TEAMModelOS.SDK.Extension
                 { "area",areaId==null?"":areaId},
                 { JwtRegisteredClaimNames.Website,Website},
             };
-
+            //学生入学年
+            if (year!=-1) {
+                payload.Add("year", year);
+            }
             // 建立一組對稱式加密的金鑰,主要用於 JWT 簽章之用
             var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(salt));
             // HmacSha256 有要求必須要大於 128 bits,所以 salt 不能太短,至少要 16 字元以上

+ 1 - 1
TEAMModelOS/Controllers/Student/StudentController.cs

@@ -672,7 +672,7 @@ namespace TEAMModelOS.Controllers
             var (blob_uri, blob_sas) = _azureStorage.GetBlobContainerSAS(school_code.ToLower(), BlobContainerSasPermissions.Read);
 
             //換取AuthToken,提供給前端
-            var auth_token = JwtAuthExtension.CreateAuthToken(_option.HostName, id, name, picture, _option.JwtSecretKey, scope: Constant.ScopeStudent, Website: "IES", areaId: areaId, schoolID: school_code, roles: new[] { "student" }, expire: 1);
+            var auth_token = JwtAuthExtension.CreateAuthToken(_option.HostName, id, name, picture, _option.JwtSecretKey, scope: Constant.ScopeStudent, Website: "IES", areaId: areaId, schoolID: school_code, roles: new[] { "student" }, expire: 1,year: student.year);
 
             //用户在线记录
             try