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

@alipay/faas-biz-web-sdk

v1.1.5

Published

支付宝云开发业务 SDK(WEB 端)

Downloads

95

Readme

WEB SDK

@alipay/faas-biz-web-sdk 可以在 Web 端(例如 PC Web 页面、H5 等)使用 Javascript 访问云开发用户身份服务。

安装

可以通过 npm 安装:

npm i @alipay/faas-biz-web-sdk

前置配置

参数:

| 字段 | 类型 | 必填 | 说明 | | --- | --- | --- | --- | | envId | string | 是 | 云开发的 envId | | userPoolUid | string | 是 | 云开发 UserPool 的 UID | | persistence | string | 否 | 登录成功后会返回AccessToken+RefreshToken,通过 persistence 配置这两个 token 的存储位置,默认为 session:

  • none,不持久化,当前浏览器窗口关闭或刷新登录态即丢失
  • session,持久化在 SessionStorage 中,浏览器关闭登录态丢失
  • local,持久化在 LocalStorage 中,浏览器关闭后登录态仍保存 | | environment | string | 否 | 环境,当前仅支持生产(hz)环境,默认为 hz | | useHttps | boolean | 否 | 是否使用 HTTPS,默认为 true |

UserPool 是在云开发创建出来的,会分配一个 Uid,一般一个应用使用一个 UserPool 即可,云开发也支持创建多个。 示例代码:

import { Auth } from "@alipay/faas-biz-web-sdk";

const auth = new Auth({
  envId: "your-env-id",
  userPoolUid: "your-userpool-uid",
  persistence: "local"
});

API

loginWithUserIdAndPassword()

接口功能:用户名密码登录 输入参数:

| 字段 | 类型 | 必填 | 说明 | | --- | --- | --- | --- | | idpUserId | string | 是 | 用户UID | | password | string | 是 | 密码 |

返回结果:

| 字段 | 类型 | 不为空 | 说明 | | --- | --- | --- | --- | | user | User | 是 | 用户信息 | | loginType | string | 是 | 登录方式 | | isAlipayAuth | boolean | 是 | 支付宝三方登录 | | isUsernameAuth | boolean | 是 | 账密登录 |

示例代码:

import { Auth } from "@alipay/faas-biz-web-sdk";

const userPoolConfig = {
	envId: 'your-env-id',
	userPoolUid: 'your-userPool-uid',
};
const auth = new Auth(userPoolConfig);
auth.loginWithUsernameAndPassword(username, password).then((res) => {
	// 登录成功
});

getAuthHeader()

接口功能:获取 HTTP 鉴权头部,如果未登录,则返回 null。 输入参数:无 返回结果:

| 字段 | 类型 | 不为空 | 说明 | | --- | --- | --- | --- | | x-faas-context-authorization | string | 是 | 鉴权头部信息 |

示例代码:

import { Auth } from "@alipay/faas-biz-web-sdk";

const userPoolConfig = {
	envId: 'your-env-id',
	userPoolUid: 'your-userPool-uid',
};
const auth = new Auth(userPoolConfig);
auth.getAuthHeader().then((ah) => {
	//获取鉴权头部成功
});

getCurrentUser()

接口功能:获取当前登录用户对象,如果未登录,则返回 null。 输入参数:无 返回结果:

| 字段 | 类型 | 不为空 | 说明 | | --- | --- | --- | --- | | user | User | 是 | 用户对象 |

示例代码:

import { Auth } from "@alipay/faas-biz-web-sdk";

const userPoolConfig = {
	envId: 'your-env-id',
	userPoolUid: 'your-userPool-uid',
};
const auth = new Auth(userPoolConfig);
auth.getCurrentUser()
		.then((res) => {
			//获取当前登录用户对象成功
		});

logout()

接口功能:退出登录 输入参数:无 返回结果:无 示例代码:

import { Auth } from "@alipay/faas-biz-web-sdk";

const userPoolConfig = {
	envId: 'your-env-id',
	userPoolUid: 'your-userPool-uid',
};
const auth = new Auth(userPoolConfig);
auth.logout();

三方登录

支付宝
getAlipayAuthProvider().loginWithRedirect()

接口功能:跳转到支付宝登录页面 输入参数:

| 字段 | 类型 | 必填 | 说明 | | --- | --- | --- | --- | | appId | string | 是 | 商户的 appId |

返回结果:无 示例代码:

import { Auth } from "@alipay/faas-biz-web-sdk";

const userPoolConfig = {
	envId: 'your-env-id',
	userPoolUid: 'your-userPool-uid',
};
const auth = new Auth(userPoolConfig);
const authProvider = auth.getAlipayAuthProvider();
authProvider.loginWithRedirect({
	appId: 'your-app-id'
});
getAlipayAuthProvider().getRedirectResult()

接口功能:支付宝登录页面重定向回来后,使用重定向的返回值登录,并获取登录态。 输入参数:

| 字段 | 类型 | 必填 | 说明 | | --- | --- | --- | --- | | createUser | boolean | 否 | 当支付宝 openid 没有对应的云开发用户时,是否自动创建一个新的云开发用户,默认为 true |

返回结果:

| 字段 | 类型 | 不为空 | 说明 | | --- | --- | --- | --- | | user | User | 是 | 用户信息 | | loginType | string | 是 | 登录方式 | | isAlipayAuth | boolean | 是 | 支付宝三方登录 | | isUsernameAuth | boolean | 是 | 账密登录 |

示例代码:

import { Auth } from "@alipay/faas-biz-web-sdk";

const userPoolConfig = {
	envId: 'your-env-id',
	userPoolUid: 'your-userPool-uid',
};
const auth = new Auth(userPoolConfig);
const authProvider = auth.getAlipayAuthProvider();
authProvider.getRedirectResult()
	.then((res) => {
		//登录成功
	});