mirror of
https://github.com/chillzhuang/Saber.git
synced 2024-11-22 10:29:28 +08:00
🎉 增加多终端token认证
This commit is contained in:
parent
f843875db4
commit
b860051ce7
@ -23,7 +23,8 @@
|
||||
"vue-axios": "^2.1.2",
|
||||
"vue-i18n": "^8.7.0",
|
||||
"vue-router": "^3.0.1",
|
||||
"vuex": "^3.0.1"
|
||||
"vuex": "^3.0.1",
|
||||
"js-base64": "^2.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vue/cli-plugin-babel": "^3.1.1",
|
||||
|
50
src/api/system/client.js
Normal file
50
src/api/system/client.js
Normal file
@ -0,0 +1,50 @@
|
||||
import request from '@/router/axios';
|
||||
|
||||
export const getList = (current, size, params) => {
|
||||
return request({
|
||||
url: '/api/blade-system/client/list',
|
||||
method: 'get',
|
||||
params: {
|
||||
...params,
|
||||
current,
|
||||
size,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const getDetail = (id) => {
|
||||
return request({
|
||||
url: '/api/blade-system/client/detail',
|
||||
method: 'get',
|
||||
params: {
|
||||
id
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const remove = (ids) => {
|
||||
return request({
|
||||
url: '/api/blade-system/client/remove',
|
||||
method: 'post',
|
||||
params: {
|
||||
ids,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const add = (row) => {
|
||||
return request({
|
||||
url: '/api/blade-system/client/submit',
|
||||
method: 'post',
|
||||
data: row
|
||||
})
|
||||
}
|
||||
|
||||
export const update = (row) => {
|
||||
return request({
|
||||
url: '/api/blade-system/client/submit',
|
||||
method: 'post',
|
||||
data: row
|
||||
})
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
export default {
|
||||
title: "saber",
|
||||
indexTitle: 'Saber Admin',
|
||||
clientId: 'saber', // 客户端id
|
||||
clientSecret: 'saber_secret', // 客户端密钥
|
||||
tenantMode: true, // 是否开启租户模式
|
||||
logo: "S",
|
||||
key: 'saber',//配置主键,目前用于存储
|
||||
|
@ -8,12 +8,14 @@
|
||||
import axios from 'axios'
|
||||
import store from '@/store/';
|
||||
import router from '@/router/router'
|
||||
import { serialize } from '@/util/util'
|
||||
import { getToken } from '@/util/auth'
|
||||
import { Message } from 'element-ui'
|
||||
import {serialize} from '@/util/util'
|
||||
import {getToken} from '@/util/auth'
|
||||
import {Message} from 'element-ui'
|
||||
import website from '@/config/website';
|
||||
import NProgress from 'nprogress' // progress bar
|
||||
import 'nprogress/nprogress.css' // progress bar style
|
||||
import {Base64} from 'js-base64';
|
||||
|
||||
axios.defaults.timeout = 10000;
|
||||
//返回其他状态吗
|
||||
axios.defaults.validateStatus = function (status) {
|
||||
@ -30,8 +32,9 @@ axios.interceptors.request.use(config => {
|
||||
NProgress.start() // start progress bar
|
||||
const meta = (config.meta || {});
|
||||
const isToken = meta.isToken === false;
|
||||
config.headers['Authorization'] = `Basic ${Base64.encode(`${website.clientId}:${website.clientSecret}`)}`;
|
||||
if (getToken() && !isToken) {
|
||||
config.headers['blade-auth'] = 'Bearer ' + getToken() // 让每个请求携带token--['Authorization']为自定义key 请根据实际情况自行修改
|
||||
config.headers['Blade-Auth'] = 'bearer ' + getToken() // 让每个请求携带token--['Authorization']为自定义key 请根据实际情况自行修改
|
||||
}
|
||||
//headers中配置serialize为true开启序列化
|
||||
if (config.method === 'post' && meta.isSerialize === true) {
|
||||
@ -50,7 +53,7 @@ axios.interceptors.response.use(res => {
|
||||
//如果在白名单里则自行catch逻辑处理
|
||||
if (statusWhiteList.includes(status)) return Promise.reject(res);
|
||||
//如果是401则跳转到登录页面
|
||||
if (status === 401) store.dispatch('FedLogOut').then(() => router.push({ path: '/login' }));
|
||||
if (status === 401) store.dispatch('FedLogOut').then(() => router.push({path: '/login'}));
|
||||
// 如果请求为非200否者默认统一处理
|
||||
if (status !== 200) {
|
||||
Message({
|
||||
|
273
src/views/system/client.vue
Normal file
273
src/views/system/client.vue
Normal file
@ -0,0 +1,273 @@
|
||||
<template>
|
||||
<basic-container>
|
||||
<avue-crud :option="option"
|
||||
:data="data"
|
||||
:page="page"
|
||||
@row-del="rowDel"
|
||||
v-model="form"
|
||||
:permission="permissionList"
|
||||
@row-update="rowUpdate"
|
||||
@row-save="rowSave"
|
||||
:before-open="beforeOpen"
|
||||
@search-change="searchChange"
|
||||
@search-reset="searchReset"
|
||||
@selection-change="selectionChange"
|
||||
@on-load="onLoad">
|
||||
<template slot="menuLeft">
|
||||
<el-button type="danger"
|
||||
size="small"
|
||||
icon="el-icon-delete"
|
||||
plain
|
||||
v-if="permission.client_delete"
|
||||
@click="handleDelete">删 除
|
||||
</el-button>
|
||||
</template>
|
||||
</avue-crud>
|
||||
</basic-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {getList, getDetail, add, update, remove} from "@/api/system/client";
|
||||
import {mapGetters} from "vuex";
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
form: {},
|
||||
page: {
|
||||
pageSize: 10,
|
||||
currentPage: 1,
|
||||
total: 0
|
||||
},
|
||||
selectionList: [],
|
||||
option: {
|
||||
tip: false,
|
||||
border: true,
|
||||
index: true,
|
||||
viewBtn: true,
|
||||
selection: true,
|
||||
column: [
|
||||
{
|
||||
label: "应用id",
|
||||
prop: "clientId",
|
||||
search: true,
|
||||
rules: [{
|
||||
required: true,
|
||||
message: "请输入客户端id",
|
||||
trigger: "blur"
|
||||
}]
|
||||
},
|
||||
{
|
||||
label: "应用密钥",
|
||||
prop: "clientSecret",
|
||||
search: true,
|
||||
rules: [{
|
||||
required: true,
|
||||
message: "请输入客户端密钥",
|
||||
trigger: "blur"
|
||||
}]
|
||||
},
|
||||
{
|
||||
label: "授权类型",
|
||||
prop: "authorizedGrantTypes",
|
||||
valueDefault: "refresh_token,password,authorization_code",
|
||||
rules: [{
|
||||
required: true,
|
||||
message: "请输入授权类型",
|
||||
trigger: "blur"
|
||||
}]
|
||||
},
|
||||
{
|
||||
label: "授权范围",
|
||||
prop: "scope",
|
||||
valueDefault: "all",
|
||||
rules: [{
|
||||
required: true,
|
||||
message: "请输入授权范围",
|
||||
trigger: "blur"
|
||||
}]
|
||||
},
|
||||
{
|
||||
label: "令牌秒数",
|
||||
prop: "accessTokenValidity",
|
||||
type: "number",
|
||||
valueDefault: 3600,
|
||||
rules: [{
|
||||
required: true,
|
||||
message: "请输入令牌过期秒数",
|
||||
trigger: "blur"
|
||||
}]
|
||||
},
|
||||
{
|
||||
label: "刷新秒数",
|
||||
prop: "refreshTokenValidity",
|
||||
type: "number",
|
||||
valueDefault: 604800,
|
||||
hide: true,
|
||||
rules: [{
|
||||
required: true,
|
||||
message: "请输入刷新令牌过期秒数",
|
||||
trigger: "blur"
|
||||
}]
|
||||
},
|
||||
{
|
||||
label: "回调地址",
|
||||
prop: "webServerRedirectUri",
|
||||
hide: true,
|
||||
rules: [{
|
||||
required: true,
|
||||
message: "请输入回调地址",
|
||||
trigger: "blur"
|
||||
}]
|
||||
},
|
||||
{
|
||||
label: "资源集合",
|
||||
prop: "resourceIds",
|
||||
hide: true,
|
||||
rules: [{
|
||||
message: "请输入资源集合",
|
||||
trigger: "blur"
|
||||
}]
|
||||
},
|
||||
{
|
||||
label: "权限",
|
||||
prop: "authorities",
|
||||
hide: true,
|
||||
rules: [{
|
||||
message: "请输入权限",
|
||||
trigger: "blur"
|
||||
}]
|
||||
},
|
||||
{
|
||||
label: "自动授权",
|
||||
prop: "autoapprove",
|
||||
hide: true,
|
||||
rules: [{
|
||||
message: "请输入自动授权",
|
||||
trigger: "blur"
|
||||
}]
|
||||
},
|
||||
{
|
||||
label: "附加说明",
|
||||
hide: true,
|
||||
prop: "additionalInformation",
|
||||
span: 24,
|
||||
rules: [{
|
||||
message: "请输入附加说明",
|
||||
trigger: "blur"
|
||||
}]
|
||||
},
|
||||
]
|
||||
},
|
||||
data: []
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
...mapGetters(["permission"]),
|
||||
permissionList() {
|
||||
return {
|
||||
addBtn: this.vaildData(this.permission.client_add),
|
||||
viewBtn: this.vaildData(this.permission.client_view),
|
||||
delBtn: this.vaildData(this.permission.client_delete),
|
||||
editBtn: this.vaildData(this.permission.client_edit)
|
||||
};
|
||||
},
|
||||
ids() {
|
||||
let ids = [];
|
||||
this.selectionList.forEach(ele => {
|
||||
ids.push(ele.id);
|
||||
});
|
||||
return ids.join(",");
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
rowSave(row, loading) {
|
||||
add(row).then(() => {
|
||||
loading();
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: "success",
|
||||
message: "操作成功!"
|
||||
});
|
||||
});
|
||||
},
|
||||
rowUpdate(row, index, loading) {
|
||||
update(row).then(() => {
|
||||
loading();
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: "success",
|
||||
message: "操作成功!"
|
||||
});
|
||||
});
|
||||
},
|
||||
rowDel(row) {
|
||||
this.$confirm("确定将选择数据删除?", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning"
|
||||
})
|
||||
.then(() => {
|
||||
return remove(row.id);
|
||||
})
|
||||
.then(() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: "success",
|
||||
message: "操作成功!"
|
||||
});
|
||||
});
|
||||
},
|
||||
searchReset() {
|
||||
this.onLoad(this.page);
|
||||
},
|
||||
searchChange(params) {
|
||||
this.onLoad(this.page, params);
|
||||
},
|
||||
selectionChange(list) {
|
||||
this.selectionList = list;
|
||||
},
|
||||
handleDelete() {
|
||||
if (this.selectionList.length === 0) {
|
||||
this.$message.warning("请选择至少一条数据");
|
||||
return;
|
||||
}
|
||||
this.$confirm("确定将选择数据删除?", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning"
|
||||
})
|
||||
.then(() => {
|
||||
return remove(this.ids);
|
||||
})
|
||||
.then(() => {
|
||||
this.onLoad(this.page);
|
||||
this.$message({
|
||||
type: "success",
|
||||
message: "操作成功!"
|
||||
});
|
||||
this.$refs.crud.toggleSelection();
|
||||
});
|
||||
},
|
||||
|
||||
beforeOpen(done, type) {
|
||||
if (["edit", "view"].includes(type)) {
|
||||
getDetail(this.form.id).then(res => {
|
||||
this.form = res.data.data;
|
||||
});
|
||||
}
|
||||
done();
|
||||
},
|
||||
onLoad(page, params = {}) {
|
||||
getList(page.currentPage, page.pageSize, params).then(res => {
|
||||
const data = res.data.data;
|
||||
this.page.total = data.total;
|
||||
this.data = data.records;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
</style>
|
@ -4490,9 +4490,9 @@ joi@^14.3.0:
|
||||
isemail "3.x.x"
|
||||
topo "3.x.x"
|
||||
|
||||
js-base64@^2.1.8:
|
||||
js-base64@^2.1.8, js-base64@^2.5.1:
|
||||
version "2.5.1"
|
||||
resolved "http://registry.npm.taobao.org/js-base64/download/js-base64-2.5.1.tgz#1efa39ef2c5f7980bb1784ade4a8af2de3291121"
|
||||
resolved "http://registry.npm.taobao.org/js-base64/download/js-base64-2.5.1.tgz?cache=0&other_urls=http%3A%2F%2Fregistry.npm.taobao.org%2Fjs-base64%2Fdownload%2Fjs-base64-2.5.1.tgz#1efa39ef2c5f7980bb1784ade4a8af2de3291121"
|
||||
integrity sha1-Hvo57yxfeYC7F4St5KivLeMpESE=
|
||||
|
||||
js-cookie@^2.2.0:
|
||||
|
Loading…
Reference in New Issue
Block a user