何時使用
以下情況適合使用簽署身分:- 訪客已登入你的產品
- 你想把回覆連到自己的使用者 ID
- 你需要姓名或 email 由後端提供
取得網站密鑰
在儀表板建立該網站的第一組 identity signing secret。TinyInbox 只會顯示新的密鑰一次,因此離開頁面前請先複製到你的後端環境變數。 你也可以從 API 建立或輪替:identitySecret,且只顯示這一次。既有密鑰不會再次回傳。
簽署 token
身分 token 必須:- 使用
HS256演算法 - 如果你的 JWT library 會設定 type header,請使用
typ: "JWT"。沒有typ的 token 可以接受,但其他typ值會被拒絕。 - 將
aud設為tinyinbox-widget-identity - 包含
userId或sub - 可選擇包含
name、email和siteKey - 設定短時間過期
傳給小工具
提供一個瀏覽器可呼叫、會回傳{ identityToken } 的 endpoint,然後從 client-only code 把這個 token 傳給 widget。請繼續使用 TinyInbox 儀表板複製出來的 widget script;不要在應用程式碼裡重新組合 widget URL 或 site key。
如果你對已登入訪客使用 signed identity,不要再為同一位訪客呼叫 TinyInbox.identify({ name, email })。可信任的 name 和 email 應該放在 signed token 裡;兩種方式同時使用可能先建立匿名 session,接著又切換到 signed visitor session。
對於已登入 app 頁面,請在 auth state 已知後取得 token,然後傳給 TinyInbox。如果這段程式碼可以在複製的 widget script 載入前執行,指令會先排入 queue,第一個 widget session 就會是 signed visitor。
data-tinyinbox-identity 屬性直接提供 token。