merged into swagger-js
This commit is contained in:
29
dist/lib/swagger-client.js
vendored
29
dist/lib/swagger-client.js
vendored
@@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* swagger-client - swagger.js is a javascript client for use with swaggering APIs.
|
* swagger-client - swagger.js is a javascript client for use with swaggering APIs.
|
||||||
* @version v2.1.0-alpha.6
|
* @version v2.1.0-alpha.7
|
||||||
* @link http://swagger.io
|
* @link http://swagger.io
|
||||||
* @license apache 2.0
|
* @license apache 2.0
|
||||||
*/
|
*/
|
||||||
@@ -76,10 +76,10 @@ SwaggerAuthorizations.prototype.remove = function(name) {
|
|||||||
|
|
||||||
SwaggerAuthorizations.prototype.apply = function (obj, authorizations) {
|
SwaggerAuthorizations.prototype.apply = function (obj, authorizations) {
|
||||||
var status = null;
|
var status = null;
|
||||||
var key;
|
var key, value, result;
|
||||||
|
|
||||||
// if the "authorizations" key is undefined, or has an empty array, add all keys
|
// if the "authorizations" key is undefined, or has an empty array, add all keys
|
||||||
if(typeof authorizations === 'undefined' || Object.keys(authorizations).length === 0) {
|
if (typeof authorizations === 'undefined' || Object.keys(authorizations).length == 0) {
|
||||||
for (key in this.authz) {
|
for (key in this.authz) {
|
||||||
value = this.authz[key];
|
value = this.authz[key];
|
||||||
result = value.apply(obj, authorizations);
|
result = value.apply(obj, authorizations);
|
||||||
@@ -88,13 +88,28 @@ SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// 2.0 support
|
||||||
if (Array.isArray(authorizations)) {
|
if (Array.isArray(authorizations)) {
|
||||||
var i;
|
for (var i = 0; i < authorizations.length; i++) {
|
||||||
for(i = 0; i < authorizations.length; i++) {
|
|
||||||
var auth = authorizations[i];
|
var auth = authorizations[i];
|
||||||
|
for (name in auth) {
|
||||||
for (key in this.authz) {
|
for (key in this.authz) {
|
||||||
var value = this.authz[key];
|
if (key == name) {
|
||||||
if(typeof value !== 'undefined') {
|
value = this.authz[key];
|
||||||
|
result = value.apply(obj, authorizations);
|
||||||
|
if (result === true)
|
||||||
|
status = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// 1.2 support
|
||||||
|
for (name in authorizations) {
|
||||||
|
for (key in this.authz) {
|
||||||
|
if (key == name) {
|
||||||
|
value = this.authz[key];
|
||||||
result = value.apply(obj, authorizations);
|
result = value.apply(obj, authorizations);
|
||||||
if (result === true)
|
if (result === true)
|
||||||
status = true;
|
status = true;
|
||||||
|
|||||||
48
dist/lib/swagger-oauth.js
vendored
48
dist/lib/swagger-oauth.js
vendored
@@ -3,6 +3,7 @@ var popupMask;
|
|||||||
var popupDialog;
|
var popupDialog;
|
||||||
var clientId;
|
var clientId;
|
||||||
var realm;
|
var realm;
|
||||||
|
var oauth2KeyName;
|
||||||
|
|
||||||
function handleLogin() {
|
function handleLogin() {
|
||||||
var scopes = [];
|
var scopes = [];
|
||||||
@@ -14,6 +15,7 @@ function handleLogin() {
|
|||||||
for(key in defs) {
|
for(key in defs) {
|
||||||
var auth = defs[key];
|
var auth = defs[key];
|
||||||
if(auth.type === 'oauth2' && auth.scopes) {
|
if(auth.type === 'oauth2' && auth.scopes) {
|
||||||
|
oauth2KeyName = key;
|
||||||
var scope;
|
var scope;
|
||||||
if(Array.isArray(auth.scopes)) {
|
if(Array.isArray(auth.scopes)) {
|
||||||
// 1.2 support
|
// 1.2 support
|
||||||
@@ -86,6 +88,7 @@ function handleLogin() {
|
|||||||
popupDialog = [];
|
popupDialog = [];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('button.api-popup-authbtn').unbind();
|
||||||
popupDialog.find('button.api-popup-authbtn').click(function() {
|
popupDialog.find('button.api-popup-authbtn').click(function() {
|
||||||
popupMask.hide();
|
popupMask.hide();
|
||||||
popupDialog.hide();
|
popupDialog.hide();
|
||||||
@@ -98,10 +101,13 @@ function handleLogin() {
|
|||||||
|
|
||||||
for (var key in authSchemes) {
|
for (var key in authSchemes) {
|
||||||
if (authSchemes.hasOwnProperty(key)) {
|
if (authSchemes.hasOwnProperty(key)) {
|
||||||
if(authSchemes[key].type === 'oauth2' && authSchemes[key].flow === 'implicit') {
|
var flow = authSchemes[key].flow;
|
||||||
|
|
||||||
|
if(authSchemes[key].type === 'oauth2' && flow && (flow === 'implicit' || flow === 'accessCode')) {
|
||||||
var dets = authSchemes[key];
|
var dets = authSchemes[key];
|
||||||
url = dets.authorizationUrl + '?response_type=token';
|
url = dets.authorizationUrl + '?response_type=' + (flow === 'implicit' ? 'token' : 'code');
|
||||||
window.swaggerUi.tokenName = dets.tokenUrl || 'access_token';
|
window.swaggerUi.tokenName = dets.tokenName || 'access_token';
|
||||||
|
window.swaggerUi.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
|
||||||
}
|
}
|
||||||
else if(authSchemes[key].grantTypes) {
|
else if(authSchemes[key].grantTypes) {
|
||||||
// 1.2 support
|
// 1.2 support
|
||||||
@@ -113,6 +119,12 @@ function handleLogin() {
|
|||||||
url = dets.loginEndpoint.url + '?response_type=token';
|
url = dets.loginEndpoint.url + '?response_type=token';
|
||||||
window.swaggerUi.tokenName = dets.tokenName;
|
window.swaggerUi.tokenName = dets.tokenName;
|
||||||
}
|
}
|
||||||
|
else if (o.hasOwnProperty(t) && t === 'accessCode') {
|
||||||
|
var dets = o[t];
|
||||||
|
var ep = dets.tokenRequestEndpoint.url;
|
||||||
|
url = dets.tokenRequestEndpoint.url + '?response_type=code';
|
||||||
|
window.swaggerUi.tokenName = dets.tokenName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,7 +133,10 @@ function handleLogin() {
|
|||||||
var o = $('.api-popup-scopes').find('input:checked');
|
var o = $('.api-popup-scopes').find('input:checked');
|
||||||
|
|
||||||
for(k =0; k < o.length; k++) {
|
for(k =0; k < o.length; k++) {
|
||||||
scopes.push($(o[k]).attr('scope'));
|
var scope = $(o[k]).attr('scope');
|
||||||
|
|
||||||
|
if (scopes.indexOf(scope) === -1)
|
||||||
|
scopes.push(scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.enabledScopes=scopes;
|
window.enabledScopes=scopes;
|
||||||
@@ -169,6 +184,7 @@ function initOAuth(opts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
|
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
|
||||||
|
$('.api-ic').unbind();
|
||||||
$('.api-ic').click(function(s) {
|
$('.api-ic').click(function(s) {
|
||||||
if($(s.target).hasClass('ic-off'))
|
if($(s.target).hasClass('ic-off'))
|
||||||
handleLogin();
|
handleLogin();
|
||||||
@@ -179,6 +195,28 @@ function initOAuth(opts) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function processOAuthCode(data) {
|
||||||
|
var params = {
|
||||||
|
'client_id': clientId,
|
||||||
|
'code': data.code,
|
||||||
|
'grant_type': 'authorization_code'
|
||||||
|
}
|
||||||
|
$.ajax(
|
||||||
|
{
|
||||||
|
url : window.swaggerUi.tokenUrl,
|
||||||
|
type: "POST",
|
||||||
|
data: params,
|
||||||
|
success:function(data, textStatus, jqXHR)
|
||||||
|
{
|
||||||
|
onOAuthComplete(data);
|
||||||
|
},
|
||||||
|
error: function(jqXHR, textStatus, errorThrown)
|
||||||
|
{
|
||||||
|
onOAuthComplete("");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function onOAuthComplete(token) {
|
function onOAuthComplete(token) {
|
||||||
if(token) {
|
if(token) {
|
||||||
if(token.error) {
|
if(token.error) {
|
||||||
@@ -230,7 +268,7 @@ function onOAuthComplete(token) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
window.authorizations.add('oauth2', new ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
|
window.authorizations.add(oauth2KeyName, new ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
5
dist/o2c.html
vendored
5
dist/o2c.html
vendored
@@ -10,6 +10,11 @@ qp = qp ? JSON.parse('{"' + qp.replace(/&/g, '","').replace(/=/g,'":"') + '"}',
|
|||||||
function(key, value) {
|
function(key, value) {
|
||||||
return key===""?value:decodeURIComponent(value) }
|
return key===""?value:decodeURIComponent(value) }
|
||||||
):{}
|
):{}
|
||||||
|
|
||||||
|
if (window.opener.swaggerUi.tokenUrl)
|
||||||
|
window.opener.processOAuthCode(qp);
|
||||||
|
else
|
||||||
window.opener.onOAuthComplete(qp);
|
window.opener.onOAuthComplete(qp);
|
||||||
|
|
||||||
window.close();
|
window.close();
|
||||||
</script>
|
</script>
|
||||||
50
dist/swagger-ui.js
vendored
50
dist/swagger-ui.js
vendored
@@ -1794,7 +1794,7 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
|||||||
};
|
};
|
||||||
|
|
||||||
OperationView.prototype.render = function() {
|
OperationView.prototype.render = function() {
|
||||||
var a, auth, auths, code, contentTypeModel, isMethodSubmissionSupported, k, key, o, param, ref, responseContentTypeView, responseSignatureView, schema, schemaObj, signatureModel, statusCode, type, v, value, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref10, _ref11, _ref5, _ref6, _ref7, _ref8, _ref9;
|
var a, auth, auths, code, contentTypeModel, isMethodSubmissionSupported, k, key, modelAuths, o, param, ref, responseContentTypeView, responseSignatureView, schema, schemaObj, scopeIndex, signatureModel, statusCode, type, v, value, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref5, _ref6, _ref7, _ref8, _ref9;
|
||||||
isMethodSubmissionSupported = true;
|
isMethodSubmissionSupported = true;
|
||||||
if (!isMethodSubmissionSupported) {
|
if (!isMethodSubmissionSupported) {
|
||||||
this.model.isReadOnly = true;
|
this.model.isReadOnly = true;
|
||||||
@@ -1804,11 +1804,11 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
|||||||
this.model.description = this.model.description.replace(/(?:\r\n|\r|\n)/g, '<br />');
|
this.model.description = this.model.description.replace(/(?:\r\n|\r|\n)/g, '<br />');
|
||||||
}
|
}
|
||||||
this.model.oauth = null;
|
this.model.oauth = null;
|
||||||
if (this.model.authorizations) {
|
modelAuths = this.model.authorizations || this.model.security;
|
||||||
if (Array.isArray(this.model.authorizations)) {
|
if (modelAuths) {
|
||||||
_ref5 = this.model.authorizations;
|
if (Array.isArray(modelAuths)) {
|
||||||
for (_i = 0, _len = _ref5.length; _i < _len; _i++) {
|
for (_i = 0, _len = modelAuths.length; _i < _len; _i++) {
|
||||||
auths = _ref5[_i];
|
auths = modelAuths[_i];
|
||||||
for (key in auths) {
|
for (key in auths) {
|
||||||
auth = auths[key];
|
auth = auths[key];
|
||||||
for (a in this.auths) {
|
for (a in this.auths) {
|
||||||
@@ -1816,9 +1816,11 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
|||||||
if (auth.type === 'oauth2') {
|
if (auth.type === 'oauth2') {
|
||||||
this.model.oauth = {};
|
this.model.oauth = {};
|
||||||
this.model.oauth.scopes = [];
|
this.model.oauth.scopes = [];
|
||||||
_ref6 = auth.value.scopes;
|
_ref5 = auth.value.scopes;
|
||||||
for (k in _ref6) {
|
for (k in _ref5) {
|
||||||
v = _ref6[k];
|
v = _ref5[k];
|
||||||
|
scopeIndex = auths[key].indexOf(k);
|
||||||
|
if (scopeIndex >= 0) {
|
||||||
o = {
|
o = {
|
||||||
scope: k,
|
scope: k,
|
||||||
description: v
|
description: v
|
||||||
@@ -1829,10 +1831,10 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
_ref7 = this.model.authorizations;
|
for (k in modelAuths) {
|
||||||
for (k in _ref7) {
|
v = modelAuths[k];
|
||||||
v = _ref7[k];
|
|
||||||
if (k === "oauth2") {
|
if (k === "oauth2") {
|
||||||
if (this.model.oauth === null) {
|
if (this.model.oauth === null) {
|
||||||
this.model.oauth = {};
|
this.model.oauth = {};
|
||||||
@@ -1850,9 +1852,9 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
|||||||
}
|
}
|
||||||
if (typeof this.model.responses !== 'undefined') {
|
if (typeof this.model.responses !== 'undefined') {
|
||||||
this.model.responseMessages = [];
|
this.model.responseMessages = [];
|
||||||
_ref8 = this.model.responses;
|
_ref6 = this.model.responses;
|
||||||
for (code in _ref8) {
|
for (code in _ref6) {
|
||||||
value = _ref8[code];
|
value = _ref6[code];
|
||||||
schema = null;
|
schema = null;
|
||||||
schemaObj = this.model.responses[code].schema;
|
schemaObj = this.model.responses[code].schema;
|
||||||
if (schemaObj && schemaObj['$ref']) {
|
if (schemaObj && schemaObj['$ref']) {
|
||||||
@@ -1892,9 +1894,9 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
|||||||
};
|
};
|
||||||
contentTypeModel.consumes = this.model.consumes;
|
contentTypeModel.consumes = this.model.consumes;
|
||||||
contentTypeModel.produces = this.model.produces;
|
contentTypeModel.produces = this.model.produces;
|
||||||
_ref9 = this.model.parameters;
|
_ref7 = this.model.parameters;
|
||||||
for (_k = 0, _len2 = _ref9.length; _k < _len2; _k++) {
|
for (_k = 0, _len2 = _ref7.length; _k < _len2; _k++) {
|
||||||
param = _ref9[_k];
|
param = _ref7[_k];
|
||||||
type = param.type || param.dataType || '';
|
type = param.type || param.dataType || '';
|
||||||
if (typeof type === 'undefined') {
|
if (typeof type === 'undefined') {
|
||||||
schema = param.schema;
|
schema = param.schema;
|
||||||
@@ -1918,14 +1920,14 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
|||||||
model: contentTypeModel
|
model: contentTypeModel
|
||||||
});
|
});
|
||||||
$('.response-content-type', $(this.el)).append(responseContentTypeView.render().el);
|
$('.response-content-type', $(this.el)).append(responseContentTypeView.render().el);
|
||||||
_ref10 = this.model.parameters;
|
_ref8 = this.model.parameters;
|
||||||
for (_l = 0, _len3 = _ref10.length; _l < _len3; _l++) {
|
for (_l = 0, _len3 = _ref8.length; _l < _len3; _l++) {
|
||||||
param = _ref10[_l];
|
param = _ref8[_l];
|
||||||
this.addParameter(param, contentTypeModel.consumes);
|
this.addParameter(param, contentTypeModel.consumes);
|
||||||
}
|
}
|
||||||
_ref11 = this.model.responseMessages;
|
_ref9 = this.model.responseMessages;
|
||||||
for (_m = 0, _len4 = _ref11.length; _m < _len4; _m++) {
|
for (_m = 0, _len4 = _ref9.length; _m < _len4; _m++) {
|
||||||
statusCode = _ref11[_m];
|
statusCode = _ref9[_m];
|
||||||
this.addStatusCode(statusCode);
|
this.addStatusCode(statusCode);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
2
dist/swagger-ui.min.js
vendored
2
dist/swagger-ui.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* swagger-client - swagger.js is a javascript client for use with swaggering APIs.
|
* swagger-client - swagger.js is a javascript client for use with swaggering APIs.
|
||||||
* @version v2.1.0-alpha.6
|
* @version v2.1.0-alpha.7
|
||||||
* @link http://swagger.io
|
* @link http://swagger.io
|
||||||
* @license apache 2.0
|
* @license apache 2.0
|
||||||
*/
|
*/
|
||||||
@@ -76,10 +76,10 @@ SwaggerAuthorizations.prototype.remove = function(name) {
|
|||||||
|
|
||||||
SwaggerAuthorizations.prototype.apply = function (obj, authorizations) {
|
SwaggerAuthorizations.prototype.apply = function (obj, authorizations) {
|
||||||
var status = null;
|
var status = null;
|
||||||
var key;
|
var key, value, result;
|
||||||
|
|
||||||
// if the "authorizations" key is undefined, or has an empty array, add all keys
|
// if the "authorizations" key is undefined, or has an empty array, add all keys
|
||||||
if(typeof authorizations === 'undefined' || Object.keys(authorizations).length === 0) {
|
if (typeof authorizations === 'undefined' || Object.keys(authorizations).length == 0) {
|
||||||
for (key in this.authz) {
|
for (key in this.authz) {
|
||||||
value = this.authz[key];
|
value = this.authz[key];
|
||||||
result = value.apply(obj, authorizations);
|
result = value.apply(obj, authorizations);
|
||||||
@@ -88,13 +88,28 @@ SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// 2.0 support
|
||||||
if (Array.isArray(authorizations)) {
|
if (Array.isArray(authorizations)) {
|
||||||
var i;
|
for (var i = 0; i < authorizations.length; i++) {
|
||||||
for(i = 0; i < authorizations.length; i++) {
|
|
||||||
var auth = authorizations[i];
|
var auth = authorizations[i];
|
||||||
|
for (name in auth) {
|
||||||
for (key in this.authz) {
|
for (key in this.authz) {
|
||||||
var value = this.authz[key];
|
if (key == name) {
|
||||||
if(typeof value !== 'undefined') {
|
value = this.authz[key];
|
||||||
|
result = value.apply(obj, authorizations);
|
||||||
|
if (result === true)
|
||||||
|
status = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// 1.2 support
|
||||||
|
for (name in authorizations) {
|
||||||
|
for (key in this.authz) {
|
||||||
|
if (key == name) {
|
||||||
|
value = this.authz[key];
|
||||||
result = value.apply(obj, authorizations);
|
result = value.apply(obj, authorizations);
|
||||||
if (result === true)
|
if (result === true)
|
||||||
status = true;
|
status = true;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ var popupMask;
|
|||||||
var popupDialog;
|
var popupDialog;
|
||||||
var clientId;
|
var clientId;
|
||||||
var realm;
|
var realm;
|
||||||
|
var oauth2KeyName;
|
||||||
|
|
||||||
function handleLogin() {
|
function handleLogin() {
|
||||||
var scopes = [];
|
var scopes = [];
|
||||||
@@ -14,6 +15,7 @@ function handleLogin() {
|
|||||||
for(key in defs) {
|
for(key in defs) {
|
||||||
var auth = defs[key];
|
var auth = defs[key];
|
||||||
if(auth.type === 'oauth2' && auth.scopes) {
|
if(auth.type === 'oauth2' && auth.scopes) {
|
||||||
|
oauth2KeyName = key;
|
||||||
var scope;
|
var scope;
|
||||||
if(Array.isArray(auth.scopes)) {
|
if(Array.isArray(auth.scopes)) {
|
||||||
// 1.2 support
|
// 1.2 support
|
||||||
@@ -86,6 +88,7 @@ function handleLogin() {
|
|||||||
popupDialog = [];
|
popupDialog = [];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('button.api-popup-authbtn').unbind();
|
||||||
popupDialog.find('button.api-popup-authbtn').click(function() {
|
popupDialog.find('button.api-popup-authbtn').click(function() {
|
||||||
popupMask.hide();
|
popupMask.hide();
|
||||||
popupDialog.hide();
|
popupDialog.hide();
|
||||||
@@ -98,10 +101,13 @@ function handleLogin() {
|
|||||||
|
|
||||||
for (var key in authSchemes) {
|
for (var key in authSchemes) {
|
||||||
if (authSchemes.hasOwnProperty(key)) {
|
if (authSchemes.hasOwnProperty(key)) {
|
||||||
if(authSchemes[key].type === 'oauth2' && authSchemes[key].flow === 'implicit') {
|
var flow = authSchemes[key].flow;
|
||||||
|
|
||||||
|
if(authSchemes[key].type === 'oauth2' && flow && (flow === 'implicit' || flow === 'accessCode')) {
|
||||||
var dets = authSchemes[key];
|
var dets = authSchemes[key];
|
||||||
url = dets.authorizationUrl + '?response_type=token';
|
url = dets.authorizationUrl + '?response_type=' + (flow === 'implicit' ? 'token' : 'code');
|
||||||
window.swaggerUi.tokenName = dets.tokenUrl || 'access_token';
|
window.swaggerUi.tokenName = dets.tokenName || 'access_token';
|
||||||
|
window.swaggerUi.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
|
||||||
}
|
}
|
||||||
else if(authSchemes[key].grantTypes) {
|
else if(authSchemes[key].grantTypes) {
|
||||||
// 1.2 support
|
// 1.2 support
|
||||||
@@ -113,6 +119,12 @@ function handleLogin() {
|
|||||||
url = dets.loginEndpoint.url + '?response_type=token';
|
url = dets.loginEndpoint.url + '?response_type=token';
|
||||||
window.swaggerUi.tokenName = dets.tokenName;
|
window.swaggerUi.tokenName = dets.tokenName;
|
||||||
}
|
}
|
||||||
|
else if (o.hasOwnProperty(t) && t === 'accessCode') {
|
||||||
|
var dets = o[t];
|
||||||
|
var ep = dets.tokenRequestEndpoint.url;
|
||||||
|
url = dets.tokenRequestEndpoint.url + '?response_type=code';
|
||||||
|
window.swaggerUi.tokenName = dets.tokenName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,7 +133,10 @@ function handleLogin() {
|
|||||||
var o = $('.api-popup-scopes').find('input:checked');
|
var o = $('.api-popup-scopes').find('input:checked');
|
||||||
|
|
||||||
for(k =0; k < o.length; k++) {
|
for(k =0; k < o.length; k++) {
|
||||||
scopes.push($(o[k]).attr('scope'));
|
var scope = $(o[k]).attr('scope');
|
||||||
|
|
||||||
|
if (scopes.indexOf(scope) === -1)
|
||||||
|
scopes.push(scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.enabledScopes=scopes;
|
window.enabledScopes=scopes;
|
||||||
@@ -169,6 +184,7 @@ function initOAuth(opts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
|
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
|
||||||
|
$('.api-ic').unbind();
|
||||||
$('.api-ic').click(function(s) {
|
$('.api-ic').click(function(s) {
|
||||||
if($(s.target).hasClass('ic-off'))
|
if($(s.target).hasClass('ic-off'))
|
||||||
handleLogin();
|
handleLogin();
|
||||||
@@ -179,6 +195,28 @@ function initOAuth(opts) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function processOAuthCode(data) {
|
||||||
|
var params = {
|
||||||
|
'client_id': clientId,
|
||||||
|
'code': data.code,
|
||||||
|
'grant_type': 'authorization_code'
|
||||||
|
}
|
||||||
|
$.ajax(
|
||||||
|
{
|
||||||
|
url : window.swaggerUi.tokenUrl,
|
||||||
|
type: "POST",
|
||||||
|
data: params,
|
||||||
|
success:function(data, textStatus, jqXHR)
|
||||||
|
{
|
||||||
|
onOAuthComplete(data);
|
||||||
|
},
|
||||||
|
error: function(jqXHR, textStatus, errorThrown)
|
||||||
|
{
|
||||||
|
onOAuthComplete("");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function onOAuthComplete(token) {
|
function onOAuthComplete(token) {
|
||||||
if(token) {
|
if(token) {
|
||||||
if(token.error) {
|
if(token.error) {
|
||||||
@@ -230,7 +268,7 @@ function onOAuthComplete(token) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
window.authorizations.add('oauth2', new ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
|
window.authorizations.add(oauth2KeyName, new ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,9 +52,10 @@ class OperationView extends Backbone.View
|
|||||||
if @model.description
|
if @model.description
|
||||||
@model.description = @model.description.replace(/(?:\r\n|\r|\n)/g, '<br />')
|
@model.description = @model.description.replace(/(?:\r\n|\r|\n)/g, '<br />')
|
||||||
@model.oauth = null
|
@model.oauth = null
|
||||||
if @model.authorizations
|
modelAuths = @model.authorizations || @model.security
|
||||||
if Array.isArray @model.authorizations
|
if modelAuths
|
||||||
for auths in @model.authorizations
|
if Array.isArray modelAuths
|
||||||
|
for auths in modelAuths
|
||||||
for key, auth of auths
|
for key, auth of auths
|
||||||
for a of @auths
|
for a of @auths
|
||||||
auth = @auths[a]
|
auth = @auths[a]
|
||||||
@@ -62,10 +63,12 @@ class OperationView extends Backbone.View
|
|||||||
@model.oauth = {}
|
@model.oauth = {}
|
||||||
@model.oauth.scopes = []
|
@model.oauth.scopes = []
|
||||||
for k, v of auth.value.scopes
|
for k, v of auth.value.scopes
|
||||||
|
scopeIndex = auths[key].indexOf k
|
||||||
|
if scopeIndex >= 0
|
||||||
o = {scope: k, description: v}
|
o = {scope: k, description: v}
|
||||||
@model.oauth.scopes.push o
|
@model.oauth.scopes.push o
|
||||||
else
|
else
|
||||||
for k, v of @model.authorizations
|
for k, v of modelAuths
|
||||||
if k == "oauth2"
|
if k == "oauth2"
|
||||||
if @model.oauth == null
|
if @model.oauth == null
|
||||||
@model.oauth = {}
|
@model.oauth = {}
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ qp = qp ? JSON.parse('{"' + qp.replace(/&/g, '","').replace(/=/g,'":"') + '"}',
|
|||||||
function(key, value) {
|
function(key, value) {
|
||||||
return key===""?value:decodeURIComponent(value) }
|
return key===""?value:decodeURIComponent(value) }
|
||||||
):{}
|
):{}
|
||||||
|
|
||||||
|
if (window.opener.swaggerUi.tokenUrl)
|
||||||
|
window.opener.processOAuthCode(qp);
|
||||||
|
else
|
||||||
window.opener.onOAuthComplete(qp);
|
window.opener.onOAuthComplete(qp);
|
||||||
|
|
||||||
window.close();
|
window.close();
|
||||||
</script>
|
</script>
|
||||||
Reference in New Issue
Block a user