forked from xiaoymin/knife4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
134 changed files
with
5,746 additions
and
5,267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/> | ||
<title>Knife4j-OAuth2</title> | ||
<script src="jquery.min.js"></script> | ||
</head> | ||
<body> | ||
<script type="text/javascript"> | ||
$(function(){ | ||
function OAuth2(url){ | ||
this.url=url; | ||
this.code=null; | ||
this.accessToken=null; | ||
this.tokenType=null; | ||
this.state=null; | ||
//缓存在localStorage中的对象 | ||
this.cacheValue=null; | ||
} | ||
OAuth2.prototype.init=function(){ | ||
var local=this.url; | ||
this.code=this.getKey("code",local,""); | ||
this.accessToken=this.getKey("access_token",local,""); | ||
this.tokenType=this.getKey("token_type",local,"Bearer"); | ||
this.state=this.getKey("state",local); | ||
if(window.localStorage){ | ||
var value=window.localStorage.getItem(this.state); | ||
if(this.strNotBlank(value)){ | ||
this.cacheValue=JSON.parse(value); | ||
} | ||
} | ||
} | ||
OAuth2.prototype.auth=function(){ | ||
if(this.strNotBlank(this.code)){ | ||
this.authorizationCode(); | ||
}else{ | ||
this.implicit(); | ||
} | ||
} | ||
OAuth2.prototype.getKey=function(key,str,defaultValue){ | ||
var reg=new RegExp(".*?"+key+"=(.*?)(&.*)?$","ig"); | ||
var val=defaultValue; | ||
if(reg.test(str)){ | ||
val=RegExp.$1; | ||
} | ||
return val; | ||
} | ||
OAuth2.prototype.strNotBlank=function(str){ | ||
var flag = false; | ||
if ( str != undefined &&str != null &&str != "") { | ||
flag = true; | ||
} | ||
return flag; | ||
} | ||
|
||
OAuth2.prototype.implicit=function(){ | ||
this.cacheValue.accessToken=this.tokenType+" "+this.accessToken; | ||
this.cacheValue.tokenType=this.tokenType; | ||
this.cacheValue.granted=true; | ||
window.localStorage.setItem(this.state,JSON.stringify(this.cacheValue)) | ||
window.close(); | ||
} | ||
OAuth2.prototype.authorizationCode=function(){ | ||
var that=this; | ||
console.log(this.cacheValue); | ||
var url=this.cacheValue.tokenUrl; | ||
var params={ | ||
"grant_type":"authorization_code", | ||
"code":this.code, | ||
"redirect_uri":decodeURIComponent(this.cacheValue.redirectUri), | ||
"client_id":this.cacheValue.clientId, | ||
"client_secret":this.cacheValue.clientSecret | ||
} | ||
$.post(url,params,function(data){ | ||
if(data!=null&&data!=undefined) { | ||
that.cacheValue.accessToken=data.token_type+" "+data.access_token; | ||
that.cacheValue.tokenType=data.token_type; | ||
that.cacheValue.granted=true; | ||
window.localStorage.setItem(that.state,JSON.stringify(that.cacheValue)) | ||
window.close(); | ||
} | ||
}) | ||
} | ||
var oauth=new OAuth2(window.location.href); | ||
oauth.init(); | ||
oauth.auth(); | ||
}) | ||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import localStore from '@/store/local' | ||
import constant from '@/store/constants' | ||
import KUtils from '@/core/utils'; | ||
|
||
var KEnvironment =function(settings){ | ||
window.console.log(settings) | ||
this.groupid=settings.groupid||'afterScriptGroup'; | ||
this.allgroupids=settings.allgroupids||[]; | ||
this.response=settings.response||{ | ||
data:{}, | ||
headers:{} | ||
}; | ||
this.global={ | ||
/** | ||
* 设置当前逻辑分组下全局Header | ||
* @param {*} name Header名称 | ||
* @param {*} value Header值 | ||
*/ | ||
setHeader:(name,value)=>{ | ||
this.global.setCommon(name,value,'header',false); | ||
}, | ||
/** | ||
* 设置所有逻辑分组下全局Header | ||
* @param {*} name Header名称 | ||
* @param {*} value Header值 | ||
*/ | ||
setAllHeader:(name,value)=>{ | ||
this.global.setCommon(name,value,'header',true); | ||
}, | ||
/** | ||
* 当前逻辑分组下全局设置query类型的参数 | ||
* @param {*} name 参数名称 | ||
* @param {*} value 参数值 | ||
*/ | ||
setParameter:(name,value)=>{ | ||
this.global.setCommon(name,value,'query',false); | ||
}, | ||
/** | ||
* 所有逻辑分组下全局设置query类型的参数 | ||
* @param {*} name 参数名称 | ||
* @param {*} value 参数值 | ||
*/ | ||
setAllParameter:(name,value)=>{ | ||
this.global.setCommon(name,value,'query',true); | ||
}, | ||
setCommon:(name,value,type,all)=>{ | ||
//window.console.log('setCommon,name:'+name+',value:'+value+',type:'+type); | ||
var key=this.groupid; | ||
var pkid=name+type; | ||
if(all){ | ||
var allGroup=this.allgroupids; | ||
//更新所有逻辑分组下的全局参数 | ||
localStore.getItem(constant.globalParameter).then(val => { | ||
if(KUtils.checkUndefined(val)){ | ||
var tmpVal={}; | ||
allGroup.forEach(gid=>{ | ||
var tmpValue=val[gid]; | ||
if(KUtils.checkUndefined(tmpValue)||KUtils.arrEmpty(tmpValue)){ | ||
//空的,直接push | ||
tmpValue=[]; | ||
tmpValue.push({ | ||
name: name, | ||
value: value, | ||
in: type, | ||
pkid: pkid | ||
}) | ||
tmpVal[gid]=tmpValue; | ||
}else{ | ||
//不为空,更新 | ||
//1.是否包含该参数,包含则更新,不包含新增 | ||
var exlength=tmpValue.filter(p=>p.pkid==pkid && p.in==type).length; | ||
if(exlength==0){ | ||
//不存在 | ||
tmpValue.push({ | ||
name: name, | ||
value: value, | ||
in: type, | ||
pkid: pkid | ||
}) | ||
}else{ | ||
tmpValue.forEach(gp=>{ | ||
if(gp.in==type && gp.pkid==pkid){ | ||
gp.value=value; | ||
} | ||
}) | ||
} | ||
tmpVal[gid]=tmpValue; | ||
} | ||
}) | ||
//存储 | ||
localStore.setItem(constant.globalParameter, tmpVal); | ||
}else{ | ||
var tmpGlobalParams=[]; | ||
tmpGlobalParams.push({ | ||
name: name, | ||
value: value, | ||
in: type, | ||
pkid: pkid | ||
}) | ||
var groupVal={}; | ||
allGroup.forEach(gid=>{ | ||
groupVal[gid]=tmpGlobalParams; | ||
}) | ||
//存储 | ||
localStore.setItem(constant.globalParameter, groupVal); | ||
} | ||
}) | ||
}else{ | ||
//设置当前逻辑分组的全局参数 | ||
localStore.getItem(constant.globalParameter).then(val => { | ||
//存在全局参数 | ||
var groupParameters=[]; | ||
var tmpVal={}; | ||
if(KUtils.checkUndefined(val)){ | ||
for(var gid in val){ | ||
if(gid==key){ | ||
groupParameters=val[gid]; | ||
}else{ | ||
tmpVal[gid]=val[gid]; | ||
} | ||
} | ||
var exlength=groupParameters.filter(p=>p.pkid==pkid && p.in==type).length; | ||
if(exlength==0){ | ||
//不存在 | ||
groupParameters.push({ | ||
name: name, | ||
value: value, | ||
in: type, | ||
pkid: pkid | ||
}) | ||
}else{ | ||
groupParameters.forEach(gp=>{ | ||
if(gp.in==type && gp.pkid==pkid){ | ||
gp.value=value; | ||
} | ||
}) | ||
} | ||
tmpVal[key]=groupParameters; | ||
//存储 | ||
localStore.setItem(constant.globalParameter, tmpVal); | ||
}else{ | ||
groupParameters.push({ | ||
name: name, | ||
value: value, | ||
in: type, | ||
pkid: pkid | ||
}) | ||
} | ||
tmpVal[key]=groupParameters; | ||
// window.console.log(tmpVal) | ||
//存储 | ||
localStore.setItem(constant.globalParameter, tmpVal); | ||
}) | ||
} | ||
} | ||
} | ||
}; | ||
|
||
export default KEnvironment; |
Oops, something went wrong.