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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@kyleit/auth-sdk

v1.0.0

Published

VanillaJS Auth SDK for GH Platform

Downloads

118

Readme

🛡️ GH Platform – JavaScript Auth SDK (Multi‑Tenant Version)

SDK JavaScript hỗ trợ đăng nhập (login), làm mới token (refresh), kiểm tra token (introspect),
và tự động xác thực request HTTP trong kiến trúc multi‑tenant của GH Platform.


🚀 Tính năng chính

  • ✅ Hỗ trợ login, refresh, introspect
  • Tenant‑aware client: mọi API tự động gắn {tenant} vào URL
  • ✅ Middleware AuthFetch tự động gắn Bearer token + auto refresh
  • ✅ Hoạt động cả browser & Node.js
  • ✅ Hỗ trợ nhúng trực tiếp (auth-sdk.min.js) hoặc cài qua npm

🧱 Kiến trúc Multi‑Tenant

Mọi API của GH Platform Authenticate đều sử dụng dạng:

/api/v1/{tenant}/auth/login
/api/v1/{tenant}/auth/refresh
/api/v1/{tenant}/auth/introspect

JavaScript SDK tự động truyền tenant trong mọi request.

✳️ Khởi tạo client theo tenant

const tenant = "demo"; // hoặc trích xuất từ email: [email protected] → example.com

const client = new AuthClient({
  baseUrl: "https://auth.example.com",
  tenant
});

const storage = new TokenStorage("auth", tenant);
const fetcher = new AuthFetch(client, storage);

📌 TokenStorage cũng tách token theo tenant

// Lưu token theo từng tenant
storage.accessToken = res.access_token;
storage.refreshToken = res.refresh_token;

// Key lưu trong localStorage sẽ giống:
// auth.demo.access_token
// auth.demo.refresh_token

📦 Cài đặt

🔹 Cách 1 – Cài qua NPM

npm install @gh-platform/auth-sdk

Import:

import { AuthClient, AuthFetch, TokenStorage } from "@gh-platform/auth-sdk";

🔹 Cách 2 – Dùng trực tiếp trên Web (HTML thuần)

<script src="https://cdn.yourdomain.com/auth-sdk.min.js"></script>
<script>
  const { AuthClient, AuthFetch, TokenStorage } = window.AuthSDK;
</script>

🔐 Ví dụ Multi‑Tenant Login

const tenant = "example";
const client = new AuthClient({
  baseUrl: "https://auth.example.com",
  tenant
});

async function login() {
  const res = await client.login(
    "[email protected]", // identifier
    "User@123",          // password
    "gh-platform-admin"  // client_id
  );

  storage.accessToken = res.access_token;
  storage.refreshToken = res.refresh_token;

  console.log("Login success!", res);
}

🌐 Fetch API với AuthFetch (auto refresh + retry)

const fetcher = new AuthFetch(client, storage);

const resp = await fetcher.fetch(
  client.baseUrl + "/api/v1/" + tenant + "/auth/me"
);

const user = await resp.json();
console.log("User:", user);

Tự động:

  • Gắn Authorization: Bearer <access_token>
  • Nếu token hết hạn → tự refresh → retry request
  • Lưu token đúng tenant

🔧 Build hướng dẫn

npm install vite terser -D
npm run build
npx terser dist/auth-sdk.umd.js -o dist/auth-sdk.min.js --compress --mangle

🌐 Demo HTML

<!DOCTYPE html>
<html>
<head><title>Auth SDK Demo</title></head>
<body>
  <button id="login">Login</button>
  <button id="getUser">Get Profile</button>

  <script src="./dist/auth-sdk.min.js"></script>
  <script>
    const tenant = "demo";

    const { AuthClient, TokenStorage, AuthFetch } = window.AuthSDK;
    const client = new AuthClient({ baseUrl: "https://auth.example.com", tenant });
    const storage = new TokenStorage("auth", tenant);
    const fetcher = new AuthFetch(client, storage);

    document.getElementById("login").onclick = async () => {
      const res = await client.login("[email protected]", "User@123", "gh-platform-admin");
      storage.accessToken = res.access_token;
      storage.refreshToken = res.refresh_token;
      alert("Login success!");
    };

    document.getElementById("getUser").onclick = async () => {
      const r = await fetcher.fetch(client.baseUrl + "/api/v1/" + tenant + "/auth/me");
      console.log("User:", await r.json());
    };
  </script>
</body>
</html>

🧾 License

Bản quyền © 2025 GH Platform – Phát hành theo giấy phép MIT