[auth] Added logout for auth with apiKey and basic auth
This commit is contained in:
4
dist/css/print.css
vendored
4
dist/css/print.css
vendored
@@ -1203,7 +1203,8 @@
|
|||||||
color: #999999;
|
color: #999999;
|
||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
}
|
}
|
||||||
.swagger-section .auth_container .auth_submit__button {
|
.swagger-section .auth_container .auth_submit__button,
|
||||||
|
.swagger-section .auth_container .auth_logout__button {
|
||||||
color: #547f00;
|
color: #547f00;
|
||||||
border: none;
|
border: none;
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
@@ -1211,6 +1212,7 @@
|
|||||||
padding-left: 0;
|
padding-left: 0;
|
||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
outline: none;
|
||||||
}
|
}
|
||||||
.swagger-section .auth_container .key_input_container {
|
.swagger-section .auth_container .key_input_container {
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
|
|||||||
4
dist/css/screen.css
vendored
4
dist/css/screen.css
vendored
@@ -1203,7 +1203,8 @@
|
|||||||
color: #999999;
|
color: #999999;
|
||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
}
|
}
|
||||||
.swagger-section .auth_container .auth_submit__button {
|
.swagger-section .auth_container .auth_submit__button,
|
||||||
|
.swagger-section .auth_container .auth_logout__button {
|
||||||
color: #547f00;
|
color: #547f00;
|
||||||
border: none;
|
border: none;
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
@@ -1211,6 +1212,7 @@
|
|||||||
padding-left: 0;
|
padding-left: 0;
|
||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
outline: none;
|
||||||
}
|
}
|
||||||
.swagger-section .auth_container .key_input_container {
|
.swagger-section .auth_container .key_input_container {
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
|
|||||||
2
dist/index.html
vendored
2
dist/index.html
vendored
@@ -36,7 +36,7 @@
|
|||||||
if (url && url.length > 1) {
|
if (url && url.length > 1) {
|
||||||
url = decodeURIComponent(url[1]);
|
url = decodeURIComponent(url[1]);
|
||||||
} else {
|
} else {
|
||||||
url = "http://petstore.swagger.io/v2/swagger.json";
|
url = "http://localhost:3001/swagger.json";
|
||||||
}
|
}
|
||||||
|
|
||||||
hljs.configure({
|
hljs.configure({
|
||||||
|
|||||||
112
dist/swagger-ui.js
vendored
112
dist/swagger-ui.js
vendored
File diff suppressed because one or more lines are too long
22
dist/swagger-ui.min.js
vendored
22
dist/swagger-ui.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -1203,7 +1203,8 @@
|
|||||||
color: #999999;
|
color: #999999;
|
||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
}
|
}
|
||||||
.swagger-section .auth_container .auth_submit__button {
|
.swagger-section .auth_container .auth_submit__button,
|
||||||
|
.swagger-section .auth_container .auth_logout__button {
|
||||||
color: #547f00;
|
color: #547f00;
|
||||||
border: none;
|
border: none;
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
@@ -1211,6 +1212,7 @@
|
|||||||
padding-left: 0;
|
padding-left: 0;
|
||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
outline: none;
|
||||||
}
|
}
|
||||||
.swagger-section .auth_container .key_input_container {
|
.swagger-section .auth_container .key_input_container {
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
|
|||||||
@@ -1203,7 +1203,8 @@
|
|||||||
color: #999999;
|
color: #999999;
|
||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
}
|
}
|
||||||
.swagger-section .auth_container .auth_submit__button {
|
.swagger-section .auth_container .auth_submit__button,
|
||||||
|
.swagger-section .auth_container .auth_logout__button {
|
||||||
color: #547f00;
|
color: #547f00;
|
||||||
border: none;
|
border: none;
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
@@ -1211,6 +1212,7 @@
|
|||||||
padding-left: 0;
|
padding-left: 0;
|
||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
outline: none;
|
||||||
}
|
}
|
||||||
.swagger-section .auth_container .key_input_container {
|
.swagger-section .auth_container .key_input_container {
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
if (url && url.length > 1) {
|
if (url && url.length > 1) {
|
||||||
url = decodeURIComponent(url[1]);
|
url = decodeURIComponent(url[1]);
|
||||||
} else {
|
} else {
|
||||||
url = "http://petstore.swagger.io/v2/swagger.json";
|
url = "http://localhost:3001/swagger.json";
|
||||||
}
|
}
|
||||||
|
|
||||||
hljs.configure({
|
hljs.configure({
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
SwaggerUi.Views.ApiKeyButton = Backbone.View.extend({ // TODO: append this to global SwaggerUi
|
SwaggerUi.Views.ApiKeyButton = Backbone.View.extend({ // TODO: append this to global SwaggerUi
|
||||||
|
|
||||||
events:{
|
events:{
|
||||||
'click .auth_submit_button' : 'applyApiKey'
|
'click .auth_submit_button' : 'applyApiKey',
|
||||||
|
'click .auth_logout__button' : 'clickLogout'
|
||||||
},
|
},
|
||||||
|
|
||||||
template: Handlebars.templates.apikey_button_view,
|
template: Handlebars.templates.apikey_button_view,
|
||||||
@@ -28,6 +29,11 @@ SwaggerUi.Views.ApiKeyButton = Backbone.View.extend({ // TODO: append this to gl
|
|||||||
);
|
);
|
||||||
this.router.api.clientAuthorizations.add(this.model.name, keyAuth);
|
this.router.api.clientAuthorizations.add(this.model.name, keyAuth);
|
||||||
this.router.load();
|
this.router.load();
|
||||||
|
},
|
||||||
|
|
||||||
|
clickLogout: function () {
|
||||||
|
window.swaggerUi.api.clientAuthorizations.remove(this.model.name);
|
||||||
|
this.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -28,23 +28,23 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
|
|||||||
|
|
||||||
authsModel = {
|
authsModel = {
|
||||||
title: 'Available authorizations',
|
title: 'Available authorizations',
|
||||||
content: this.renderAuths()
|
content: this.renderAuths(this.model.auths)
|
||||||
};
|
};
|
||||||
|
|
||||||
this.popup = new SwaggerUi.Views.PopupView({model: authsModel});
|
this.popup = new SwaggerUi.Views.PopupView({model: authsModel});
|
||||||
this.popup.render();
|
this.popup.render();
|
||||||
},
|
},
|
||||||
|
|
||||||
renderAuths: function () {
|
renderAuths: function (auths) {
|
||||||
var name, authEl, auth;
|
var name, authEl, auth;
|
||||||
var el = $('<div>');
|
var el = $('<div>');
|
||||||
|
|
||||||
//todo refactor, copy-pasted from MainView.js
|
//todo refactor, copy-pasted from MainView.js
|
||||||
for (name in this.model.auths) {
|
for (name in auths) {
|
||||||
auth = this.model.auths[name];
|
auth = auths[name];
|
||||||
|
|
||||||
if (auth.type === 'apiKey') {
|
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);
|
el.append(authEl);
|
||||||
} else if (auth.type === 'basic' && el.find('.basic_auth_container').length === 0) {
|
} else if (auth.type === 'basic' && el.find('.basic_auth_container').length === 0) {
|
||||||
authEl = new SwaggerUi.Views.BasicAuthButton({model: auth, router: this.router}).render().el;
|
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) {
|
logoutClick: function (e) {
|
||||||
var authsModel;
|
var authsModel;
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
authsModel = {
|
authsModel = {
|
||||||
title: 'Logout authorizations'
|
title: 'Logout authorizations',
|
||||||
|
content: this.renderAuths(this.getAuthMap())
|
||||||
};
|
};
|
||||||
|
|
||||||
this.popup = new SwaggerUi.Views.PopupView({model: authsModel});
|
this.popup = new SwaggerUi.Views.PopupView({model: authsModel});
|
||||||
this.popup.render();
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ SwaggerUi.Views.BasicAuthButton = Backbone.View.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
'submit .key_input_container' : 'applyPassword'
|
'submit .key_input_container' : 'applyPassword',
|
||||||
|
'click .auth_logout__button' : 'clickLogout'
|
||||||
},
|
},
|
||||||
|
|
||||||
applyPassword: function(event) {
|
applyPassword: function(event) {
|
||||||
@@ -27,6 +28,11 @@ SwaggerUi.Views.BasicAuthButton = Backbone.View.extend({
|
|||||||
var basicAuth = new SwaggerClient.PasswordAuthorization('basic', username, password);
|
var basicAuth = new SwaggerClient.PasswordAuthorization('basic', username, password);
|
||||||
this.router.api.clientAuthorizations.add(this.model.type, basicAuth);
|
this.router.api.clientAuthorizations.add(this.model.type, basicAuth);
|
||||||
this.router.load();
|
this.router.load();
|
||||||
|
},
|
||||||
|
|
||||||
|
clickLogout: function () {
|
||||||
|
window.swaggerUi.api.clientAuthorizations.remove(this.model.name);
|
||||||
|
this.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -12,7 +12,7 @@ SwaggerUi.Views.HeaderView = Backbone.View.extend({
|
|||||||
|
|
||||||
showPetStore: function(){
|
showPetStore: function(){
|
||||||
this.trigger('update-swagger-ui', {
|
this.trigger('update-swagger-ui', {
|
||||||
url:'http://petstore.swagger.io/v2/swagger.json'
|
url:'http://localhost:3001/swagger.json'
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@
|
|||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.auth_submit__button {
|
.auth_submit__button, .auth_logout__button {
|
||||||
color: #547f00;
|
color: #547f00;
|
||||||
border: none;
|
border: none;
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
@@ -58,6 +58,7 @@
|
|||||||
padding-left: 0;
|
padding-left: 0;
|
||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.key_input_container {
|
.key_input_container {
|
||||||
|
|||||||
@@ -4,8 +4,16 @@
|
|||||||
<div>
|
<div>
|
||||||
<span class='auth_label'><label for='input_apiKey_entry'><span>Api key</span> in {{in}}</label></span>
|
<span class='auth_label'><label for='input_apiKey_entry'><span>Api key</span> in {{in}}</label></span>
|
||||||
<span class='auth_in'><label for='input_apiKey_entry'>{{name}} =</label></span>
|
<span class='auth_in'><label for='input_apiKey_entry'>{{name}} =</label></span>
|
||||||
<input placeholder='api_key' class='auth_input input_apiKey_entry' name='apiKey' type='text'/>
|
{{#if isLogout}}
|
||||||
|
<span class="auth_label">{{value}}</span>
|
||||||
|
{{else}}
|
||||||
|
<input placeholder='api_key' class='auth_input input_apiKey_entry' name='apiKey' type='text'/>
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
<div class='auth_submit'><a class='auth_submit_button' href='#' data-sw-translate>apply</a></div>
|
{{#if isLogout}}
|
||||||
|
<input type="button" class="auth_logout__button" value="logout"></div>
|
||||||
|
{{else}}
|
||||||
|
<div class='auth_submit'><a class='auth_submit_button' href='#' data-sw-translate>apply</a></div>
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
<div class='auth_container basic_auth_container'>
|
<div class='auth_container basic_auth_container'>
|
||||||
|
|
||||||
<h3 class="basic_auth__title">Basic authentication</h3>
|
<h3 class="basic_auth__title">Basic authentication</h3>
|
||||||
|
{{#if isLogout}}
|
||||||
|
<input type="button" class="auth_logout__button" value="logout"></div>
|
||||||
|
{{else}}
|
||||||
<form class="key_input_container">
|
<form class="key_input_container">
|
||||||
<div class="auth__description">{{description}}</div>
|
<div class="auth__description">{{description}}</div>
|
||||||
<div class="auth_label"><label data-sw-translate>username</label></div>
|
<div class="auth_label"><label data-sw-translate>username</label></div>
|
||||||
@@ -8,5 +12,6 @@
|
|||||||
<input required placeholder="password" class="basic_auth__password auth_input" name="password" type="password"/>
|
<input required placeholder="password" class="basic_auth__password auth_input" name="password" type="password"/>
|
||||||
<div class='auth_submit'><input type="submit" class="auth_submit__button" value="apply"></div>
|
<div class='auth_submit'><input type="submit" class="auth_submit__button" value="apply"></div>
|
||||||
</form>
|
</form>
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user