@niushibang/user-center-sso-plugin
v1.7.5
Published
@nsb/user-center-sso-plugin
Downloads
115
Readme
@nsb/user-center-sso-plugin
环境
npm源:http://npm.niushibang.net/
安装
npm install --save @nsb/user-center-sso-plugin使用
import { SSO } from '@nsb/user-center-sso-plugin';
// 场景:APP_WEB自己未存在登录信息时,获取登录信息
function getExistsLogin(){
/**
* 接受数据的origin,例:https://APP_WEB.com
* @see SSO.d.ts
* @type {KnownOrigin}
*/
const origin = ''
/**
* SSO页面的UI类型
* @see SSO.d.ts
* @type {KnownPath}
*/
const path = ''
const sso = new SSO({ origin, path });
// 已渲染
sso.on('ready', ()=>{});
/**
* info类型为LoginInfo
* @see SSO.d.ts
* @type {LoginInfo}
*/
// 已登录
sso.on('resolve', (info) => {});
// 无权限或未登录,APP_WEB跳登录页
sso.on('reject', () => {});
// reject或resolve后会自动销毁,如有必要提前销毁则可调用 destroy()
sso.destroy();
}
// 场景:未登录,直接在某个iframe显示登录UI
function loginView(){
const origin = '';
const path = '';
const iframe = document.getElementById('example_iframe');
const sso = new SSO({ origin, path, iframe });
sso.on('resolve', (info) => { /* 贮存info, 然后去自己该去的地方 */ });
}