Merge pull request #2587 from moses-palmer/feature-token-as-vendor-property
OAuth2 access token name as vendor property
This commit is contained in:
@@ -122,6 +122,17 @@ function handleLogin() {
|
||||
//(needs to be aware of schemes to do so correctly)
|
||||
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.vendorExtensions['x-tokenName'] || dets.tokenName;
|
||||
}
|
||||
|
||||
for (var key in authSchemes) {
|
||||
if (authSchemes.hasOwnProperty(key) && OAuthSchemeKeys.indexOf(key) != -1) { //only look at keys that match this scope.
|
||||
var flow = authSchemes[key].flow;
|
||||
@@ -129,13 +140,13 @@ function handleLogin() {
|
||||
if(authSchemes[key].type === 'oauth2' && flow && (flow === 'implicit' || flow === 'accessCode')) {
|
||||
var dets = authSchemes[key];
|
||||
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);
|
||||
state = key;
|
||||
}
|
||||
else if(authSchemes[key].type === 'oauth2' && flow && (flow === 'application')) {
|
||||
var dets = authSchemes[key];
|
||||
window.swaggerUi.tokenName = dets.tokenName || 'access_token';
|
||||
window.swaggerUi.tokenName = getTokenName(dets) || 'access_token';
|
||||
clientCredentialsFlow(scopes, dets.tokenUrl, key);
|
||||
return;
|
||||
}
|
||||
@@ -147,13 +158,13 @@ function handleLogin() {
|
||||
var dets = o[t];
|
||||
var ep = dets.loginEndpoint.url;
|
||||
url = dets.loginEndpoint.url + '?response_type=token';
|
||||
window.swaggerUi.tokenName = dets.tokenName;
|
||||
window.swaggerUi.tokenName = getTokenName(dets);
|
||||
}
|
||||
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;
|
||||
window.swaggerUi.tokenName = getTokenName(dets);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,22 +109,33 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
|
||||
window.enabledScopes = scopes;
|
||||
var flow = auth.get('flow');
|
||||
|
||||
/**
|
||||
* 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.vendorExtensions['x-tokenName'] || dets.tokenName;
|
||||
}
|
||||
|
||||
if(auth.get('type') === 'oauth2' && flow && (flow === 'implicit' || flow === 'accessCode')) {
|
||||
dets = auth.attributes;
|
||||
url = dets.authorizationUrl + '?response_type=' + (flow === 'implicit' ? 'token' : 'code');
|
||||
container.tokenName = dets.tokenName || 'access_token';
|
||||
container.tokenName = getTokenName(dets) || 'access_token';
|
||||
container.tokenUrl = (flow === 'accessCode' ? dets.tokenUrl : null);
|
||||
state = container.OAuthSchemeKey;
|
||||
}
|
||||
else if(auth.get('type') === 'oauth2' && flow && (flow === 'application')) {
|
||||
dets = auth.attributes;
|
||||
container.tokenName = dets.tokenName || 'access_token';
|
||||
container.tokenName = getTokenName(dets) || 'access_token';
|
||||
this.clientCredentialsFlow(scopes, dets, container.OAuthSchemeKey);
|
||||
return;
|
||||
}
|
||||
else if(auth.get('type') === 'oauth2' && flow && (flow === 'password')) {
|
||||
dets = auth.attributes;
|
||||
container.tokenName = dets.tokenName || 'access_token';
|
||||
container.tokenName = getTokenName(dets) || 'access_token';
|
||||
this.passwordFlow(scopes, dets, container.OAuthSchemeKey);
|
||||
return;
|
||||
}
|
||||
@@ -136,13 +147,13 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
|
||||
dets = o[t];
|
||||
ep = dets.loginEndpoint.url;
|
||||
url = dets.loginEndpoint.url + '?response_type=token';
|
||||
container.tokenName = dets.tokenName;
|
||||
container.tokenName = getTokenName(dets);
|
||||
}
|
||||
else if (o.hasOwnProperty(t) && t === 'accessCode') {
|
||||
dets = o[t];
|
||||
ep = dets.tokenRequestEndpoint.url;
|
||||
url = dets.tokenRequestEndpoint.url + '?response_type=code';
|
||||
container.tokenName = dets.tokenName;
|
||||
container.tokenName = getTokenName(dets);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user