mirror of
https://github.com/chillzhuang/Saber.git
synced 2024-11-22 02:19:32 +08:00
🎉 增加多终端token认证
This commit is contained in:
parent
f843875db4
commit
b860051ce7
95
package.json
95
package.json
@ -1,48 +1,49 @@
|
||||
{
|
||||
"name": "saber-admin",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"serve": "vue-cli-service serve",
|
||||
"build": "vue-cli-service build",
|
||||
"lint": "vue-cli-service lint",
|
||||
"analyz": "npm_config_report=true npm run build",
|
||||
"test:unit": "vue-cli-service test:unit",
|
||||
"test:e2e": "vue-cli-service test:e2e"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.18.0",
|
||||
"babel-polyfill": "^6.26.0",
|
||||
"classlist-polyfill": "^1.2.0",
|
||||
"element-ui": "^2.4.5",
|
||||
"js-cookie": "^2.2.0",
|
||||
"mockjs": "^1.0.1-beta3",
|
||||
"nprogress": "^0.2.0",
|
||||
"script-loader": "^0.7.2",
|
||||
"vue": "^2.5.16",
|
||||
"vue-axios": "^2.1.2",
|
||||
"vue-i18n": "^8.7.0",
|
||||
"vue-router": "^3.0.1",
|
||||
"vuex": "^3.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vue/cli-plugin-babel": "^3.1.1",
|
||||
"@vue/cli-plugin-eslint": "^3.1.5",
|
||||
"@vue/cli-service": "^3.1.4",
|
||||
"chai": "^4.1.2",
|
||||
"node-sass": "^4.9.0",
|
||||
"sass-loader": "^7.0.1",
|
||||
"vue-template-compiler": "^2.5.17",
|
||||
"webpack-bundle-analyzer": "^3.0.3"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.js": [
|
||||
"vue-cli-service lint",
|
||||
"git add"
|
||||
],
|
||||
"*.vue": [
|
||||
"vue-cli-service lint",
|
||||
"git add"
|
||||
]
|
||||
}
|
||||
}
|
||||
"name": "saber-admin",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"serve": "vue-cli-service serve",
|
||||
"build": "vue-cli-service build",
|
||||
"lint": "vue-cli-service lint",
|
||||
"analyz": "npm_config_report=true npm run build",
|
||||
"test:unit": "vue-cli-service test:unit",
|
||||
"test:e2e": "vue-cli-service test:e2e"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.18.0",
|
||||
"babel-polyfill": "^6.26.0",
|
||||
"classlist-polyfill": "^1.2.0",
|
||||
"element-ui": "^2.4.5",
|
||||
"js-cookie": "^2.2.0",
|
||||
"mockjs": "^1.0.1-beta3",
|
||||
"nprogress": "^0.2.0",
|
||||
"script-loader": "^0.7.2",
|
||||
"vue": "^2.5.16",
|
||||
"vue-axios": "^2.1.2",
|
||||
"vue-i18n": "^8.7.0",
|
||||
"vue-router": "^3.0.1",
|
||||
"vuex": "^3.0.1",
|
||||
"js-base64": "^2.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vue/cli-plugin-babel": "^3.1.1",
|
||||
"@vue/cli-plugin-eslint": "^3.1.5",
|
||||
"@vue/cli-service": "^3.1.4",
|
||||
"chai": "^4.1.2",
|
||||
"node-sass": "^4.9.0",
|
||||
"sass-loader": "^7.0.1",
|
||||
"vue-template-compiler": "^2.5.17",
|
||||
"webpack-bundle-analyzer": "^3.0.3"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.js": [
|
||||
"vue-cli-service lint",
|
||||
"git add"
|
||||
],
|
||||
"*.vue": [
|
||||
"vue-cli-service lint",
|
||||
"git add"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
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,61 +8,64 @@
|
||||
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) {
|
||||
return status >= 200 && status <= 500; // 默认的
|
||||
return status >= 200 && status <= 500; // 默认的
|
||||
};
|
||||
//跨域请求,允许保存cookie
|
||||
axios.defaults.withCredentials = true;
|
||||
// NProgress Configuration
|
||||
NProgress.configure({
|
||||
showSpinner: false
|
||||
showSpinner: false
|
||||
});
|
||||
//HTTPrequest拦截
|
||||
axios.interceptors.request.use(config => {
|
||||
NProgress.start() // start progress bar
|
||||
const meta = (config.meta || {});
|
||||
const isToken = meta.isToken === false;
|
||||
if (getToken() && !isToken) {
|
||||
config.headers['blade-auth'] = 'Bearer ' + getToken() // 让每个请求携带token--['Authorization']为自定义key 请根据实际情况自行修改
|
||||
}
|
||||
//headers中配置serialize为true开启序列化
|
||||
if (config.method === 'post' && meta.isSerialize === true) {
|
||||
config.data = serialize(config.data);
|
||||
}
|
||||
return 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 请根据实际情况自行修改
|
||||
}
|
||||
//headers中配置serialize为true开启序列化
|
||||
if (config.method === 'post' && meta.isSerialize === true) {
|
||||
config.data = serialize(config.data);
|
||||
}
|
||||
return config
|
||||
}, error => {
|
||||
return Promise.reject(error)
|
||||
return Promise.reject(error)
|
||||
});
|
||||
//HTTPresponse拦截
|
||||
axios.interceptors.response.use(res => {
|
||||
NProgress.done();
|
||||
const status = res.data.code || 200
|
||||
const statusWhiteList = website.statusWhiteList || [];
|
||||
const message = res.data.msg || '未知错误';
|
||||
//如果在白名单里则自行catch逻辑处理
|
||||
if (statusWhiteList.includes(status)) return Promise.reject(res);
|
||||
//如果是401则跳转到登录页面
|
||||
if (status === 401) store.dispatch('FedLogOut').then(() => router.push({ path: '/login' }));
|
||||
// 如果请求为非200否者默认统一处理
|
||||
if (status !== 200) {
|
||||
Message({
|
||||
message: message,
|
||||
type: 'error'
|
||||
})
|
||||
return Promise.reject(new Error(message))
|
||||
}
|
||||
return res;
|
||||
NProgress.done();
|
||||
const status = res.data.code || 200
|
||||
const statusWhiteList = website.statusWhiteList || [];
|
||||
const message = res.data.msg || '未知错误';
|
||||
//如果在白名单里则自行catch逻辑处理
|
||||
if (statusWhiteList.includes(status)) return Promise.reject(res);
|
||||
//如果是401则跳转到登录页面
|
||||
if (status === 401) store.dispatch('FedLogOut').then(() => router.push({path: '/login'}));
|
||||
// 如果请求为非200否者默认统一处理
|
||||
if (status !== 200) {
|
||||
Message({
|
||||
message: message,
|
||||
type: 'error'
|
||||
})
|
||||
return Promise.reject(new Error(message))
|
||||
}
|
||||
return res;
|
||||
}, error => {
|
||||
NProgress.done();
|
||||
return Promise.reject(new Error(error));
|
||||
NProgress.done();
|
||||
return Promise.reject(new Error(error));
|
||||
})
|
||||
|
||||
export default axios;
|
||||
|
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