Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions dist/lib/swagger-oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var additionalQueryStringParams;
function handleLogin() {
var scopes = [];

var auths = window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions;
var auths = window.swaggerUiAuth.authSchemes || window.swaggerUiAuth.securityDefinitions;
if(auths) {
var key;
var defs = auths;
Expand All @@ -36,8 +36,7 @@ function handleLogin() {
}
}

if(window.swaggerUi.api
&& window.swaggerUi.api.info) {
if(window.swaggerUi.api && window.swaggerUi.api.info) {
appName = window.swaggerUi.api.info.title;
}

Expand Down Expand Up @@ -285,7 +284,7 @@ window.processOAuthCode = function processOAuthCode(data) {
});
};

window.onOAuthComplete = function onOAuthComplete(token,OAuthSchemeKey) {
window.onOAuthComplete = function onOAuthComplete(token, OAuthSchemeKey) {
if(token) {
if(token.error) {
var checkbox = $('input[type=checkbox],.secured')
Expand All @@ -295,7 +294,7 @@ window.onOAuthComplete = function onOAuthComplete(token,OAuthSchemeKey) {
alert(token.error);
}
else {
var b = token[window.swaggerUi.tokenName];
var b = token[window.swaggerUiAuth.tokenName];
if (!OAuthSchemeKey){
OAuthSchemeKey = token.state;
}
Expand Down Expand Up @@ -339,8 +338,10 @@ window.onOAuthComplete = function onOAuthComplete(token,OAuthSchemeKey) {
}
}
});
window.swaggerUi.api.clientAuthorizations.add(window.OAuthSchemeKey, new SwaggerClient.ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
window.swaggerUi.load();
if(typeof window.swaggerUi !== 'undefined') {
window.swaggerUi.api.clientAuthorizations.add(window.swaggerUiAuth.OAuthSchemeKey, new SwaggerClient.ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
window.swaggerUi.load();
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/o2c.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
return key===""?value:decodeURIComponent(value) }
):{}

if (window.opener.swaggerUi.tokenUrl)
if (window.opener.swaggerUiAuth.tokenUrl)
window.opener.processOAuthCode(qp);
else
window.opener.onOAuthComplete(qp);
Expand Down
31 changes: 18 additions & 13 deletions dist/swagger-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -21935,8 +21935,8 @@ window.SwaggerUi.utils = {};
'use strict';

window.SwaggerUi.utils = {
parseSecurityDefinitions: function (security) {
var auths = Object.assign({}, window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions);
parseSecurityDefinitions: function (security, securityDefinitions) {
var auths = Object.assign({}, securityDefinitions);
var oauth2Arr = [];
var authsArr = [];
var scopes = [];
Expand Down Expand Up @@ -22216,7 +22216,11 @@ SwaggerUi.Collections.AuthsCollection = Backbone.Collection.extend({
},

parse: function (data) {
var authz = Object.assign({}, window.swaggerUi.api.clientAuthorizations.authz);
var authz = {};

if(typeof window.swaggerUi !== 'undefined') {
authz = Object.assign({}, window.swaggerUi.api.clientAuthorizations.authz);
}

return _.map(data, function (auth, name) {
var isBasic = authz[name] && auth.type === 'basic' && authz[name].username && authz[name].password;
Expand Down Expand Up @@ -22395,23 +22399,24 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
var scopes = _.map(auth.get('scopes'), function (scope) {
return scope.scope;
});
var container = window.swaggerUiAuth || (window.swaggerUiAuth = {});
var state, dets, ep;
window.OAuthSchemeKey = auth.get('title');
container.OAuthSchemeKey = auth.get('title');

window.enabledScopes = scopes;
var flow = auth.get('flow');

if(auth.get('type') === 'oauth2' && flow && (flow === 'implicit' || flow === 'accessCode')) {
dets = auth.attributes;
url = dets.authorizationUrl + '?response_type=' + (flow === 'implicit' ? 'token' : 'code');
window.swaggerUi.tokenName = dets.tokenName || 'access_token';
window.swaggerUi.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
state = window.OAuthSchemeKey;
container.tokenName = dets.tokenName || 'access_token';
container.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
state = container.OAuthSchemeKey;
}
else if(auth.get('type') === 'oauth2' && flow && (flow === 'application')) {
dets = auth.attributes;
window.swaggerUi.tokenName = dets.tokenName || 'access_token';
this.clientCredentialsFlow(scopes, dets.tokenUrl, window.OAuthSchemeKey);
container.tokenName = dets.tokenName || 'access_token';
this.clientCredentialsFlow(scopes, dets.tokenUrl, container.OAuthSchemeKey);
return;
}
else if(auth.get('grantTypes')) {
Expand All @@ -22422,13 +22427,13 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
dets = o[t];
ep = dets.loginEndpoint.url;
url = dets.loginEndpoint.url + '?response_type=token';
window.swaggerUi.tokenName = dets.tokenName;
container.tokenName = dets.tokenName;
}
else if (o.hasOwnProperty(t) && t === 'accessCode') {
dets = o[t];
ep = dets.tokenRequestEndpoint.url;
url = dets.tokenRequestEndpoint.url + '?response_type=code';
window.swaggerUi.tokenName = dets.tokenName;
container.tokenName = dets.tokenName;
}
}
}
Expand Down Expand Up @@ -23075,9 +23080,9 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
}

if (Array.isArray(this.model.security)) {
var authsModel = SwaggerUi.utils.parseSecurityDefinitions(this.model.security);
var authsModel = SwaggerUi.utils.parseSecurityDefinitions(this.model.security, this.model.parent.securityDefinitions);

authsModel.isLogout = !_.isEmpty(window.swaggerUi.api.clientAuthorizations.authz);
authsModel.isLogout = !_.isEmpty(this.model.clientAuthorizations.authz);
this.authView = new SwaggerUi.Views.AuthButtonView({
data: authsModel,
router: this.router,
Expand Down
4 changes: 2 additions & 2 deletions dist/swagger-ui.min.js

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions lib/swagger-oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var additionalQueryStringParams;
function handleLogin() {
var scopes = [];

var auths = window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions;
var auths = window.swaggerUiAuth.authSchemes || window.swaggerUiAuth.securityDefinitions;
if(auths) {
var key;
var defs = auths;
Expand All @@ -36,8 +36,7 @@ function handleLogin() {
}
}

if(window.swaggerUi.api
&& window.swaggerUi.api.info) {
if(window.swaggerUi.api && window.swaggerUi.api.info) {
appName = window.swaggerUi.api.info.title;
}

Expand Down Expand Up @@ -285,7 +284,7 @@ window.processOAuthCode = function processOAuthCode(data) {
});
};

window.onOAuthComplete = function onOAuthComplete(token,OAuthSchemeKey) {
window.onOAuthComplete = function onOAuthComplete(token, OAuthSchemeKey) {
if(token) {
if(token.error) {
var checkbox = $('input[type=checkbox],.secured')
Expand All @@ -295,7 +294,7 @@ window.onOAuthComplete = function onOAuthComplete(token,OAuthSchemeKey) {
alert(token.error);
}
else {
var b = token[window.swaggerUi.tokenName];
var b = token[window.swaggerUiAuth.tokenName];
if (!OAuthSchemeKey){
OAuthSchemeKey = token.state;
}
Expand Down Expand Up @@ -339,8 +338,10 @@ window.onOAuthComplete = function onOAuthComplete(token,OAuthSchemeKey) {
}
}
});
window.swaggerUi.api.clientAuthorizations.add(window.OAuthSchemeKey, new SwaggerClient.ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
window.swaggerUi.load();
if(typeof window.swaggerUi !== 'undefined') {
window.swaggerUi.api.clientAuthorizations.add(window.swaggerUiAuth.OAuthSchemeKey, new SwaggerClient.ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
window.swaggerUi.load();
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/html/o2c.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
return key===""?value:decodeURIComponent(value) }
):{}

if (window.opener.swaggerUi.tokenUrl)
if (window.opener.swaggerUiAuth.tokenUrl)
window.opener.processOAuthCode(qp);
else
window.opener.onOAuthComplete(qp);
Expand Down
4 changes: 2 additions & 2 deletions src/main/javascript/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

window.SwaggerUi.utils = {
parseSecurityDefinitions: function (security) {
var auths = Object.assign({}, window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions);
parseSecurityDefinitions: function (security, securityDefinitions) {
var auths = Object.assign({}, securityDefinitions);
var oauth2Arr = [];
var authsArr = [];
var scopes = [];
Expand Down
17 changes: 9 additions & 8 deletions src/main/javascript/view/AuthView.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,24 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
var scopes = _.map(auth.get('scopes'), function (scope) {
return scope.scope;
});
var container = window.swaggerUiAuth || (window.swaggerUiAuth = {});
var state, dets, ep;
window.OAuthSchemeKey = auth.get('title');
container.OAuthSchemeKey = auth.get('title');

window.enabledScopes = scopes;
var flow = auth.get('flow');

if(auth.get('type') === 'oauth2' && flow && (flow === 'implicit' || flow === 'accessCode')) {
dets = auth.attributes;
url = dets.authorizationUrl + '?response_type=' + (flow === 'implicit' ? 'token' : 'code');
window.swaggerUi.tokenName = dets.tokenName || 'access_token';
window.swaggerUi.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
state = window.OAuthSchemeKey;
container.tokenName = dets.tokenName || 'access_token';
container.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
state = container.OAuthSchemeKey;
}
else if(auth.get('type') === 'oauth2' && flow && (flow === 'application')) {
dets = auth.attributes;
window.swaggerUi.tokenName = dets.tokenName || 'access_token';
this.clientCredentialsFlow(scopes, dets.tokenUrl, window.OAuthSchemeKey);
container.tokenName = dets.tokenName || 'access_token';
this.clientCredentialsFlow(scopes, dets.tokenUrl, container.OAuthSchemeKey);
return;
}
else if(auth.get('grantTypes')) {
Expand All @@ -127,13 +128,13 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
dets = o[t];
ep = dets.loginEndpoint.url;
url = dets.loginEndpoint.url + '?response_type=token';
window.swaggerUi.tokenName = dets.tokenName;
container.tokenName = dets.tokenName;
}
else if (o.hasOwnProperty(t) && t === 'accessCode') {
dets = o[t];
ep = dets.tokenRequestEndpoint.url;
url = dets.tokenRequestEndpoint.url + '?response_type=code';
window.swaggerUi.tokenName = dets.tokenName;
container.tokenName = dets.tokenName;
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/javascript/view/AuthsCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ SwaggerUi.Collections.AuthsCollection = Backbone.Collection.extend({
},

parse: function (data) {
var authz = Object.assign({}, window.swaggerUi.api.clientAuthorizations.authz);
var authz = {};

if(typeof window.swaggerUi !== 'undefined') {
authz = Object.assign({}, window.swaggerUi.api.clientAuthorizations.authz);
}

return _.map(data, function (auth, name) {
var isBasic = authz[name] && auth.type === 'basic' && authz[name].username && authz[name].password;
Expand Down
4 changes: 2 additions & 2 deletions src/main/javascript/view/OperationView.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
}

if (Array.isArray(this.model.security)) {
var authsModel = SwaggerUi.utils.parseSecurityDefinitions(this.model.security);
var authsModel = SwaggerUi.utils.parseSecurityDefinitions(this.model.security, this.model.parent.securityDefinitions);

authsModel.isLogout = !_.isEmpty(window.swaggerUi.api.clientAuthorizations.authz);
authsModel.isLogout = !_.isEmpty(this.model.clientAuthorizations.authz);
this.authView = new SwaggerUi.Views.AuthButtonView({
data: authsModel,
router: this.router,
Expand Down