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

tcloudauth-sdk

v0.0.53

Published

支付宝云开发业务扩展 web SDK

Readme

概览

支付宝云开发身份认证服务 SDK。

使用方法

登录

import { Auth } from "tcloudauth-sdk";
// 或者在html中引用 <script src="dist/tcloudauth-sdk-bundle.js"></script>

const auth = new Auth({
  envId: "your-env-id",
  userPoolUid: "your-userpool-uid",
  persistence: "local",
  //environment: "hz",
  //useHttps: true,
});
const idpUserId = "your-username";
const password = "your-password";
auth
  .loginWithUsernameAndPassword(idpUserId, password)
  .then((loginState) => {
    if (loginState) {
      // 用户名密码登录成功,有登录态
    }
  });

UserPool 是在云开发创建出来的,会分配一个 Uid,一般一个应用使用一个 UserPool 即可,云开发也支持创建多个。 使用 idpUserId+password 来识别用户身份,idp 为 Identity Provider 的简写,当前只支持传统用户名密码方式,后续可支持三方登陆和自定义 IDP 登陆。 登录成功后会返回 AccessToken+RefreshToken,通过 persistence 配置这两个 token 的存储位置,默认为 session:

  • none,不持久化,当前浏览器窗口关闭或刷新登录态即丢失
  • session,持久化在 SessionStorage 中,浏览器关闭登录态丢失
  • local,持久化在 LocalStorage 中,浏览器关闭后登录态仍保存

envId: 必传,设置云开发的 envId userPoolUid: 必传,设置云开发 UserPool 的 UID environment: 环境,支持 UAT(uat)和生产(hz)环境,默认生产环境。 useHttps: 是否使用 HTTPS,默认为 true。

获取 HTTP 鉴权头部

auth.getAuthHeader().then((res) => {
  // { "x-faas-context-authorization": "......" }
});

header 的值为 AccessToken 值。

刷新 token

auth.refreshAccessToken().then((res) => {
  // access token 刷新成功
});

AccessToken 有效期为 30 分钟,RefreshToken 有效期为 1 天,在有效期内可通过 RefreshToken 获取新 AccessToken。

登出

auth.logout();

登出后登录态被清除。

三方登录

支付宝登录

const alipayAuthProvider = auth.alipayAuthProvider({
  appId: 'your-app-id',
  scope: 'auth_user'
});

//跳转到支付宝登录页面
alipayAuthProvider.loginWithRedirect();

//支付宝登录页面重定向回来后,使用重定向的返回值登录
alipayAuthProvider.getRedirectResult().then((loginState) => {
  if (loginState) {
    //登录成功,有登录态
  }
});

appId参数是商家实际使用的 appId, scope参数可不填。