@yqsl-cd/auth
v0.0.8
Published
元气森林-登陆鉴权
Readme
元气森林,登陆、鉴权组件
基于元气森林-技术工程部服务,用于在PC端或者飞书浏览器进行登陆、鉴权
安装
npm install @yqsl-cd/auth或者使用yarn命令
yarn add @yqsl-cd/auth使用
import yqslAuth from '@yqsl-cd/auth'
...
yqslAuth.loginLark(...)API
loginLark(params)
说明
pc端飞书登录
params参数定义
| 参数名 | 必填 | 参数类型 | 说明 | | --------- | ---- | ----------------------- | ------------------------ | | appCode | 是 | string | 应用标识 | | env | 否 | 'test'|'uat'|'prod' | 当前环境,默认test | | width | 否 | number | 弹窗宽度,默认585 | | height | 否 | number | 弹窗高度,默认648 | | onSuccess | 否 | (token: string) => void | 成功回调,参数为token | | onFail | 否 | (error: string) => void | 失败回调,参数为失败原因 |
返回
void
实例
yqslAuth.loginLark({ appCode: 'infra-op', env: 'uat', onSuccess: (token) => { console.log('token:', token) }, onFail: (err) => { console.log('login err:', err) } })
getUrlByLark(params)
说明
返回在飞书浏览器中,登陆需要跳转的地址
params参数定义
| 参数名 | 必填 | 参数类型 | 说明 | | -------- | ---- | --------------------- | ------------------------- | | appCode | 是 | string | 应用标识 | | pathname | 是 | string | 回调路径,如'/checkToken' | | env | 否 | 'test'|'uat'|'prod' | 当前环境,默认test | | search | 否 | string | 回调查询信息,如'a=1&b=2' |
返回
string | null
实例
if (/Lark/i.test(window.navigator.userAgent)) { const urlAuth = yqslAuth.getUrlByLark({ appCode: 'infra-op', pathname: '/checkToken', env: 'uat', search: 'pageBeforeLogin=%2Findex%3Fa%3D1%26b%3D2' }) if (urlAuth !== null) { window.location.href = urlAuth; } } // 小技巧:可以通过search传递登录前页面,如%2Findex%3Fa%3D1%26b%3D2 => /index?a=1&b=2// 如登录成功,页面会跳转至/checkToken?token={token}&pageBeforeLogin=%2Findex%3Fa%3D1%26b%3D2 // 可在checkToken页面,通过校验token是否有效
