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

f1-passport

v1.1.0

Published

F1Passport SDK 是Fox.One Cloud API 的接口的封装。

Downloads

2

Readme

F1Passport SDK

F1Passport SDK 是Fox.One Cloud API 的接口的封装。

  • 滑块
  • 用户登陆
  • 用户注册
  • 获取用户信息
  • 商户登陆

Fox.One Cloud API 以及 GateWay API 的接口都需要签名和生成动态的Token,PassportSDK 同时提供了访问网关的签名API

  • 生成Token
  • 解析Token
  • 生成Sign

安装

yarn add f1-passport

使用

Passport 不会存储 Session 和用户信息,由使用F1-Passport的接入放自行存储 Passport 登陆后获取到的数据结构大致如下,session为后续接入方发送请求时签名的必要字段

{
    "user":
     {
    //...
    },
    "session": {
        "key": "xxxx",
        "secret":"xxx"
    }
}

Passport

用户登陆模块

import { Passport } from 'f1-passport';

// 实例化 Passport
const passport = new Passport({
  host: constants.passportHost,
  merchantId: constants.merchantId,
});
// 获取滑块
passport.getCaptcha()

// 获取注册验证码 邮箱 手机二选一
passport.requestRegister({regionCode,
        mobile,
        captchaId,
        captchaCode,
        email})
return {token:''}

// 注册 name可不传
passport.register({
        name,
        code,
        password,
        token,
    })
return {user:{},session:{}}
// 获取手机登录验证码
passport.requestLoginSMS({
        regionCode,
        mobile,
        captchaId,
        captchaCode
    })
return {token:''}

// 手机登陆
passport.mobileLogin({
        token,
        mobileCode,
})
return {user:{},session:{}}

// 账户密码登陆
// mobile 或者邮箱为选填字段
passport.login({ password: rawPassword, mobile, email })
return {user:{},session:{}}

// 获取用户信息
passport.getUserDetail({secret, key})
return {user:{}}

Admin

商户模块

import { Admin } from 'f1-passport';

const admin = new Admin({
  host: constants.adminHost,
});
// 商户登陆
admin.login({ password: rawPassword, username})
return {admin:{},session:{}}

Sign

签名函数

import { generateSignRequest, generateSignAndJWT } from 'f1-passport';

const signData = generateSignRequest({ method: 'get', url: pathAndQuery, body: options.body });
return { uri, body, sign }

Token

生成请求的Token

import { generateToken, decodeToken } from 'f1-passport';

const token = await generateToken({ key: session.key, secret: session.secret, requestSign: signData.sign });

Password Salt

密码加盐

import { passwordSalt } from 'f1-passport';
const salePassword = passwordSalt(password);

Fox Cloud API 和 Gateway API 的调用说明

当业务方为 User,Maker 时必须在 Http Header里添加请求头 'fox-merchant-id':'xxxxxxx'

所有的业务方在有用户session时,发送的请求都需要默认的加上 "Authorization": Bearer ${token} }

token 为上述 Token 章节生成的动态token,每次都不一样,需要每次创建新的Token

Host

Admin https://dev-gateway.fox.one/ admin login https://dev-gateway.fox.one/admin/login

Maker https://dev-cloud.fox.one/ maker login https://dev-cloud.fox.one/api/account/login

Example

一个具体实际的例子,传入的url为完整的url,函数正则截取 host 对host 之后的path进行签名和请求

const regexSt = new RegExp('^https://[a-zA-Z0-9.-]*/');

async function signAndRequest(session, url, options) {
  let host = url.match(regexSt)[0];
  host = host.substring(0, host.length - 1);

  const pathAndQuery = url.replace(regexSt, '/');
  const signData = generateSignRequest({ method: options.method, url: pathAndQuery, body: options.body });
  const token = await generateToken({ key: session.key, secret: session.secret, requestSign: signData.sign });
  const finalUrl = `${host}${signData.uri}`;
  const headers = {
    ...options.headers,
    Authorization: `Bearer ${token}`,
  };
  const newOptions = {
    ...options,
    method: options.method,
    body: JSON.stringify(signData.body),
    headers,
  };
  return window.fetch(finalUrl, newOptions);
}

Playground

以下为已集成了 passportsdk 的模版 FoxOne Admin 模版 FoxONE Maker 模板工程