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 🙏

© 2026 – Pkg Stats / Ryan Hefner

shiw-auth

v1.2.1

Published

接入IdentityServer4自定义授权shiw_code、jjt_cas

Readme

#使用方法

安装

npm install shiw-auth --save

配置

所有的配置项,这里可以读取环境变量中的值


export default {
    authServer: 'https://www.xxxx.xyz:1001',
    casServer:'',
    loginPath: '/Login',
    loginOutPath: '/LoginOut',
    tokenEnd: '/connect/token',
    clientId: '',
    grantType: 'shiw_code', // 默认授权方式 支持:shiw_code,jjt_cas
    scope: 'XXXX offline_access',
    returnUrl: `${window.location.origin}/code-callback`,
    casReturnUrl: `${window.location.origin}/cas-callback`,
    loginOutReturnUrl: `${window.location.origin}`, //退出登录后回调地址
    isOnlyCasLogin: false, //是否仅仅支持CAS登录
    isFullCasLoginOut: false, // 是否在全站退出CAS
    extraTokenParams: {},//拓展参数
};

vuex配置


import { vuexShiwAuthStoreModule } from 'shiw-auth';
import config from '@/shiw_auth_config'; // 导入配置文件

export default new Vuex.Store({
  state: {
  },
  mutations: {
  },
  actions: {},
  getters: {
    token: store => {
      return store.auth.access_token;
    },
    isLogin: store => {
      return store.auth.isLogin;
    }
  },
  modules: {
    auth: vuexShiwAuthStoreModule(config) //使用认证模块
  }
});

路由守卫配置

// 导入依赖项
import { isPublicPath } from 'shiw-auth';
import store from '@/store';

// 添加回调路由
const routes = [
    {
        path: '/code-callback',
        name: 'codeCallback',
        component: CodeCallback,
    },
    {
        path: '/cas-callback',
        name: 'CasCallback',
        component: CasCallback,
    },
];

// 配置路由守卫
router.beforeEach((to, from, next) => {
    if (isPublicPath(to.path)) {
        next();
        return;
    }

    if (store.getters.isLogin) {
        next();
    } else {
        // 尝试登录,如果登录成功,那么跳转到目标路由,否则自动跳转到登录界面
        store.dispatch('auth/signIn')
            .then(res => {
                if (res === true) {
                    next({ ...to });
                }
            });
    }
});

//回调路由,关键代码,代码都差不多,唯一的区别就是设置授权方式的不一样
import { mapActions, mapMutations } from 'vuex';

export default {
    name: 'XXXCallback',
    data() {
        return {};
    },
    created() {
        // 这里是唯一的区别,要和配置里面的对应起来
        // jjt_cas、shiw_code
        this.setGrantType('jjt_cas');
    },
    methods: {
        init() {
            this.getToken()
                .then(res => {
                    this.$router.push('/');
                })
                .catch(err => {
                    this.$message.error('token获取失败', 0);
                    console.error(err);
                });
        },
        ...mapActions('auth', ['getToken']),
        ...mapMutations('auth', ['setGrantType'])
    },
    mounted() {
        console.log('XXX跳转回来...');
        this.init();
    }
};