Refactor Word Add-in authentication to use e-Court pass-through; remove Keycloak integration
- Updated documentation to reflect removal of login and transition to e-Court pass-through authentication. - Modified `authService` to handle authentication via custom properties in documents without user login. - Adjusted `apiClient` to immediately throw `AuthRequiredError` for invalid tokens, as refresh tokens are no longer applicable. - Revised UI flow to accommodate new authentication method, including changes to state management and error handling. - Added new requirements document outlining the add-in workflow and authentication process.
This commit is contained in:
parent
6ce071ee14
commit
50af6c10fa
9 changed files with 161 additions and 197 deletions
44
docs/requirement/addin-workflow.md
Normal file
44
docs/requirement/addin-workflow.md
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
# ขั้นตอนการทำงานของ Addin
|
||||
|
||||
## 1. เมื่อเปิดเอกสาร
|
||||
|
||||
- อ่าน custom property ของ word
|
||||
1. ticket_data ซึ่งจะมีข้อมูลเบื้องต้น ดังนี้
|
||||
```jsonc
|
||||
{
|
||||
"exp": 1793067433,
|
||||
"fid": "T12_FD155_3s-long_ZZZ",
|
||||
"tid": "T12",
|
||||
"uid": "oom",
|
||||
"uname": "สรวิชญ์",
|
||||
}
|
||||
```
|
||||
2. นำค่า ticket_data ที่เป็น string ก่อนนำไปแปลง json ทำการ sign HMAC-SHA256 โดยใช้ secret "super_secret" ซึ่งต้องรองรับการ config ค่านี้ในอนาคต
|
||||
3. นำค่าที่ sign ได้ มาเทียบกับค่า property "HmacSha256"
|
||||
- ขั้นตอนการทำ authen
|
||||
```
|
||||
ขั้นตอน
|
||||
1. เมื่อเปิดไฟล์ Word ให้อ่าน Custom Property 2 ค่าที่ฝังมาในไฟล์ คือ value จริง และ Hash Value (HMAC) เพื่อตรวจสอบว่าไฟล์สร้างผ่านระบบอย่างถูกต้อง
|
||||
2. ถ้า HMAC ไม่ตรงกัน แสดงว่าไฟล์ถูกแก้ไข ให้ Add-in disable การทำงานทั้งหมด
|
||||
3. ถ้า HMAC ตรงกัน ให้เก็บค่า uId, uName, fId, tid ไว้ แล้วตรวจสอบว่า userId นี้มีใน localStorage อยู่แล้วหรือไม่
|
||||
4. ถ้ายังไม่มีให้ตรวจค่า Exp ที่ได้จากไฟล์ Word
|
||||
- หมดอายุ → disable Add-in ทั้งหมด
|
||||
- ยังไม่หมดอายุ → เก็บใน localStorage
|
||||
- userName: ค่าจาก uName
|
||||
- คีย์คือ fid: เอาค่า {
|
||||
"userid": uid,
|
||||
"username": uname,
|
||||
"fid": fid (เป็น string),
|
||||
"tid": tid
|
||||
}
|
||||
ไปทำการขอ token ที่ /api/documents/token แล้วนำค่าที่ได้มาเก็บไว้ที่ตัวแปรนี้ เพื่อให้อ่านค่าไปใช้ให้ตรงกับค่า fid ที่ได้รับ เนื่องจาก api ในส่วน /documents จะต้องแนบ token ไปไม่ส่งค่าไปตรงๆ เพื่อความถูกต้อง
|
||||
5. ถ้ามี Session อยู่แล้ว ให้ตรวจว่า userId ตรงกับ Session หรือไม่
|
||||
6. ถ้า userId ไม่ตรงกัน (user ใหม่) ให้ตรวจค่า Expire
|
||||
- ยังไม่หมดอายุ → เคลียร์ Session เดิม แล้วสร้าง Session 2 ค่าใหม่
|
||||
- หมดอายุ → disable Add-in ทั้งหมด
|
||||
7. ถ้า userId ตรงกัน (คนเดิม) ให้ตรวจว่า fid มีใน localStorage แล้วหรือไม่
|
||||
- มีแล้ว (กลับมาทำเอกสารเดิม) → ผ่านได้เลย ไม่ต้องตรวจ Expire
|
||||
- ยังไม่มี (เอกสารใหม่) → ตรวจค่า Expire
|
||||
- ยังไม่หมดอายุ → ทำการขอ token แล้วเก็บใน localStorage ตามขั้นตอนก่อนหน้า
|
||||
- หมดอายุ → disable Add-in ทั้งหมด
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue