Merge brancht push origin develop_2.0 'bshamblen-oauth_issues' into develop_2.0
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.
|
||||
* @version v2.1.0-alpha.6
|
||||
* @version v2.1.0-alpha.7
|
||||
* @link http://swagger.io
|
||||
* @license apache 2.0
|
||||
*/
|
||||
@@ -76,10 +76,10 @@ SwaggerAuthorizations.prototype.remove = function(name) {
|
||||
|
||||
SwaggerAuthorizations.prototype.apply = function (obj, authorizations) {
|
||||
var status = null;
|
||||
var key;
|
||||
var key, value, result;
|
||||
|
||||
// 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) {
|
||||
value = this.authz[key];
|
||||
result = value.apply(obj, authorizations);
|
||||
@@ -88,13 +88,28 @@ SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 2.0 support
|
||||
if (Array.isArray(authorizations)) {
|
||||
var i;
|
||||
for(i = 0; i < authorizations.length; i++) {
|
||||
for (var i = 0; i < authorizations.length; i++) {
|
||||
var auth = authorizations[i];
|
||||
for (name in auth) {
|
||||
for (key in this.authz) {
|
||||
var value = this.authz[key];
|
||||
if(typeof value !== 'undefined') {
|
||||
if (key == name) {
|
||||
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);
|
||||
if (result === 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 clientId;
|
||||
var realm;
|
||||
var oauth2KeyName;
|
||||
|
||||
function handleLogin() {
|
||||
var scopes = [];
|
||||
@@ -14,6 +15,7 @@ function handleLogin() {
|
||||
for(key in defs) {
|
||||
var auth = defs[key];
|
||||
if(auth.type === 'oauth2' && auth.scopes) {
|
||||
oauth2KeyName = key;
|
||||
var scope;
|
||||
if(Array.isArray(auth.scopes)) {
|
||||
// 1.2 support
|
||||
@@ -86,6 +88,7 @@ function handleLogin() {
|
||||
popupDialog = [];
|
||||
});
|
||||
|
||||
$('button.api-popup-authbtn').unbind();
|
||||
popupDialog.find('button.api-popup-authbtn').click(function() {
|
||||
popupMask.hide();
|
||||
popupDialog.hide();
|
||||
@@ -98,10 +101,13 @@ function handleLogin() {
|
||||
|
||||
for (var key in authSchemes) {
|
||||
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];
|
||||
url = dets.authorizationUrl + '?response_type=token';
|
||||
window.swaggerUi.tokenName = dets.tokenUrl || 'access_token';
|
||||
url = dets.authorizationUrl + '?response_type=' + (flow === 'implicit' ? 'token' : 'code');
|
||||
window.swaggerUi.tokenName = dets.tokenName || 'access_token';
|
||||
window.swaggerUi.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
|
||||
}
|
||||
else if(authSchemes[key].grantTypes) {
|
||||
// 1.2 support
|
||||
@@ -113,6 +119,12 @@ function handleLogin() {
|
||||
url = dets.loginEndpoint.url + '?response_type=token';
|
||||
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');
|
||||
|
||||
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;
|
||||
@@ -169,6 +184,7 @@ function initOAuth(opts) {
|
||||
}
|
||||
|
||||
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
|
||||
$('.api-ic').unbind();
|
||||
$('.api-ic').click(function(s) {
|
||||
if($(s.target).hasClass('ic-off'))
|
||||
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) {
|
||||
if(token) {
|
||||
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) {
|
||||
return key===""?value:decodeURIComponent(value) }
|
||||
):{}
|
||||
|
||||
if (window.opener.swaggerUi.tokenUrl)
|
||||
window.opener.processOAuthCode(qp);
|
||||
else
|
||||
window.opener.onOAuthComplete(qp);
|
||||
|
||||
window.close();
|
||||
</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() {
|
||||
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;
|
||||
if (!isMethodSubmissionSupported) {
|
||||
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.oauth = null;
|
||||
if (this.model.authorizations) {
|
||||
if (Array.isArray(this.model.authorizations)) {
|
||||
_ref5 = this.model.authorizations;
|
||||
for (_i = 0, _len = _ref5.length; _i < _len; _i++) {
|
||||
auths = _ref5[_i];
|
||||
modelAuths = this.model.authorizations || this.model.security;
|
||||
if (modelAuths) {
|
||||
if (Array.isArray(modelAuths)) {
|
||||
for (_i = 0, _len = modelAuths.length; _i < _len; _i++) {
|
||||
auths = modelAuths[_i];
|
||||
for (key in auths) {
|
||||
auth = auths[key];
|
||||
for (a in this.auths) {
|
||||
@@ -1816,9 +1816,11 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
if (auth.type === 'oauth2') {
|
||||
this.model.oauth = {};
|
||||
this.model.oauth.scopes = [];
|
||||
_ref6 = auth.value.scopes;
|
||||
for (k in _ref6) {
|
||||
v = _ref6[k];
|
||||
_ref5 = auth.value.scopes;
|
||||
for (k in _ref5) {
|
||||
v = _ref5[k];
|
||||
scopeIndex = auths[key].indexOf(k);
|
||||
if (scopeIndex >= 0) {
|
||||
o = {
|
||||
scope: k,
|
||||
description: v
|
||||
@@ -1829,10 +1831,10 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_ref7 = this.model.authorizations;
|
||||
for (k in _ref7) {
|
||||
v = _ref7[k];
|
||||
for (k in modelAuths) {
|
||||
v = modelAuths[k];
|
||||
if (k === "oauth2") {
|
||||
if (this.model.oauth === null) {
|
||||
this.model.oauth = {};
|
||||
@@ -1850,9 +1852,9 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
}
|
||||
if (typeof this.model.responses !== 'undefined') {
|
||||
this.model.responseMessages = [];
|
||||
_ref8 = this.model.responses;
|
||||
for (code in _ref8) {
|
||||
value = _ref8[code];
|
||||
_ref6 = this.model.responses;
|
||||
for (code in _ref6) {
|
||||
value = _ref6[code];
|
||||
schema = null;
|
||||
schemaObj = this.model.responses[code].schema;
|
||||
if (schemaObj && schemaObj['$ref']) {
|
||||
@@ -1892,9 +1894,9 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
};
|
||||
contentTypeModel.consumes = this.model.consumes;
|
||||
contentTypeModel.produces = this.model.produces;
|
||||
_ref9 = this.model.parameters;
|
||||
for (_k = 0, _len2 = _ref9.length; _k < _len2; _k++) {
|
||||
param = _ref9[_k];
|
||||
_ref7 = this.model.parameters;
|
||||
for (_k = 0, _len2 = _ref7.length; _k < _len2; _k++) {
|
||||
param = _ref7[_k];
|
||||
type = param.type || param.dataType || '';
|
||||
if (typeof type === 'undefined') {
|
||||
schema = param.schema;
|
||||
@@ -1918,14 +1920,14 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
model: contentTypeModel
|
||||
});
|
||||
$('.response-content-type', $(this.el)).append(responseContentTypeView.render().el);
|
||||
_ref10 = this.model.parameters;
|
||||
for (_l = 0, _len3 = _ref10.length; _l < _len3; _l++) {
|
||||
param = _ref10[_l];
|
||||
_ref8 = this.model.parameters;
|
||||
for (_l = 0, _len3 = _ref8.length; _l < _len3; _l++) {
|
||||
param = _ref8[_l];
|
||||
this.addParameter(param, contentTypeModel.consumes);
|
||||
}
|
||||
_ref11 = this.model.responseMessages;
|
||||
for (_m = 0, _len4 = _ref11.length; _m < _len4; _m++) {
|
||||
statusCode = _ref11[_m];
|
||||
_ref9 = this.model.responseMessages;
|
||||
for (_m = 0, _len4 = _ref9.length; _m < _len4; _m++) {
|
||||
statusCode = _ref9[_m];
|
||||
this.addStatusCode(statusCode);
|
||||
}
|
||||
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.
|
||||
* @version v2.1.0-alpha.6
|
||||
* @version v2.1.0-alpha.7
|
||||
* @link http://swagger.io
|
||||
* @license apache 2.0
|
||||
*/
|
||||
@@ -76,10 +76,10 @@ SwaggerAuthorizations.prototype.remove = function(name) {
|
||||
|
||||
SwaggerAuthorizations.prototype.apply = function (obj, authorizations) {
|
||||
var status = null;
|
||||
var key;
|
||||
var key, value, result;
|
||||
|
||||
// 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) {
|
||||
value = this.authz[key];
|
||||
result = value.apply(obj, authorizations);
|
||||
@@ -88,13 +88,28 @@ SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 2.0 support
|
||||
if (Array.isArray(authorizations)) {
|
||||
var i;
|
||||
for(i = 0; i < authorizations.length; i++) {
|
||||
for (var i = 0; i < authorizations.length; i++) {
|
||||
var auth = authorizations[i];
|
||||
for (name in auth) {
|
||||
for (key in this.authz) {
|
||||
var value = this.authz[key];
|
||||
if(typeof value !== 'undefined') {
|
||||
if (key == name) {
|
||||
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);
|
||||
if (result === true)
|
||||
status = true;
|
||||
|
||||
@@ -3,6 +3,7 @@ var popupMask;
|
||||
var popupDialog;
|
||||
var clientId;
|
||||
var realm;
|
||||
var oauth2KeyName;
|
||||
|
||||
function handleLogin() {
|
||||
var scopes = [];
|
||||
@@ -14,6 +15,7 @@ function handleLogin() {
|
||||
for(key in defs) {
|
||||
var auth = defs[key];
|
||||
if(auth.type === 'oauth2' && auth.scopes) {
|
||||
oauth2KeyName = key;
|
||||
var scope;
|
||||
if(Array.isArray(auth.scopes)) {
|
||||
// 1.2 support
|
||||
@@ -86,6 +88,7 @@ function handleLogin() {
|
||||
popupDialog = [];
|
||||
});
|
||||
|
||||
$('button.api-popup-authbtn').unbind();
|
||||
popupDialog.find('button.api-popup-authbtn').click(function() {
|
||||
popupMask.hide();
|
||||
popupDialog.hide();
|
||||
@@ -98,10 +101,13 @@ function handleLogin() {
|
||||
|
||||
for (var key in authSchemes) {
|
||||
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];
|
||||
url = dets.authorizationUrl + '?response_type=token';
|
||||
window.swaggerUi.tokenName = dets.tokenUrl || 'access_token';
|
||||
url = dets.authorizationUrl + '?response_type=' + (flow === 'implicit' ? 'token' : 'code');
|
||||
window.swaggerUi.tokenName = dets.tokenName || 'access_token';
|
||||
window.swaggerUi.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
|
||||
}
|
||||
else if(authSchemes[key].grantTypes) {
|
||||
// 1.2 support
|
||||
@@ -113,6 +119,12 @@ function handleLogin() {
|
||||
url = dets.loginEndpoint.url + '?response_type=token';
|
||||
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');
|
||||
|
||||
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;
|
||||
@@ -169,6 +184,7 @@ function initOAuth(opts) {
|
||||
}
|
||||
|
||||
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
|
||||
$('.api-ic').unbind();
|
||||
$('.api-ic').click(function(s) {
|
||||
if($(s.target).hasClass('ic-off'))
|
||||
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) {
|
||||
if(token) {
|
||||
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
|
||||
@model.description = @model.description.replace(/(?:\r\n|\r|\n)/g, '<br />')
|
||||
@model.oauth = null
|
||||
if @model.authorizations
|
||||
if Array.isArray @model.authorizations
|
||||
for auths in @model.authorizations
|
||||
modelAuths = @model.authorizations || @model.security
|
||||
if modelAuths
|
||||
if Array.isArray modelAuths
|
||||
for auths in modelAuths
|
||||
for key, auth of auths
|
||||
for a of @auths
|
||||
auth = @auths[a]
|
||||
@@ -62,10 +63,12 @@ class OperationView extends Backbone.View
|
||||
@model.oauth = {}
|
||||
@model.oauth.scopes = []
|
||||
for k, v of auth.value.scopes
|
||||
scopeIndex = auths[key].indexOf k
|
||||
if scopeIndex >= 0
|
||||
o = {scope: k, description: v}
|
||||
@model.oauth.scopes.push o
|
||||
else
|
||||
for k, v of @model.authorizations
|
||||
for k, v of modelAuths
|
||||
if k == "oauth2"
|
||||
if @model.oauth == null
|
||||
@model.oauth = {}
|
||||
|
||||
@@ -10,6 +10,11 @@ qp = qp ? JSON.parse('{"' + qp.replace(/&/g, '","').replace(/=/g,'":"') + '"}',
|
||||
function(key, value) {
|
||||
return key===""?value:decodeURIComponent(value) }
|
||||
):{}
|
||||
|
||||
if (window.opener.swaggerUi.tokenUrl)
|
||||
window.opener.processOAuthCode(qp);
|
||||
else
|
||||
window.opener.onOAuthComplete(qp);
|
||||
|
||||
window.close();
|
||||
</script>
|
||||
Reference in New Issue
Block a user