merged into swagger-js
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* swagger-client - swagger.js is a javascript client for use with swaggering APIs.
|
||||
* @version v2.1.0-alpha.6
|
||||
* @version v2.1.0-alpha.7
|
||||
* @link http://swagger.io
|
||||
* @license apache 2.0
|
||||
*/
|
||||
@@ -74,12 +74,12 @@ SwaggerAuthorizations.prototype.remove = function(name) {
|
||||
return delete this.authz[name];
|
||||
};
|
||||
|
||||
SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
|
||||
SwaggerAuthorizations.prototype.apply = function (obj, authorizations) {
|
||||
var status = null;
|
||||
var key;
|
||||
var key, value, result;
|
||||
|
||||
// if the "authorizations" key is undefined, or has an empty array, add all keys
|
||||
if(typeof authorizations === 'undefined' || Object.keys(authorizations).length === 0) {
|
||||
if (typeof authorizations === 'undefined' || Object.keys(authorizations).length == 0) {
|
||||
for (key in this.authz) {
|
||||
value = this.authz[key];
|
||||
result = value.apply(obj, authorizations);
|
||||
@@ -88,13 +88,28 @@ SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(Array.isArray(authorizations)) {
|
||||
var i;
|
||||
for(i = 0; i < authorizations.length; i++) {
|
||||
// 2.0 support
|
||||
if (Array.isArray(authorizations)) {
|
||||
for (var i = 0; i < authorizations.length; i++) {
|
||||
var auth = authorizations[i];
|
||||
for (name in auth) {
|
||||
for (key in this.authz) {
|
||||
if (key == name) {
|
||||
value = this.authz[key];
|
||||
result = value.apply(obj, authorizations);
|
||||
if (result === true)
|
||||
status = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 1.2 support
|
||||
for (name in authorizations) {
|
||||
for (key in this.authz) {
|
||||
var value = this.authz[key];
|
||||
if(typeof value !== 'undefined') {
|
||||
if (key == name) {
|
||||
value = this.authz[key];
|
||||
result = value.apply(obj, authorizations);
|
||||
if (result === true)
|
||||
status = true;
|
||||
|
||||
@@ -3,6 +3,7 @@ var popupMask;
|
||||
var popupDialog;
|
||||
var clientId;
|
||||
var realm;
|
||||
var oauth2KeyName;
|
||||
|
||||
function handleLogin() {
|
||||
var scopes = [];
|
||||
@@ -14,6 +15,7 @@ function handleLogin() {
|
||||
for(key in defs) {
|
||||
var auth = defs[key];
|
||||
if(auth.type === 'oauth2' && auth.scopes) {
|
||||
oauth2KeyName = key;
|
||||
var scope;
|
||||
if(Array.isArray(auth.scopes)) {
|
||||
// 1.2 support
|
||||
@@ -86,6 +88,7 @@ function handleLogin() {
|
||||
popupDialog = [];
|
||||
});
|
||||
|
||||
$('button.api-popup-authbtn').unbind();
|
||||
popupDialog.find('button.api-popup-authbtn').click(function() {
|
||||
popupMask.hide();
|
||||
popupDialog.hide();
|
||||
@@ -98,10 +101,13 @@ function handleLogin() {
|
||||
|
||||
for (var key in authSchemes) {
|
||||
if (authSchemes.hasOwnProperty(key)) {
|
||||
if(authSchemes[key].type === 'oauth2' && authSchemes[key].flow === 'implicit') {
|
||||
var flow = authSchemes[key].flow;
|
||||
|
||||
if(authSchemes[key].type === 'oauth2' && flow && (flow === 'implicit' || flow === 'accessCode')) {
|
||||
var dets = authSchemes[key];
|
||||
url = dets.authorizationUrl + '?response_type=token';
|
||||
window.swaggerUi.tokenName = dets.tokenUrl || 'access_token';
|
||||
url = dets.authorizationUrl + '?response_type=' + (flow === 'implicit' ? 'token' : 'code');
|
||||
window.swaggerUi.tokenName = dets.tokenName || 'access_token';
|
||||
window.swaggerUi.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
|
||||
}
|
||||
else if(authSchemes[key].grantTypes) {
|
||||
// 1.2 support
|
||||
@@ -113,6 +119,12 @@ function handleLogin() {
|
||||
url = dets.loginEndpoint.url + '?response_type=token';
|
||||
window.swaggerUi.tokenName = dets.tokenName;
|
||||
}
|
||||
else if (o.hasOwnProperty(t) && t === 'accessCode') {
|
||||
var dets = o[t];
|
||||
var ep = dets.tokenRequestEndpoint.url;
|
||||
url = dets.tokenRequestEndpoint.url + '?response_type=code';
|
||||
window.swaggerUi.tokenName = dets.tokenName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,7 +133,10 @@ function handleLogin() {
|
||||
var o = $('.api-popup-scopes').find('input:checked');
|
||||
|
||||
for(k =0; k < o.length; k++) {
|
||||
scopes.push($(o[k]).attr('scope'));
|
||||
var scope = $(o[k]).attr('scope');
|
||||
|
||||
if (scopes.indexOf(scope) === -1)
|
||||
scopes.push(scope);
|
||||
}
|
||||
|
||||
window.enabledScopes=scopes;
|
||||
@@ -169,6 +184,7 @@ function initOAuth(opts) {
|
||||
}
|
||||
|
||||
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
|
||||
$('.api-ic').unbind();
|
||||
$('.api-ic').click(function(s) {
|
||||
if($(s.target).hasClass('ic-off'))
|
||||
handleLogin();
|
||||
@@ -179,6 +195,28 @@ function initOAuth(opts) {
|
||||
});
|
||||
}
|
||||
|
||||
function processOAuthCode(data) {
|
||||
var params = {
|
||||
'client_id': clientId,
|
||||
'code': data.code,
|
||||
'grant_type': 'authorization_code'
|
||||
}
|
||||
$.ajax(
|
||||
{
|
||||
url : window.swaggerUi.tokenUrl,
|
||||
type: "POST",
|
||||
data: params,
|
||||
success:function(data, textStatus, jqXHR)
|
||||
{
|
||||
onOAuthComplete(data);
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown)
|
||||
{
|
||||
onOAuthComplete("");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function onOAuthComplete(token) {
|
||||
if(token) {
|
||||
if(token.error) {
|
||||
@@ -230,7 +268,7 @@ function onOAuthComplete(token) {
|
||||
}
|
||||
}
|
||||
});
|
||||
window.authorizations.add('oauth2', new ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
|
||||
window.authorizations.add(oauth2KeyName, new ApiKeyAuthorization('Authorization', 'Bearer ' + b, 'header'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user