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

cra-bs

v0.0.2

Published

用于引导用户使用自定义模版来初始化项目框架

Downloads

4

Readme

bsy-sso-login 使用文档

bsy-sso-login 是前端对接 SSO 登录的sdk。

快速开始

1. 安装

npm i -S bsy-sso-login

或者

yarn add bsy-sso-login

2. 在代码中使用

bsy-sso-login 本质上默认导出了一个异步的登录函数,所以你需要先在代码中引入它:

import ssoLogin from 'bsy-sso-sdk'

你需要传入以下参数:

import ssoLogin,{cleanAuthUrl} from 'bsy-sso-login'

ssoLogin(
  clientId, // 平台的ID,string(必填),找后端开发同学要
  debugMode // boolean(必填),在开发环境请开启调试模式,在生产环境请关闭调试模式
).then(accessToken=>{ // 异步函数执行的结果是 accessToken,使用 accessToken 来作为业务平台的登录请求的参数
    // 以下为示例:
    window.axios.post('/mtrpc/digital/bs.digital.auth.Auth/Login', {
        clientID: process.env.REACT_APP_SSO_CLIENT_ID,
        ssoToken: accessToken
      }).then(({ data }) => {
        cleanAuthUrl() // 请务必在登录之后调用这个函数(用于清除URL中已经被使用过的参数)
        window.localStorage.setItem('user-info', JSON.stringify(data))
      })
  })

拿到token之后,就可以在业务中发网络请求了。

如果token失效,则网络请求响应的code是1016,

所以你需要在网络请求中判断,如果code=1016,则需要清除原来保存的token信息,并且刷新页面, bsy-sso-login导出了一个token失效之后的处理函数,你可以在定义请求实例的时候使用它:

import { onTokenInvalid } from 'bsy-sso-login'

if (code === 1016) {
  onTokenInvalid()
}

一个使用示例

在 React 项目的根组件中:

// App.js
import React, { useEffect, useState } from 'react'
import Pages from './pages'
import { Spin } from 'antd'

import 'util/initRequest' // 初始化网络请求模块
import ssoLogin, { cleanAuthUrl } from 'bsy-sso-login'

import './App.css'

const App = () => {
  const [logining, setlogining] = useState(true)

  useEffect(() => {
    ssoLogin(
      [clientID],
      [debugMode],
    ).then(accessToken => {

      if (!accessToken) {
        setlogining(false)
      } else {
        window.axios.post('/mtrpc/digital/bs.digital.auth.Auth/Login', {
          clientID: process.env.REACT_APP_SSO_CLIENT_ID,
          ssoToken: accessToken
        }).then(({ data }) => {
          setlogining(false)
          cleanAuthUrl()
          window.localStorage.setItem('user-info', JSON.stringify(data))
        })
      }

    })
  }, [])

  return (
    <Spin spinning={logining} tip="正在获取SSO授权...">
      <Pages />
    </Spin>
  )
}

export default App

或者直接参考 /test 目录下的示例项目

SSO登录过程

SSO登录过程