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

koa-sso

v1.2.2

Published

node接入兑吧sso

Downloads

8

Readme

koa-sso

用于koa2对接兑吧sso单点登录

流程介绍

一般,我们会在自己的服务也实现一套用户系统,然后去支持sso登录

  • 判断用户未登录
  • 跳转sso登录页面http://sso.duiba.com.cn/login并自己拼接systemId参数,redirect参数(登录后需要跳转的地址到)
  • 在sso平台登录,会自动跳转回我们的固定接口'/sso/ssoIndex',并带上ssoStamp参数
  • 在这个接口里,根据ssoStamp去拿ticket通行证,再用ticket去拿sso账户信息。(这个ticket是可以在本地自己存起来的,如后面一直要校验sso信息,可以省略之前步骤直接用ticket去取)
  • sso登录成功,后面就是自己的业务逻辑

use

const Koa = require('koa')
const app = new Koa()
const koaSso = require('koa-sso')

app.use(koaSso({
  ssourl: 'https://sso.duibatest.com.cn/',
  systemId: 29,
  systemName: 'jimo',
  appSecret: '95cfda1e006330958c2abbefd64d5259',
  profiles: 'test'
}))


/**
 * sso要求本地实现的一个接口,用来对接sso
 */
const router = require('koa-router')
router.get('/sso/ssoIndex', async ctx => {
  // 获取通行证
  let ticket = await ctx.sso.findTicketByStamp()

  // 获取sso账号信息
  let ssoData = await ctx.sso.verifyTicketAndGetAdmin(ticket)

  if (ssoData) {
    // 至此,已获取sso信息,后面只需将用户置为登录状态
    console.log(ssoData.id)
    
    
    /****** 以下根据具体业务场景自己写 ******/
    /****** 例: ******/
    // koa-session 登录
    ctx.session.userId = ssoData.id
    ctx.success('登录成功')
    const params = qs.parse(ctx.request.querystring)
    // 登录成功后跳转到之前所在页面
    if (params.redirect) {
      ctx.response.redirect(params.redirect);
    }
  }
})

接口: await fn()调用

通过凭证获取的通行证(原来使用链接参数方式跨域传递通行证,不安全)

ctx.sso.findTicketByStamp()

登录验证接口(验证失败返回null)

ctx.sso.verifyTicketAndGetAdmin()

获取一个用户所有的角色 ctx.sso.getAdminAllRoles()

获取用户在系统下的权限 ctx.sso.getPowerIdsBySystemIdAndAdminId()

加载整个系统得权限树 ctx.sso.loadPowerList()

登出sso ctx.sso.outLogin()