Quellcode durchsuchen

merged from auth_2.0 branch

bubble
Tony Tam vor 10 Jahren
Ursprung
Commit
329772af4c
11 geänderte Dateien mit 170 neuen und 357 gelöschten Zeilen
  1. +0
    -79
      dist/css/screen.css
  2. +3
    -0
      dist/lib/swagger-client.js
  3. +73
    -47
      dist/lib/swagger-oauth.js
  4. +17
    -11
      dist/lib/swagger.js
  5. +0
    -1
      dist/swagger-ui.js
  6. +1
    -1
      dist/swagger-ui.min.js
  7. +3
    -0
      lib/swagger-client.js
  8. +73
    -47
      lib/swagger-oauth.js
  9. +0
    -1
      src/main/coffeescript/view/OperationView.coffee
  10. +0
    -79
      src/main/html/css/screen.css
  11. +0
    -91
      src/main/less/auth.less

+ 0
- 79
dist/css/screen.css Datei anzeigen

@@ -1100,85 +1100,6 @@
.swagger-section .api-popup-actions {
padding-top: 10px;
}
.auth {
text-align: right;
height: 15px;
float: right;
clear: both;
display: inline-block;
position: relative;
z-index: 3;
}
.auth_icon {
float: right;
}
.auth_container_2 {
visibility: visible;
position: absolute;
width: 250px;
margin-top: 26px;
float: left;
display: none;
border: solid 2px;
background: white;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
-o-border-radius: 4px;
-ms-border-radius: 4px;
-khtml-border-radius: 4px;
z-index: 2;
}
.auth_label {
text-align: left;
clear: left;
float: left;
padding-left: 10px;
width: 90px;
}
.auth_submit {
border-left: 1px;
border-right: 1px;
margin-top: 25px;
margin-bottom: 25px;
text-align: center;
}
.auth_button {
display: block;
float: right;
text-align: right;
}
.auth_submit_button {
display: block;
text-decoration: none;
font-weight: bold;
padding: 6px 8px;
font-size: 0.9em;
color: white;
float: right;
text-align: center;
background: #547f00;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
-o-border-radius: 4px;
-ms-border-radius: 4px;
-khtml-border-radius: 4px;
margin-top: 10px;
margin-bottom: 10px;
margin-right: 10px;
}
.auth_input {
float: left;
}
.authentication_container {
float: left;
display: block;
background: yellow;
}
.auth_button .auth_icon {
width: 25px;
height: 25px;
cursor: pointer;
}
.swagger-section .access {
float: right;
}


+ 3
- 0
dist/lib/swagger-client.js Datei anzeigen

@@ -389,6 +389,9 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
this.produces = response.produces;
this.securityDefinitions = response.securityDefinitions;

// legacy support
this.authSchemes = response.securityDefinitions;

var location = this.parseUri(this.url);
if(typeof this.schemes === 'undefined' || this.schemes.length === 0) {
this.scheme = location.scheme;


+ 73
- 47
dist/lib/swagger-oauth.js Datei anzeigen

@@ -7,10 +7,29 @@ var realm;
function handleLogin() {
var scopes = [];

if(window.swaggerUi.api.authSchemes
&& window.swaggerUi.api.authSchemes.oauth2
&& window.swaggerUi.api.authSchemes.oauth2.scopes) {
scopes = window.swaggerUi.api.authSchemes.oauth2.scopes;
var auths = window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions;
if(auths) {
var key;
var defs = auths;
for(key in defs) {
var auth = defs[key];
if(auth.type === 'oauth2' && auth.scopes) {
var scope;
if(Array.isArray(auth.scopes)) {
// 1.2 support
var i;
for(i = 0; i < auth.scopes.length; i++) {
scopes.push(auth.scopes[i]);
}
}
else {
// 2.0 support
for(scope in auth.scopes) {
scopes.push({scope: scope, description: auth.scopes[scope]});
}
}
}
}
}

if(window.swaggerUi.api
@@ -18,36 +37,32 @@ function handleLogin() {
appName = window.swaggerUi.api.info.title;
}

if(popupDialog.length > 0)
popupDialog = popupDialog.last();
else {
popupDialog = $(
[
'<div class="api-popup-dialog">',
'<div class="api-popup-title">Select OAuth2.0 Scopes</div>',
'<div class="api-popup-content">',
'<p>Scopes are used to grant an application different levels of access to data on behalf of the end user. Each API may declare one or more scopes.',
'<a href="#">Learn how to use</a>',
'</p>',
'<p><strong>' + appName + '</strong> API requires the following scopes. Select which ones you want to grant to Swagger UI.</p>',
'<ul class="api-popup-scopes">',
'</ul>',
'<p class="error-msg"></p>',
'<div class="api-popup-actions"><button class="api-popup-authbtn api-button green" type="button">Authorize</button><button class="api-popup-cancel api-button gray" type="button">Cancel</button></div>',
'</div>',
'</div>'].join(''));
$(document.body).append(popupDialog);

popup = popupDialog.find('ul.api-popup-scopes').empty();
for (i = 0; i < scopes.length; i ++) {
scope = scopes[i];
str = '<li><input type="checkbox" id="scope_' + i + '" scope="' + scope.scope + '"/>' + '<label for="scope_' + i + '">' + scope.scope;
if (scope.description) {
str += '<br/><span class="api-scope-desc">' + scope.description + '</span>';
}
str += '</label></li>';
popup.append(str);
popupDialog = $(
[
'<div class="api-popup-dialog">',
'<div class="api-popup-title">Select OAuth2.0 Scopes</div>',
'<div class="api-popup-content">',
'<p>Scopes are used to grant an application different levels of access to data on behalf of the end user. Each API may declare one or more scopes.',
'<a href="#">Learn how to use</a>',
'</p>',
'<p><strong>' + appName + '</strong> API requires the following scopes. Select which ones you want to grant to Swagger UI.</p>',
'<ul class="api-popup-scopes">',
'</ul>',
'<p class="error-msg"></p>',
'<div class="api-popup-actions"><button class="api-popup-authbtn api-button green" type="button">Authorize</button><button class="api-popup-cancel api-button gray" type="button">Cancel</button></div>',
'</div>',
'</div>'].join(''));
$(document.body).append(popupDialog);

popup = popupDialog.find('ul.api-popup-scopes').empty();
for (i = 0; i < scopes.length; i ++) {
scope = scopes[i];
str = '<li><input type="checkbox" id="scope_' + i + '" scope="' + scope.scope + '"/>' + '<label for="scope_' + i + '">' + scope.scope;
if (scope.description) {
str += '<br/><span class="api-scope-desc">' + scope.description + '</span>';
}
str += '</label></li>';
popup.append(str);
}

var $win = $(window),
@@ -67,7 +82,10 @@ function handleLogin() {
popupDialog.find('button.api-popup-cancel').click(function() {
popupMask.hide();
popupDialog.hide();
popupDialog.empty();
popupDialog = [];
});

popupDialog.find('button.api-popup-authbtn').click(function() {
popupMask.hide();
popupDialog.hide();
@@ -75,17 +93,26 @@ function handleLogin() {
var authSchemes = window.swaggerUi.api.authSchemes;
var host = window.location;
var pathname = location.pathname.substring(0, location.pathname.lastIndexOf("/"));
var redirectUrl = host.protocol + '//' + host.host + pathname + "/o2c.html";
var redirectUrl = host.protocol + '//' + host.host + pathname + '/o2c.html';
var url = null;

for (var key in authSchemes) {
if (authSchemes.hasOwnProperty(key)) {
var o = authSchemes[key].grantTypes;
for(var t in o) {
if(o.hasOwnProperty(t) && t === 'implicit') {
var dets = o[t];
url = dets.loginEndpoint.url + "?response_type=token";
window.swaggerUi.tokenName = dets.tokenName;
if(authSchemes[key].type === 'oauth2' && authSchemes[key].flow === 'implicit') {
var dets = authSchemes[key];
url = dets.authorizationUrl + '?response_type=token';
window.swaggerUi.tokenName = dets.tokenUrl || 'access_token';
}
else if(authSchemes[key].grantTypes) {
// 1.2 support
var o = authSchemes[key].grantTypes;
for(var t in o) {
if(o.hasOwnProperty(t) && t === 'implicit') {
var dets = o[t];
var ep = dets.loginEndpoint.url;
url = dets.loginEndpoint.url + '?response_type=token';
window.swaggerUi.tokenName = dets.tokenName;
}
}
}
}
@@ -94,7 +121,7 @@ function handleLogin() {
var o = $('.api-popup-scopes').find('input:checked');

for(k =0; k < o.length; k++) {
scopes.push($(o[k]).attr("scope"));
scopes.push($(o[k]).attr('scope'));
}

window.enabledScopes=scopes;
@@ -130,14 +157,14 @@ function initOAuth(opts) {
var o = (opts||{});
var errors = [];

appName = (o.appName||errors.push("missing appName"));
appName = (o.appName||errors.push('missing appName'));
popupMask = (o.popupMask||$('#api-common-mask'));
popupDialog = (o.popupDialog||$('.api-popup-dialog'));
clientId = (o.clientId||errors.push("missing client id"));
realm = (o.realm||errors.push("missing realm"));
clientId = (o.clientId||errors.push('missing client id'));
realm = (o.realm||errors.push('missing realm'));

if(errors.length > 0){
log("auth unable initialize oauth: " + errors);
log('auth unable initialize oauth: ' + errors);
return;
}

@@ -203,8 +230,7 @@ function onOAuthComplete(token) {
}
}
});

window.authorizations.add("oauth2", new ApiKeyAuthorization("Authorization", "Bearer " + b, "header"));
window.authorizations.add('oauth2', new ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
}
}
}

+ 17
- 11
dist/lib/swagger.js Datei anzeigen

@@ -1,5 +1,5 @@
// swagger.js
// version 2.0.41
// version 2.0.42

(function () {

@@ -974,16 +974,22 @@
var queryParams = "";
for (var i = 0; i < params.length; i++) {
var param = params[i];
if (param.paramType === 'query') {
if (args[param.name] !== undefined) {
if (queryParams !== '')
queryParams += "&";
queryParams += encodeURIComponent(param.name) + '=' + encodeURIComponent(args[param.name]);
}
if (queryParams !== '')
queryParams += '&';
if (Array.isArray(param)) {
var j;
var output = '';
for(j = 0; j < param.length; j++) {
if(j > 0)
output += ',';
output += encodeURIComponent(param[j]);
}
queryParams += encodeURIComponent(param.name) + '=' + output;
}
else {
queryParams += encodeURIComponent(param.name) + '=' + encodeURIComponent(args[param.name]);
}
}
if ((queryParams != null) && queryParams.length > 0)
url += '?' + queryParams;
return url;
};

@@ -1477,8 +1483,8 @@
data: response.content.data
};

var contentType = (response._headers["content-type"] || response._headers["Content-Type"] || null)
var headers = response._headers.normalized || response._headers;
var contentType = (headers["content-type"] || headers["Content-Type"] || null)
if (contentType != null) {
if (contentType.indexOf("application/json") == 0 || contentType.indexOf("+json") > 0) {
if (response.content.data && response.content.data !== "")


+ 0
- 1
dist/swagger-ui.js Datei anzeigen

@@ -1782,7 +1782,6 @@ 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;
log(this.model.authorizations);
if (this.model.authorizations) {
if (Array.isArray(this.model.authorizations)) {
_ref5 = this.model.authorizations;


+ 1
- 1
dist/swagger-ui.min.js
Datei-Diff unterdrückt, da er zu groß ist
Datei anzeigen


+ 3
- 0
lib/swagger-client.js Datei anzeigen

@@ -389,6 +389,9 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
this.produces = response.produces;
this.securityDefinitions = response.securityDefinitions;

// legacy support
this.authSchemes = response.securityDefinitions;

var location = this.parseUri(this.url);
if(typeof this.schemes === 'undefined' || this.schemes.length === 0) {
this.scheme = location.scheme;


+ 73
- 47
lib/swagger-oauth.js Datei anzeigen

@@ -7,10 +7,29 @@ var realm;
function handleLogin() {
var scopes = [];

if(window.swaggerUi.api.authSchemes
&& window.swaggerUi.api.authSchemes.oauth2
&& window.swaggerUi.api.authSchemes.oauth2.scopes) {
scopes = window.swaggerUi.api.authSchemes.oauth2.scopes;
var auths = window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions;
if(auths) {
var key;
var defs = auths;
for(key in defs) {
var auth = defs[key];
if(auth.type === 'oauth2' && auth.scopes) {
var scope;
if(Array.isArray(auth.scopes)) {
// 1.2 support
var i;
for(i = 0; i < auth.scopes.length; i++) {
scopes.push(auth.scopes[i]);
}
}
else {
// 2.0 support
for(scope in auth.scopes) {
scopes.push({scope: scope, description: auth.scopes[scope]});
}
}
}
}
}

if(window.swaggerUi.api
@@ -18,36 +37,32 @@ function handleLogin() {
appName = window.swaggerUi.api.info.title;
}

if(popupDialog.length > 0)
popupDialog = popupDialog.last();
else {
popupDialog = $(
[
'<div class="api-popup-dialog">',
'<div class="api-popup-title">Select OAuth2.0 Scopes</div>',
'<div class="api-popup-content">',
'<p>Scopes are used to grant an application different levels of access to data on behalf of the end user. Each API may declare one or more scopes.',
'<a href="#">Learn how to use</a>',
'</p>',
'<p><strong>' + appName + '</strong> API requires the following scopes. Select which ones you want to grant to Swagger UI.</p>',
'<ul class="api-popup-scopes">',
'</ul>',
'<p class="error-msg"></p>',
'<div class="api-popup-actions"><button class="api-popup-authbtn api-button green" type="button">Authorize</button><button class="api-popup-cancel api-button gray" type="button">Cancel</button></div>',
'</div>',
'</div>'].join(''));
$(document.body).append(popupDialog);

popup = popupDialog.find('ul.api-popup-scopes').empty();
for (i = 0; i < scopes.length; i ++) {
scope = scopes[i];
str = '<li><input type="checkbox" id="scope_' + i + '" scope="' + scope.scope + '"/>' + '<label for="scope_' + i + '">' + scope.scope;
if (scope.description) {
str += '<br/><span class="api-scope-desc">' + scope.description + '</span>';
}
str += '</label></li>';
popup.append(str);
popupDialog = $(
[
'<div class="api-popup-dialog">',
'<div class="api-popup-title">Select OAuth2.0 Scopes</div>',
'<div class="api-popup-content">',
'<p>Scopes are used to grant an application different levels of access to data on behalf of the end user. Each API may declare one or more scopes.',
'<a href="#">Learn how to use</a>',
'</p>',
'<p><strong>' + appName + '</strong> API requires the following scopes. Select which ones you want to grant to Swagger UI.</p>',
'<ul class="api-popup-scopes">',
'</ul>',
'<p class="error-msg"></p>',
'<div class="api-popup-actions"><button class="api-popup-authbtn api-button green" type="button">Authorize</button><button class="api-popup-cancel api-button gray" type="button">Cancel</button></div>',
'</div>',
'</div>'].join(''));
$(document.body).append(popupDialog);

popup = popupDialog.find('ul.api-popup-scopes').empty();
for (i = 0; i < scopes.length; i ++) {
scope = scopes[i];
str = '<li><input type="checkbox" id="scope_' + i + '" scope="' + scope.scope + '"/>' + '<label for="scope_' + i + '">' + scope.scope;
if (scope.description) {
str += '<br/><span class="api-scope-desc">' + scope.description + '</span>';
}
str += '</label></li>';
popup.append(str);
}

var $win = $(window),
@@ -67,7 +82,10 @@ function handleLogin() {
popupDialog.find('button.api-popup-cancel').click(function() {
popupMask.hide();
popupDialog.hide();
popupDialog.empty();
popupDialog = [];
});

popupDialog.find('button.api-popup-authbtn').click(function() {
popupMask.hide();
popupDialog.hide();
@@ -75,17 +93,26 @@ function handleLogin() {
var authSchemes = window.swaggerUi.api.authSchemes;
var host = window.location;
var pathname = location.pathname.substring(0, location.pathname.lastIndexOf("/"));
var redirectUrl = host.protocol + '//' + host.host + pathname + "/o2c.html";
var redirectUrl = host.protocol + '//' + host.host + pathname + '/o2c.html';
var url = null;

for (var key in authSchemes) {
if (authSchemes.hasOwnProperty(key)) {
var o = authSchemes[key].grantTypes;
for(var t in o) {
if(o.hasOwnProperty(t) && t === 'implicit') {
var dets = o[t];
url = dets.loginEndpoint.url + "?response_type=token";
window.swaggerUi.tokenName = dets.tokenName;
if(authSchemes[key].type === 'oauth2' && authSchemes[key].flow === 'implicit') {
var dets = authSchemes[key];
url = dets.authorizationUrl + '?response_type=token';
window.swaggerUi.tokenName = dets.tokenUrl || 'access_token';
}
else if(authSchemes[key].grantTypes) {
// 1.2 support
var o = authSchemes[key].grantTypes;
for(var t in o) {
if(o.hasOwnProperty(t) && t === 'implicit') {
var dets = o[t];
var ep = dets.loginEndpoint.url;
url = dets.loginEndpoint.url + '?response_type=token';
window.swaggerUi.tokenName = dets.tokenName;
}
}
}
}
@@ -94,7 +121,7 @@ function handleLogin() {
var o = $('.api-popup-scopes').find('input:checked');

for(k =0; k < o.length; k++) {
scopes.push($(o[k]).attr("scope"));
scopes.push($(o[k]).attr('scope'));
}

window.enabledScopes=scopes;
@@ -130,14 +157,14 @@ function initOAuth(opts) {
var o = (opts||{});
var errors = [];

appName = (o.appName||errors.push("missing appName"));
appName = (o.appName||errors.push('missing appName'));
popupMask = (o.popupMask||$('#api-common-mask'));
popupDialog = (o.popupDialog||$('.api-popup-dialog'));
clientId = (o.clientId||errors.push("missing client id"));
realm = (o.realm||errors.push("missing realm"));
clientId = (o.clientId||errors.push('missing client id'));
realm = (o.realm||errors.push('missing realm'));

if(errors.length > 0){
log("auth unable initialize oauth: " + errors);
log('auth unable initialize oauth: ' + errors);
return;
}

@@ -203,8 +230,7 @@ function onOAuthComplete(token) {
}
}
});

window.authorizations.add("oauth2", new ApiKeyAuthorization("Authorization", "Bearer " + b, "header"));
window.authorizations.add('oauth2', new ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
}
}
}

+ 0
- 1
src/main/coffeescript/view/OperationView.coffee Datei anzeigen

@@ -52,7 +52,6 @@ class OperationView extends Backbone.View
if @model.description
@model.description = @model.description.replace(/(?:\r\n|\r|\n)/g, '<br />')
@model.oauth = null
log @model.authorizations
if @model.authorizations
if Array.isArray @model.authorizations
for auths in @model.authorizations


+ 0
- 79
src/main/html/css/screen.css Datei anzeigen

@@ -1100,85 +1100,6 @@
.swagger-section .api-popup-actions {
padding-top: 10px;
}
.auth {
text-align: right;
height: 15px;
float: right;
clear: both;
display: inline-block;
position: relative;
z-index: 3;
}
.auth_icon {
float: right;
}
.auth_container_2 {
visibility: visible;
position: absolute;
width: 250px;
margin-top: 26px;
float: left;
display: none;
border: solid 2px;
background: white;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
-o-border-radius: 4px;
-ms-border-radius: 4px;
-khtml-border-radius: 4px;
z-index: 2;
}
.auth_label {
text-align: left;
clear: left;
float: left;
padding-left: 10px;
width: 90px;
}
.auth_submit {
border-left: 1px;
border-right: 1px;
margin-top: 25px;
margin-bottom: 25px;
text-align: center;
}
.auth_button {
display: block;
float: right;
text-align: right;
}
.auth_submit_button {
display: block;
text-decoration: none;
font-weight: bold;
padding: 6px 8px;
font-size: 0.9em;
color: white;
float: right;
text-align: center;
background: #547f00;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
-o-border-radius: 4px;
-ms-border-radius: 4px;
-khtml-border-radius: 4px;
margin-top: 10px;
margin-bottom: 10px;
margin-right: 10px;
}
.auth_input {
float: left;
}
.authentication_container {
float: left;
display: block;
background: yellow;
}
.auth_button .auth_icon {
width: 25px;
height: 25px;
cursor: pointer;
}
.swagger-section .access {
float: right;
}


+ 0
- 91
src/main/less/auth.less Datei anzeigen

@@ -81,94 +81,3 @@
}

}

.auth {
text-align: right;
height: 15px;
float: right;
clear: both;
display: inline-block;
position: relative;
z-index: 3;
}

.auth_icon {
float: right;
}

.auth_container_2 {
visibility: visible;
position: absolute;
width: 250px;
float:left;
margin-top: 26px;
float: left;
display: none;
border: solid 2px;
background: white;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
-o-border-radius: 4px;
-ms-border-radius: 4px;
-khtml-border-radius: 4px;

z-index: 2;
}

.auth_label {
text-align: left;
clear: left;
float: left;
padding-left: 10px;
width: 90px;
}

.auth_submit {
border-left: 1px;
border-right: 1px;
margin-top: 25px;
margin-bottom: 25px;
text-align: center;
}

.auth_button {
display: block;
float: right;
text-align: right;
}

.auth_submit_button {
display: block;
text-decoration: none;
font-weight: bold;
padding: 6px 8px;
font-size: 0.9em;
color: white;
float: right;
text-align: center;
background: #547f00;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
-o-border-radius: 4px;
-ms-border-radius: 4px;
-khtml-border-radius: 4px;
margin-top: 10px;
margin-bottom: 10px;
margin-right: 10px;
}

.auth_input {
float: left;
}

.authentication_container {
float: left;
display: block;
background: yellow;
}

.auth_button .auth_icon {
width: 25px;
height: 25px;
cursor: pointer;
}

Laden…
Abbrechen
Speichern