Read token name using function

This commit is contained in:
Moses Palmér
2016-12-29 08:39:40 +01:00
parent 2ba1c100ae
commit fd3eb4f65a

View File

@@ -122,6 +122,17 @@ function handleLogin() {
//(needs to be aware of schemes to do so correctly) //(needs to be aware of schemes to do so correctly)
window.enabledScopes=scopes; window.enabledScopes=scopes;
/**
* Returns the name of the access token parameter returned by the server.
*
* @param dets
* The authorisation scheme configuration.
* @return the name of the access token parameter
*/
function getTokenName(dets) {
return dets.tokenName;
}
for (var key in authSchemes) { for (var key in authSchemes) {
if (authSchemes.hasOwnProperty(key) && OAuthSchemeKeys.indexOf(key) != -1) { //only look at keys that match this scope. if (authSchemes.hasOwnProperty(key) && OAuthSchemeKeys.indexOf(key) != -1) { //only look at keys that match this scope.
var flow = authSchemes[key].flow; var flow = authSchemes[key].flow;
@@ -129,13 +140,13 @@ function handleLogin() {
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 = getTokenName(dets) || 'access_token';
window.swaggerUi.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null); window.swaggerUi.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
state = key; state = key;
} }
else if(authSchemes[key].type === 'oauth2' && flow && (flow === 'application')) { else if(authSchemes[key].type === 'oauth2' && flow && (flow === 'application')) {
var dets = authSchemes[key]; var dets = authSchemes[key];
window.swaggerUi.tokenName = dets.tokenName || 'access_token'; window.swaggerUi.tokenName = getTokenName(dets) || 'access_token';
clientCredentialsFlow(scopes, dets.tokenUrl, key); clientCredentialsFlow(scopes, dets.tokenUrl, key);
return; return;
} }
@@ -147,13 +158,13 @@ function handleLogin() {
var dets = o[t]; var dets = o[t];
var ep = dets.loginEndpoint.url; var ep = dets.loginEndpoint.url;
url = dets.loginEndpoint.url + '?response_type=token'; url = dets.loginEndpoint.url + '?response_type=token';
window.swaggerUi.tokenName = dets.tokenName; window.swaggerUi.tokenName = getTokenName(dets);
} }
else if (o.hasOwnProperty(t) && t === 'accessCode') { else if (o.hasOwnProperty(t) && t === 'accessCode') {
var dets = o[t]; var dets = o[t];
var ep = dets.tokenRequestEndpoint.url; var ep = dets.tokenRequestEndpoint.url;
url = dets.tokenRequestEndpoint.url + '?response_type=code'; url = dets.tokenRequestEndpoint.url + '?response_type=code';
window.swaggerUi.tokenName = dets.tokenName; window.swaggerUi.tokenName = getTokenName(dets);
} }
} }
} }