Merge pull request #983 from mohsen1/CatLabInteractive-master

Cat lab interactive master
This commit is contained in:
Tony Tam
2015-03-02 10:25:49 -08:00
2 changed files with 20 additions and 12 deletions

View File

@@ -103,12 +103,12 @@ function handleLogin() {
for (var key in authSchemes) { for (var key in authSchemes) {
if (authSchemes.hasOwnProperty(key)) { if (authSchemes.hasOwnProperty(key)) {
var flow = authSchemes[key].flow; var flow = authSchemes[key].flow;
if(authSchemes[key].type === 'oauth2' && flow && (flow === 'implicit' || flow === 'accessCode')) { if(authSchemes[key].type === 'oauth2' && flow && (flow === 'implicit' || flow === 'accessCode')) {
var dets = authSchemes[key]; var dets = authSchemes[key];
url = dets.authorizationUrl + '?response_type=' + (flow === 'implicit' ? 'token' : 'code'); url = dets.authorizationUrl + '?response_type=' + (flow === 'implicit' ? 'token' : 'code');
window.swaggerUi.tokenName = dets.tokenName || 'access_token'; window.swaggerUi.tokenName = dets.tokenName || 'access_token';
window.swaggerUi.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null); window.swaggerUi.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
} }
else if(authSchemes[key].grantTypes) { else if(authSchemes[key].grantTypes) {
// 1.2 support // 1.2 support
@@ -135,11 +135,14 @@ function handleLogin() {
for(k =0; k < o.length; k++) { for(k =0; k < o.length; k++) {
var scope = $(o[k]).attr('scope'); var scope = $(o[k]).attr('scope');
if (scopes.indexOf(scope) === -1) if (scopes.indexOf(scope) === -1)
scopes.push(scope); scopes.push(scope);
} }
// Implicit auth recommends a state parameter.
var state = Math.random ();
window.enabledScopes=scopes; window.enabledScopes=scopes;
redirect_uri = redirectUrl; redirect_uri = redirectUrl;
@@ -148,6 +151,7 @@ function handleLogin() {
url += '&realm=' + encodeURIComponent(realm); url += '&realm=' + encodeURIComponent(realm);
url += '&client_id=' + encodeURIComponent(clientId); url += '&client_id=' + encodeURIComponent(clientId);
url += '&scope=' + encodeURIComponent(scopes.join(' ')); url += '&scope=' + encodeURIComponent(scopes.join(' '));
url += '&state=' + encodeURIComponent(state);
window.open(url); window.open(url);
}); });
@@ -210,11 +214,11 @@ function processOAuthCode(data) {
url : window.swaggerUi.tokenUrl, url : window.swaggerUi.tokenUrl,
type: "POST", type: "POST",
data: params, data: params,
success:function(data, textStatus, jqXHR) success:function(data, textStatus, jqXHR)
{ {
onOAuthComplete(data); onOAuthComplete(data);
}, },
error: function(jqXHR, textStatus, errorThrown) error: function(jqXHR, textStatus, errorThrown)
{ {
onOAuthComplete(""); onOAuthComplete("");
} }
@@ -268,7 +272,7 @@ function onOAuthComplete(token) {
// all scopes are satisfied // all scopes are satisfied
$(o).find('.api-ic').addClass('ic-info'); $(o).find('.api-ic').addClass('ic-info');
$(o).find('.api-ic').removeClass('ic-warning'); $(o).find('.api-ic').removeClass('ic-warning');
$(o).find('.api-ic').removeClass('ic-error'); $(o).find('.api-ic').removeClass('ic-error');
} }
} }
}); });

View File

@@ -103,12 +103,12 @@ function handleLogin() {
for (var key in authSchemes) { for (var key in authSchemes) {
if (authSchemes.hasOwnProperty(key)) { if (authSchemes.hasOwnProperty(key)) {
var flow = authSchemes[key].flow; var flow = authSchemes[key].flow;
if(authSchemes[key].type === 'oauth2' && flow && (flow === 'implicit' || flow === 'accessCode')) { if(authSchemes[key].type === 'oauth2' && flow && (flow === 'implicit' || flow === 'accessCode')) {
var dets = authSchemes[key]; var dets = authSchemes[key];
url = dets.authorizationUrl + '?response_type=' + (flow === 'implicit' ? 'token' : 'code'); url = dets.authorizationUrl + '?response_type=' + (flow === 'implicit' ? 'token' : 'code');
window.swaggerUi.tokenName = dets.tokenName || 'access_token'; window.swaggerUi.tokenName = dets.tokenName || 'access_token';
window.swaggerUi.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null); window.swaggerUi.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
} }
else if(authSchemes[key].grantTypes) { else if(authSchemes[key].grantTypes) {
// 1.2 support // 1.2 support
@@ -135,11 +135,14 @@ function handleLogin() {
for(k =0; k < o.length; k++) { for(k =0; k < o.length; k++) {
var scope = $(o[k]).attr('scope'); var scope = $(o[k]).attr('scope');
if (scopes.indexOf(scope) === -1) if (scopes.indexOf(scope) === -1)
scopes.push(scope); scopes.push(scope);
} }
// Implicit auth recommends a state parameter.
var state = Math.random ();
window.enabledScopes=scopes; window.enabledScopes=scopes;
redirect_uri = redirectUrl; redirect_uri = redirectUrl;
@@ -148,6 +151,7 @@ function handleLogin() {
url += '&realm=' + encodeURIComponent(realm); url += '&realm=' + encodeURIComponent(realm);
url += '&client_id=' + encodeURIComponent(clientId); url += '&client_id=' + encodeURIComponent(clientId);
url += '&scope=' + encodeURIComponent(scopes.join(' ')); url += '&scope=' + encodeURIComponent(scopes.join(' '));
url += '&state=' + encodeURIComponent(state);
window.open(url); window.open(url);
}); });
@@ -210,11 +214,11 @@ function processOAuthCode(data) {
url : window.swaggerUi.tokenUrl, url : window.swaggerUi.tokenUrl,
type: "POST", type: "POST",
data: params, data: params,
success:function(data, textStatus, jqXHR) success:function(data, textStatus, jqXHR)
{ {
onOAuthComplete(data); onOAuthComplete(data);
}, },
error: function(jqXHR, textStatus, errorThrown) error: function(jqXHR, textStatus, errorThrown)
{ {
onOAuthComplete(""); onOAuthComplete("");
} }
@@ -268,7 +272,7 @@ function onOAuthComplete(token) {
// all scopes are satisfied // all scopes are satisfied
$(o).find('.api-ic').addClass('ic-info'); $(o).find('.api-ic').addClass('ic-info');
$(o).find('.api-ic').removeClass('ic-warning'); $(o).find('.api-ic').removeClass('ic-warning');
$(o).find('.api-ic').removeClass('ic-error'); $(o).find('.api-ic').removeClass('ic-error');
} }
} }
}); });