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

jwork-auth-middle

v1.0.0

Published

佛山简为单点登录中间件

Downloads

2

Readme

INSTALL

yarn add @iwhale/user-auth-middle --registry=http://10.10.178.55:8084/nexus/repository/cb-npm

USAGE

1.中间件配置 edit your config located in $WORKDIR/config/config_xxx.js

...
    middleware:{
        foshanUserAuth: {
		  enable: true, // 是否启用该中间件
		  module: '../middleware/foshanauthmiddle',//中间件包
		  config: { // 需传入配置
			ssoLoginUrl: 'http://121.201.125.236/bsp',
			tokenAuthUrl: 'http://121.201.125.236/api/ums/login',
			cookieName: 'honeycomb_token',
			tokenVar: 'token',
			expiresTime: 18000, // 单位 秒
			apiAuth: ['/api/proxy/backService'], // 需要增加token的api 例如 ['/api/proxy/test']
			ignore: ['/login', '/assets', '/register', '/api/proxy/unAuthBackService/', '/api/getConfig', '/api/permission'], // ignore path,support url regex
			logoutUrl: 'http://121.201.125.236/api/ums/logout',
			redirectHost: ''
		  }
		},
        spa:{//honeycomb项目加一下这个,代表此中间件在spa中间件之前运行
            deps:"foshanUserAuth"
        }
    },
    extension: {
        redirect: {
            config: {
                allowDomains: [//添加下上方服务地址,如果不在同一个域名下的话
                    '10.45.70.55:8380'
                ]
            }
        },
    },

    注意:
      如oauth配置给出的授权地址为 'http://ip:port/sso/oauth2.0/authorize?client_id=key&redirect_uri=url&response_type=type'
      
      则相应配置对应如下
      config:{
        clientUrl:'http://ip:port/sso/oauth2.0',

        casServerUrl:'http://ip:port/sso',
        localCasServerUrl:'http://ip:port/sso'

        loginUrl:'http://ip:port/sso/oauth2.0/authorize',
        logoutUrl: 'http://ip:port/sso/logout', 
        tokenUrl:'http://ip:port/sso/oauth2.0/accessToken',
        profileUrl:'http://ip:port/sso/oauth2.0/profile'
      }
      实际使用中不需要配置如此多的,以上基本上以某一组的形式出现:
        目前支持形式为 :
          1. loginUrl、logoutUrl、tokenUrl、profileUrl
          2. casServerUrl外网、localCasServerUrl 内网,如果内外网一致,仅配置casServerUrl即可
          3. clientUrl、logoutUrl v1.0.5版本及以下必须走此配置
          配置优先级:loginUrl、logoutUrl、tokenUrl、profileUrl (每个可单独配优先级高于后面两个组装的) > casServerUrl、localCasServerUrl(如果内外网一致 可以只配置casServerUrl) > clientUrl
...

2.用户信息session获取

...
  登录成功后,中间件会获取用户数据,存储到session,变量名为user,如果登出或者token完全过期会重新获取。
  获取方式:【honeycomb框架配置可参考】
  已有中间件middleware/spa.js可做如下配置
  return (req, res, next) => {
      let userInfo = req.session.user;

      res.render('index.html'),{
        ...
        userInfo: escape(JSON.stringify(userInfo || {})),
        ...
      };
  }

  view/index.html中配置
  <script>
    window.userInfo = JSON.parse(unescape("<%= userInfo %>"));//全局配置user信息 
  </script>
...

3.api操作

3.1 支持token功能,需做以下处理

...
  const proxyInstance = new Proxy({
    service: {
      test:{//可修改:此处设置为test对应api为'/api/proxy/test' 配置到上方apiAuth中
        endpoint:"http://10.45.70.56:8889/tocc-platform-service-oauth",//可修改
        client: 'http',
        headerExtension: [
          function (req, serviceCfg) {
            return {
              'access_token':req.get('access_token')
            };
          }
        ],
        api:['/*']
      },
    })
...

3.2 api请求时,token过期处理

node层直接返回数据(object): { isError:true, status: -10000, message: 'login overtime',isLogin:false }

应用侧针对返回数据做处理,同登出操作即可 例 window.location.href=http://127.0.0.1:8080/ABC/logout;

4.登出功能支持,请做以下处理

...
  window.location.href=`http://127.0.0.1:8080/ABC/logout`;//地址重定向方式
  以上两处均需要注意 
  如果是拿http://127.0.0.1:8080/ABC 为系统路径
  则登出地址一定是基于http://127.0.0.1:8080/ABC 为基础
  比如
  http://127.0.0.1:8080/ABC/logout
  http://127.0.0.1:8080/ABC/logout/xxx
  http://127.0.0.1:8080/ABC/xxx/logout/xxx
...
···
  
服务端获取到
	1.access_token 
	2.expires 过期时间(比较短可能几分钟)
	3.refresh_token (服务端设定 已知是30天)
	
后续
	access_token过期
	通过refresh_token 获取新的 access_token 和 expires
	
浏览器端可以查看到的cookie信息
honeycomb_token 对应上方access_token
HC_THIRD_AUTH	对应上方access_token,带过期时间 设定为上方expires
refresh_token	对应上方refresh_token
...