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

@seayoo-account/login

v1.1.4

Published

seayoo account login sdk

Downloads

218

Readme

世游通行证 SSO 登录组件

本 SDK 支持在浏览器端和微信小程序端使用,以完成世游通行证的登录。

login() 登录原理

  • SDK 以全屏 iframe 方式打开世游通行证 login 页面
  • 用户完成登录后,login 页面通过 postMessage 方式将 id token 发送给 SDK
  • 调用页面将 id token 发送给后端 api 进行验证
  • 验证通过后返回一个授权的信息(jwt or session Cookie)来进行后续 api 调用

注意

  • id token 仅仅用于验证,时效性很短,不能用于实际业务 api 通讯;
  • 登录调用将会受到域名白名单限制,本地调试请修改 host 使用,否则将会被拒绝;
  • 后端 api 验证逻辑另有 SDK 可用;

mpLogin() 登录原理

首次登录

  • 通过手机号快速验证组件向用户申请手机号,获得动态令牌 code
  • 将 code 发送给通行证进行用户资料获取
  • 通行证将 user id / token / id token 返回给小程序
  • 小程序保存 user id / token 到本地,并将 id token 发送给自己后端 api 进行验证
  • 验证通过后返回一个授权的信息来进行后续 api 调用

再次登录

  • 通过缓存在本地的 user id / token 调用通行证进行登录验证
  • 如果验证失败(比如超时或用户设备记录删除)则进入首次登录流程
  • 验证通过后返回 id token 给小程序
  • 小程序将 id token 发送给自己后端 api 进行验证
  • 验证通过后返回一个授权的信息来进行后续 api 调用

发布

  • 发布到 npmjs.com:
  • 如果设置了 npm 镜像, 需要恢复: npm config set registry https://registry.npmjs.org/
  • 执行: pnpm -F login pub

开发说明

使用 login 函数进行拉起登录界面, 输入参数如下, 输出参数为 Promise<string | false | Error> 注意对输出进行判断:

export function login(
  { endpoint: Endpoint,
    timeout: number = 6000,
    backgroundOpacity: number = 0.7,
    isAnonymous: boolean = false
  }
): Promise<string | false | Error>

注意: 尽量使用 preload 方法提前加载登录页面, 可以大大加快 login 的时候显示页面的速度(原理是提前加载了登录页,获取了网页资源,当真正 login 的时候, 直接显示 preload 的网页资源)

export function preload(endpoint: Endpoint, isAnonymous: boolean = false)
// 代码示例:
import { preload } from "@seayoo-account/login";
preload("account.seayoo.com", false)

代码示例

非匿名登录

// 代码示例:
import { login } from "@seayoo-account/login";

const idToken: Ref<string> = ref("");

async function doLoginProd() {
  const data = (await login({ endpoint: "account.seayoo.com"})) || "";
  if (typeof data === "string") {
    idToken.value = data;
  } else {
    console.error("data :>> ", data);
  }
}

匿名登录

import { login } from "@seayoo-account/login";

const idToken: Ref<string> = ref("");

async function doLoginProdAnonymouse() {
  const data = (await login({ endpoint: "account.seayoo.com", isAnonymous: true })) || "";
  if (typeof data === "string") {
    idToken.value = data;
  } else {
    console.error("data :>> ", data);
  }
}