1.安装oidc-client
npm install --save vuex
npm install oidc-client
2.新建oidc-client.js
- import Oidc from "oidc-client";
- export const mgr = new Oidc.UserManager({
- authority: "authority",//认证服务器
- client_id: "client_id", //表示客户端的ID,必选项
- redirect_uri: "redirect_uri", //表示重定向URI,认证服务器回调的客户端页面。可选项
post_logout_redirect_uri:"logout_uri" //退出后返回的页面
- response_type: "id_token token", // response_type:表示授权类型,必选项
- userStore: new Oidc.WebStorageStateStore({ store: window.localStorage }),
- scope: "", //scope:表示申请的权限范围,可选项
- automaticSilentRenew: true,
- });
3.所需页面引入即可
- import { mgr } from "../oidc.js";
mgr.signinRedirect() //登录
mgr.getUser() //获取用户信息
mgr.signinRedirectCallback() //callback
mgr.signoutRedirect() //退出登录