npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nueip/cross-token-access

v2.3.0

Published

Cross-client access tokens

Downloads

328

Readme

SSO-自有系統前端 SSO 封裝(SDK) Ver 2.0

主要

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.com
  • nueip.site

使用說明

安裝

Script tag

<script src="your-path/cross-token-access.umd.min.js"></script>

npm

npm install @nueip/cross-token-access

用法

// 實體化
var tokenInjection = new TokenInjection(options);

範例

請見範例

Options

autopilot

  • Type: Boolean
  • Default: true
  • note: 是否自動初始化 & 刷新同步

sso_url

  • Type: String
  • Default: empty string
  • note: SSO 伺服器 URL

cookie_prefix

  • Type: String
  • Default: empty string
  • note: Cookie 自定義前綴字串

redirect_url

  • Type: String
  • Default: empty string
  • note: 重新定向網址

xhr_with

  • Type: Boolean
  • Default: false
  • note: 是否配置 X-Requested-With 抬頭

onLogout

  • Type: Function
  • Default: null
  • note: 非登入狀態的回調函式

unauthorized

  • Type: Function
  • Default: null
  • note: 401 未授權的 Callback

maxSyncTimesPerMinute

  • Type: number
  • Default: 3
  • note: 每分鐘同步 token 最大次數限制

maxRefreshTimesPerMinute

  • Type: number
  • Default: 3
  • note: 每分鐘刷新 token 最大次數限制

Methods

init()

  • 初始化執行
    • 自動同步/刷新 Token
    • 自動登出倒數

sync()

  • return

    • Promise 方法
  • 執行一次,向 oAuth Server 同步 Token 資訊,同步錯誤時,檢查是否為登入狀態,否時刪除 Token

autoSync(interval)

  • interval
    • Type: Number
    • Note: 多少個間隔,每個間為 1000 毫秒
  • 定期執行,向 oAuth Server 同步 Token 資訊
  • 執行條件
    • Cookie 中 tkchecksum 是否與 LocalStorage 中的 token_checksum 不一樣
    • Axios 未執行過或已執行完成
  • 多視窗時有可能同時執行,待觀察
  • 請求次數超過,自動登出
  • 執行錯誤時關閉自動同步 3 秒後重啟

autoSyncStop()

  • 停止自動同步 Token 內容

refresh()

  • return
    • Promise 方法
  • throw
    • 沒有 Refresh Token 時丟出
  • 執行一次,向 oAuth Server 執行 Refresh Token
  • 執行條件
    • 必需有 refresh_token 金鑰:localStorage.token_refresh_token
    • 當現在時間超過到期時間 - TokenRefreshBefore 時觸發更新 token

autoRefresh(interval)

  • interval
    • Type: Number
    • Note: 多少個間隔,每個間為 1000 毫秒
  • 定期執行,向 oAuth Server 同步 Token 資訊
  • 執行條件
    • 即將過期
    • Axios 未執行過或已執行完成
  • 多視窗時有可能同時執行,待觀察
  • 請求次數超過,自動登出
  • 執行錯誤時關閉自動同步 3 秒後重啟

autoRefreshStop

  • 停止自動刷新 Token

getToken()

  • return
    • Type: String
    • Local Storage 中的 Token
  • 取得 Local Storage Token

getLang()

  • return
    • Type: String
    • Cookie 中的語系代號
  • 取得當前語系

validate(token)

驗證 Token

  • token
    • Type: String
    • 本地端要被驗證的 Token
  • return
    • Promise 方法

loginIAM()

  • 開啟 IAM 登入頁面,另開新視窗
  • 轉導自動帶入GET參數 redirect_uri={指定重新定向網址}

logoutIAM()

  • 開啟 IAM 登出頁面

isLogin()

  • return
    • Boolean
  • 判斷是否為登入狀態

axiosCreate()

  • config
    • Type: Object
    • axios 請求參數
    • 只支援 baseURL, withCredentials, timeout, headers
  • return
    • Boolean
  • axios 全域設定輸入接口

瀏覽器支援

  • Chrome (latest)

  • Firefox (latest)

  • Safari (latest)

  • Edge (latest)

  • ~~Internet Explorer 11~~