srun4k-webauthn

1.0.30 • Public • Published

srun4k-webauthn

vue 环境

引入

yarn add srun4k-webauthn
# or
npm i srun4k-webauthn

使用

import { srunWebAuthn } from 'srun4k-webauthn'
...

const auth = new srunWebAuthn({
        serverApi: 'https://127.0.0.1:80',              // 后台请求地址
        requestConf: {
            webauthnStatus: {                           // 查询是否注册webauthn API
                api: '/webauthnStatus'
            },
            registerBegin: {                            // 开始注册 API
                api: '/registerBegin'
            },
            registerFinish: {                           // 执行注册 API
                api: '/registerFinish',
                params: {}                              // 个性化参数
            },
            loginBegin: {                               // 开始登陆 API
                api: '/loginBegin'
            },
            loginFinish: {                              // 执行登陆 API
                api: '/loginFinish',
                params: {}                              // 个性化参数
            }
        },
        getHeader: 'token',                             // 需要从login接口获取响应头就传,不用就不传
    })

    /** webauthn认证
        username: 用户名
     */
    auth.login(username, async (res: any) => {
        if (res) {
            // 成功回调
        }
    })

    /** 新增设备
        username: 用户名
     */
     auth.register(username, async (res: any) => {
        if (res) {
            // 成功回调
        }
    })

非vue环境

引入

<script src="../src/window.js"></script>

使用

const auth = new srunWebAuthn({
        serverApi: 'https://127.0.0.1:80',              // 后台请求地址
        requestConf: {
            webauthnStatus: {                           // 查询是否注册webauthn API
                api: '/webauthnStatus'
            },
            registerBegin: {                            // 开始注册 API
                api: '/registerBegin'
            },
            registerFinish: {                           // 执行注册 API
                api: '/registerFinish',
                params: {}
            },
            loginBegin: {                               // 开始登陆 API
                api: '/loginBegin'
            },
            loginFinish: {                              // 执行登陆 API
                api: '/loginFinish',
                params: {}
            }
        },
        getHeader: 'token',                             // 需要从login接口获取响应头就传,不用就不传
    })


    /**
        username: 用户名
     */
    auth.login({
        username: this.user.user,
        // 成功回调
        func: async (res: any) => {
            if (res) {
                const auth = res.token;
                await this.store.saveLoginMethod('authn');
                await this.user_store.saveAuth(auth);
                await this.user_store.saveUser(this.user.user);
                this.$router.push('/apps');
            }
        },
        // 错误回调
        err: (err: any, flag: string) => {
            if (flag === 'register') {
                this.$q.dialog({
                    title: '注册失败',
                    message: '请检查当前网络环境'
                })
            }
        }
    })

Readme

Keywords

Package Sidebar

Install

npm i srun4k-webauthn

Weekly Downloads

3

Version

1.0.30

License

ISC

Unpacked Size

2.36 MB

Total Files

4

Last publish

Collaborators

  • readonly_i