Cross-client access tokens
npm install @nueip/cross-token-access``text`
dist/
├── cross-token-access.cjs.js (CommonJS)
├── cross-token-access.cjs.min.js (CommonJS, compressed)
├── cross-token-access.umd.js (UMD)
└── cross-token-access.umd.min.js (UMD, compressed)
依賴:
- axios
- lodash
- js-cookie
- promise.prototype.finally
注意事項:
- 依賴套件已打包封裝,無需再外部引用
- API 採用 Axios 技術
- Axios 支援 finally,引用 promise.prototype.finally 方法
- Axios 攔截器 (interceptor) 有加入請求重複發送機制
- nueip.comnueip.site
-
Script tag
`html`
npm
`bash`
npm install @nueip/cross-token-access
`js`
// 實體化
var tokenInjection = new TokenInjection(options);
- options
- Type: Object
- 參考 options
請見範例
- Type: Booleantrue
- Default:
- note: 是否自動初始化 & 刷新同步
- Type: Stringempty string
- Default:
- note: SSO 伺服器 URL
- Type: Stringempty string
- Default:
- note: Cookie 自定義前綴字串
- Type: Stringempty string
- Default:
- note: 重新定向網址
- Type: Booleanfalse
- Default:
- note: 是否配置 X-Requested-With 抬頭
- Type: Functionnull
- Default:
- note: 非登入狀態的回調函式
- Type: Functionnull
- Default:
- note: 401 未授權的 Callback
- Type: number
- Default: 3
- note: 每分鐘同步 token 最大次數限制
- Type: number
- Default: 3
- note: 每分鐘刷新 token 最大次數限制
- 初始化執行
- 自動同步/刷新 Token
- 自動登出倒數
- return
- Promise 方法
- 執行一次,向 oAuth Server 同步 Token 資訊,同步錯誤時,檢查是否為登入狀態,否時刪除 Token
- interval
- Type: Number
- Note: 多少個間隔,每個間為 1000 毫秒
- 定期執行,向 oAuth Server 同步 Token 資訊
- 執行條件
- Cookie 中 tkchecksum 是否與 LocalStorage 中的 token_checksum 不一樣
- Axios 未執行過或已執行完成
- 多視窗時有可能同時執行,待觀察
- 請求次數超過,自動登出
- 執行錯誤時關閉自動同步 3 秒後重啟
- 停止自動同步 Token 內容
- return
- Promise 方法
- throw
- 沒有 Refresh Token 時丟出
- 執行一次,向 oAuth Server 執行 Refresh Token
- 執行條件
- 必需有 refresh_token 金鑰:localStorage.token_refresh_token
- 當現在時間超過到期時間 - TokenRefreshBefore 時觸發更新 token
- interval
- Type: Number
- Note: 多少個間隔,每個間為 1000 毫秒
- 定期執行,向 oAuth Server 同步 Token 資訊
- 執行條件
- 即將過期
- Axios 未執行過或已執行完成
- 多視窗時有可能同時執行,待觀察
- 請求次數超過,自動登出
- 執行錯誤時關閉自動同步 3 秒後重啟
- 停止自動刷新 Token
- return
- Type: String
- Local Storage 中的 Token
- 取得 Local Storage Token
- return
- Type: String
- Cookie 中的語系代號
- 取得當前語系
驗證 Token
- token
- Type: String
- 本地端要被驗證的 Token
- return
- Promise 方法
- 開啟 IAM 登入頁面,另開新視窗
- 轉導自動帶入GET參數 redirect_uri={指定重新定向網址}
- 開啟 IAM 登出頁面
- return
- Boolean
- 判斷是否為登入狀態
- config
- Type: Object`
- axios 請求參數
- 只支援 baseURL, withCredentials, timeout, headers
- return
- Boolean
- axios 全域設定輸入接口
- ### Chrome (latest)
- ### Firefox (latest)
- ### Safari (latest)
- ### Edge (latest)
- ### ~~Internet Explorer 11~~