1.0.2 • Published 4 years ago
jiasheng-passport-login v1.0.2
前端项目接入 甲晟单点登录 公共插件
接入流程
# 1.初始化
# 比如在 main.js 文件中引入, 注意,位置要在 vue引入后
import PassportLogin from 'jiasheng-passport-login'
# 然后全局注入,初始化公共配置
Vue.prototype.$passport = new PassportLogin({
// 下面4的参数 为必填项
loginOriginAll: ['https://passport1.abc.net', 'https://passport2.abc.net'], // 接入的单点域名,['用户登录','管理登录']
tenantId: '', // 根据接入的项目 填写
client_id: '', // 根据接入的项目 填写
client_secret: '', // 根据接入的项目 填写
// 下面4的参数 为非必填项
// manager: '0', // 默认值为'0'-用户登录,'1'-管理员
// maybeRedirectAll: ['http://a.example.com', 'http://b.example.com'], // 2种登录成功后跳回地址。不填择 默认跳回原页面
// grant_type: '', // 固定值
// jiasheng_log_url: '' // 固定值
})
# 2.调用
# 2.1 判断是否登录
# *.vue文件中
this.$passport.isLogin().then(res => {
// 已登录
}).catch(error => {
// 未登录
})
# *.js文件中
Vue.prototype.$passport.isLogin().then(res => {}).catch(error => {})
# 2.2 获取用户信息
this.$passport.getUserInfo().then(response => {
console.log('getUserInfo: ', response)
}).catch(error => {
console.log('getUserInfo error: ', error)
})
# 2.3 登录退出 (会发生重定向,没有返回值)
this.$passport.loginOut()
# 3.读取配置项等其他功能方法 可自行看源码
# 如查看我配置的 登录域名
const loginOriginAll = this.$passport.loginOriginAll // 获取配置的某个参数