[auth] Added logout for auth with apiKey and basic auth
This commit is contained in:
@@ -28,23 +28,23 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
|
||||
|
||||
authsModel = {
|
||||
title: 'Available authorizations',
|
||||
content: this.renderAuths()
|
||||
content: this.renderAuths(this.model.auths)
|
||||
};
|
||||
|
||||
this.popup = new SwaggerUi.Views.PopupView({model: authsModel});
|
||||
this.popup.render();
|
||||
},
|
||||
|
||||
renderAuths: function () {
|
||||
renderAuths: function (auths) {
|
||||
var name, authEl, auth;
|
||||
var el = $('<div>');
|
||||
|
||||
//todo refactor, copy-pasted from MainView.js
|
||||
for (name in this.model.auths) {
|
||||
auth = this.model.auths[name];
|
||||
for (name in auths) {
|
||||
auth = auths[name];
|
||||
|
||||
if (auth.type === 'apiKey') {
|
||||
authEl = new SwaggerUi.Views.ApiKeyButton({model: auth, router: this.router}).render().el;
|
||||
authEl = new SwaggerUi.Views.ApiKeyButton({model: auth, router: this.router}).render().el;
|
||||
el.append(authEl);
|
||||
} else if (auth.type === 'basic' && el.find('.basic_auth_container').length === 0) {
|
||||
authEl = new SwaggerUi.Views.BasicAuthButton({model: auth, router: this.router}).render().el;
|
||||
@@ -57,16 +57,40 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
|
||||
|
||||
logoutClick: function (e) {
|
||||
var authsModel;
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
authsModel = {
|
||||
title: 'Logout authorizations'
|
||||
title: 'Logout authorizations',
|
||||
content: this.renderAuths(this.getAuthMap())
|
||||
};
|
||||
|
||||
this.popup = new SwaggerUi.Views.PopupView({model: authsModel});
|
||||
this.popup.render();
|
||||
},
|
||||
|
||||
console.log(window.swaggerUi.api.clientAuthorizations.authz);
|
||||
getAuthMap: function () {
|
||||
var authsMap = {};
|
||||
|
||||
_.forEach(window.swaggerUi.api.clientAuthorizations.authz, function (value, key) {
|
||||
if (key === 'basic') {
|
||||
authsMap.basic = {
|
||||
type: key,
|
||||
isLogout: true,
|
||||
name: key
|
||||
};
|
||||
} else {
|
||||
authsMap[key] = {
|
||||
type: 'apiKey',
|
||||
'in': value.type,
|
||||
value: value.value,
|
||||
isLogout: true,
|
||||
name: key
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
return authsMap;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user