[auth] added support of oauth2 in security popup
This commit is contained in:
42
dist/swagger-ui.js
vendored
42
dist/swagger-ui.js
vendored
@@ -18893,15 +18893,13 @@ window.SwaggerUi = Backbone.Router.extend({
|
||||
router: this
|
||||
}).render();
|
||||
if (!_.isEmpty(this.api.securityDefinitions)){
|
||||
authsModel = {
|
||||
auths: _.map(this.api.securityDefinitions, function (auth, name) {
|
||||
authsModel = _.map(this.api.securityDefinitions, function (auth, name) {
|
||||
var result = {};
|
||||
result[name] = auth;
|
||||
return result;
|
||||
})
|
||||
};
|
||||
});
|
||||
this.authView = new SwaggerUi.Views.AuthButtonView({
|
||||
model: authsModel,
|
||||
data: SwaggerUi.utils.parseSecurityDefinitions(authsModel),
|
||||
router: this
|
||||
});
|
||||
$('#auth_container').append(this.authView.render().el);
|
||||
@@ -19057,34 +19055,46 @@ window.SwaggerUi.utils = {};
|
||||
window.SwaggerUi.utils = {
|
||||
parseSecurityDefinitions: function (security) {
|
||||
var auths = window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions;
|
||||
var result = [];
|
||||
var oauth2Arr = [];
|
||||
var authsArr = [];
|
||||
|
||||
if (!Array.isArray(security)) { return null; }
|
||||
|
||||
security.forEach(function (item) {
|
||||
var singleSecurity = {};
|
||||
var singleOauth2Security = {};
|
||||
|
||||
for (var key in item) {
|
||||
if (Array.isArray(item[key])) {
|
||||
if (!auths[key]) { continue; }
|
||||
auths[key] = auths[key] || {};
|
||||
singleSecurity[key] = auths[key];
|
||||
if (auths[key].type === 'oauth2') {
|
||||
for (var i in singleSecurity[key].scopes) {
|
||||
singleOauth2Security[key] = auths[key];
|
||||
for (var i in singleOauth2Security[key].scopes) {
|
||||
if (item[key].indexOf(i) < 0) {
|
||||
delete singleSecurity[key].scopes[i];
|
||||
delete singleOauth2Security[key].scopes[i];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
singleSecurity[key] = auths[key];
|
||||
}
|
||||
} else {
|
||||
singleSecurity[key] = item[key];
|
||||
if (item[key].type === 'oauth2') {
|
||||
singleOauth2Security[key] = item[key];
|
||||
} else {
|
||||
singleSecurity[key] = item[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result.push(singleSecurity);
|
||||
authsArr.push(singleSecurity);
|
||||
oauth2Arr.push(singleOauth2Security);
|
||||
});
|
||||
|
||||
return result;
|
||||
return {
|
||||
auths : authsArr,
|
||||
oauth2: oauth2Arr
|
||||
};
|
||||
}
|
||||
};
|
||||
'use strict';
|
||||
@@ -19134,7 +19144,9 @@ SwaggerUi.Views.AuthButtonView = Backbone.View.extend({
|
||||
|
||||
initialize: function(opts) {
|
||||
this.options = opts || {};
|
||||
this.options.data = this.options.data || {};
|
||||
this.router = this.options.router;
|
||||
this.auths = this.options.data.auths;
|
||||
},
|
||||
|
||||
render: function () {
|
||||
@@ -19150,7 +19162,7 @@ SwaggerUi.Views.AuthButtonView = Backbone.View.extend({
|
||||
|
||||
authsModel = {
|
||||
title: 'Available authorizations',
|
||||
content: this.renderAuths(this.model.auths)
|
||||
content: this.renderAuths(this.auths)
|
||||
};
|
||||
|
||||
this.popup = new SwaggerUi.Views.PopupView({model: authsModel});
|
||||
@@ -19797,10 +19809,10 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
|
||||
}
|
||||
|
||||
if (Array.isArray(this.model.security)) {
|
||||
var authsModel = { auths: SwaggerUi.utils.parseSecurityDefinitions(this.model.security) };
|
||||
var authsModel = SwaggerUi.utils.parseSecurityDefinitions(this.model.security);
|
||||
|
||||
authsModel.isLogout = !_.isEmpty(window.swaggerUi.api.clientAuthorizations.authz);
|
||||
this.authView = new SwaggerUi.Views.AuthButtonView({model: authsModel, router: this.router});
|
||||
this.authView = new SwaggerUi.Views.AuthButtonView({data: authsModel, router: this.router});
|
||||
this.$('.authorize-wrapper').append(this.authView.render().el);
|
||||
}
|
||||
|
||||
|
||||
4
dist/swagger-ui.min.js
vendored
4
dist/swagger-ui.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -146,15 +146,13 @@ window.SwaggerUi = Backbone.Router.extend({
|
||||
router: this
|
||||
}).render();
|
||||
if (!_.isEmpty(this.api.securityDefinitions)){
|
||||
authsModel = {
|
||||
auths: _.map(this.api.securityDefinitions, function (auth, name) {
|
||||
authsModel = _.map(this.api.securityDefinitions, function (auth, name) {
|
||||
var result = {};
|
||||
result[name] = auth;
|
||||
return result;
|
||||
})
|
||||
};
|
||||
});
|
||||
this.authView = new SwaggerUi.Views.AuthButtonView({
|
||||
model: authsModel,
|
||||
data: SwaggerUi.utils.parseSecurityDefinitions(authsModel),
|
||||
router: this
|
||||
});
|
||||
$('#auth_container').append(this.authView.render().el);
|
||||
|
||||
@@ -3,33 +3,45 @@
|
||||
window.SwaggerUi.utils = {
|
||||
parseSecurityDefinitions: function (security) {
|
||||
var auths = window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions;
|
||||
var result = [];
|
||||
var oauth2Arr = [];
|
||||
var authsArr = [];
|
||||
|
||||
if (!Array.isArray(security)) { return null; }
|
||||
|
||||
security.forEach(function (item) {
|
||||
var singleSecurity = {};
|
||||
var singleOauth2Security = {};
|
||||
|
||||
for (var key in item) {
|
||||
if (Array.isArray(item[key])) {
|
||||
if (!auths[key]) { continue; }
|
||||
auths[key] = auths[key] || {};
|
||||
singleSecurity[key] = auths[key];
|
||||
if (auths[key].type === 'oauth2') {
|
||||
for (var i in singleSecurity[key].scopes) {
|
||||
singleOauth2Security[key] = auths[key];
|
||||
for (var i in singleOauth2Security[key].scopes) {
|
||||
if (item[key].indexOf(i) < 0) {
|
||||
delete singleSecurity[key].scopes[i];
|
||||
delete singleOauth2Security[key].scopes[i];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
singleSecurity[key] = auths[key];
|
||||
}
|
||||
} else {
|
||||
singleSecurity[key] = item[key];
|
||||
if (item[key].type === 'oauth2') {
|
||||
singleOauth2Security[key] = item[key];
|
||||
} else {
|
||||
singleSecurity[key] = item[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result.push(singleSecurity);
|
||||
authsArr.push(singleSecurity);
|
||||
oauth2Arr.push(singleOauth2Security);
|
||||
});
|
||||
|
||||
return result;
|
||||
return {
|
||||
auths : authsArr,
|
||||
oauth2: oauth2Arr
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -12,7 +12,9 @@ SwaggerUi.Views.AuthButtonView = Backbone.View.extend({
|
||||
|
||||
initialize: function(opts) {
|
||||
this.options = opts || {};
|
||||
this.options.data = this.options.data || {};
|
||||
this.router = this.options.router;
|
||||
this.auths = this.options.data.auths;
|
||||
},
|
||||
|
||||
render: function () {
|
||||
@@ -28,7 +30,7 @@ SwaggerUi.Views.AuthButtonView = Backbone.View.extend({
|
||||
|
||||
authsModel = {
|
||||
title: 'Available authorizations',
|
||||
content: this.renderAuths(this.model.auths)
|
||||
content: this.renderAuths(this.auths)
|
||||
};
|
||||
|
||||
this.popup = new SwaggerUi.Views.PopupView({model: authsModel});
|
||||
|
||||
@@ -258,10 +258,10 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
|
||||
}
|
||||
|
||||
if (Array.isArray(this.model.security)) {
|
||||
var authsModel = { auths: SwaggerUi.utils.parseSecurityDefinitions(this.model.security) };
|
||||
var authsModel = SwaggerUi.utils.parseSecurityDefinitions(this.model.security);
|
||||
|
||||
authsModel.isLogout = !_.isEmpty(window.swaggerUi.api.clientAuthorizations.authz);
|
||||
this.authView = new SwaggerUi.Views.AuthButtonView({model: authsModel, router: this.router});
|
||||
this.authView = new SwaggerUi.Views.AuthButtonView({data: authsModel, router: this.router});
|
||||
this.$('.authorize-wrapper').append(this.authView.render().el);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user