[auth] parsing authentications from definitions
This commit is contained in:
39
dist/swagger-ui.js
vendored
39
dist/swagger-ui.js
vendored
@@ -18996,6 +18996,7 @@ window.SwaggerUi = Backbone.Router.extend({
|
|||||||
|
|
||||||
window.SwaggerUi.Views = {};
|
window.SwaggerUi.Views = {};
|
||||||
window.SwaggerUi.partials = {};
|
window.SwaggerUi.partials = {};
|
||||||
|
window.SwaggerUi.utils = {};
|
||||||
|
|
||||||
// don't break backward compatibility with previous versions and warn users to upgrade their code
|
// don't break backward compatibility with previous versions and warn users to upgrade their code
|
||||||
(function(){
|
(function(){
|
||||||
@@ -19053,6 +19054,41 @@ window.SwaggerUi.partials = {};
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
window.SwaggerUi.utils = {
|
||||||
|
parseSecurityDefinitions: function (security) {
|
||||||
|
var auths = window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions;
|
||||||
|
var result = [];
|
||||||
|
|
||||||
|
if (!Array.isArray(security)) { return null; }
|
||||||
|
|
||||||
|
security.forEach(function (item) {
|
||||||
|
var singleSecurity = {};
|
||||||
|
|
||||||
|
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) {
|
||||||
|
if (item[key].indexOf(i) < 0) {
|
||||||
|
delete singleSecurity[key].scopes[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
singleSecurity[key] = item[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.push(singleSecurity);
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
'use strict';
|
||||||
|
|
||||||
SwaggerUi.Views.ApiKeyAuthView = Backbone.View.extend({ // TODO: append this to global SwaggerUi
|
SwaggerUi.Views.ApiKeyAuthView = Backbone.View.extend({ // TODO: append this to global SwaggerUi
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
@@ -19761,8 +19797,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(this.model.security)) {
|
if (Array.isArray(this.model.security)) {
|
||||||
//Todo add parsing security from definitions
|
var authsModel = { auths: SwaggerUi.utils.parseSecurityDefinitions(this.model.security) };
|
||||||
var authsModel = { auths: this.model.security };
|
|
||||||
|
|
||||||
authsModel.isLogout = !_.isEmpty(window.swaggerUi.api.clientAuthorizations.authz);
|
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({model: authsModel, router: this.router});
|
||||||
|
|||||||
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
@@ -249,6 +249,7 @@ window.SwaggerUi = Backbone.Router.extend({
|
|||||||
|
|
||||||
window.SwaggerUi.Views = {};
|
window.SwaggerUi.Views = {};
|
||||||
window.SwaggerUi.partials = {};
|
window.SwaggerUi.partials = {};
|
||||||
|
window.SwaggerUi.utils = {};
|
||||||
|
|
||||||
// don't break backward compatibility with previous versions and warn users to upgrade their code
|
// don't break backward compatibility with previous versions and warn users to upgrade their code
|
||||||
(function(){
|
(function(){
|
||||||
|
|||||||
35
src/main/javascript/utils/utils.js
Normal file
35
src/main/javascript/utils/utils.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
window.SwaggerUi.utils = {
|
||||||
|
parseSecurityDefinitions: function (security) {
|
||||||
|
var auths = window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions;
|
||||||
|
var result = [];
|
||||||
|
|
||||||
|
if (!Array.isArray(security)) { return null; }
|
||||||
|
|
||||||
|
security.forEach(function (item) {
|
||||||
|
var singleSecurity = {};
|
||||||
|
|
||||||
|
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) {
|
||||||
|
if (item[key].indexOf(i) < 0) {
|
||||||
|
delete singleSecurity[key].scopes[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
singleSecurity[key] = item[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.push(singleSecurity);
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -258,8 +258,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(this.model.security)) {
|
if (Array.isArray(this.model.security)) {
|
||||||
//Todo add parsing security from definitions
|
var authsModel = { auths: SwaggerUi.utils.parseSecurityDefinitions(this.model.security) };
|
||||||
var authsModel = { auths: this.model.security };
|
|
||||||
|
|
||||||
authsModel.isLogout = !_.isEmpty(window.swaggerUi.api.clientAuthorizations.authz);
|
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({model: authsModel, router: this.router});
|
||||||
|
|||||||
Reference in New Issue
Block a user