Merge pull request #1682 from lucian303/oauth-client-secret

Make client secret optional, depending on grant type.
This commit is contained in:
Tony Tam
2015-10-26 16:24:31 -07:00
2 changed files with 9 additions and 5 deletions

View File

@@ -187,7 +187,7 @@ function initOAuth(opts) {
popupMask = (o.popupMask||$('#api-common-mask')); popupMask = (o.popupMask||$('#api-common-mask'));
popupDialog = (o.popupDialog||$('.api-popup-dialog')); popupDialog = (o.popupDialog||$('.api-popup-dialog'));
clientId = (o.clientId||errors.push('missing client id')); clientId = (o.clientId||errors.push('missing client id'));
clientSecret = (o.clientSecret||errors.push('missing client secret')); clientSecret = (o.clientSecret||null);
realm = (o.realm||errors.push('missing realm')); realm = (o.realm||errors.push('missing realm'));
scopeSeparator = (o.scopeSeparator||' '); scopeSeparator = (o.scopeSeparator||' ');
@@ -211,11 +211,15 @@ function initOAuth(opts) {
window.processOAuthCode = function processOAuthCode(data) { window.processOAuthCode = function processOAuthCode(data) {
var params = { var params = {
'client_id': clientId, 'client_id': clientId,
'client_secret': clientSecret,
'code': data.code, 'code': data.code,
'grant_type': 'authorization_code', 'grant_type': 'authorization_code',
'redirect_uri': redirect_uri 'redirect_uri': redirect_uri
};
if (clientSecret) {
params.client_secret = clientSecret;
} }
$.ajax( $.ajax(
{ {
url : window.swaggerUi.tokenUrl, url : window.swaggerUi.tokenUrl,
@@ -230,7 +234,7 @@ window.processOAuthCode = function processOAuthCode(data) {
onOAuthComplete(""); onOAuthComplete("");
} }
}); });
} };
window.onOAuthComplete = function onOAuthComplete(token) { window.onOAuthComplete = function onOAuthComplete(token) {
if(token) { if(token) {
@@ -287,4 +291,4 @@ window.onOAuthComplete = function onOAuthComplete(token) {
} }
} }
} }
} };

View File

@@ -48,7 +48,7 @@
if(typeof initOAuth == "function") { if(typeof initOAuth == "function") {
initOAuth({ initOAuth({
clientId: "your-client-id", clientId: "your-client-id",
clientSecret: "your-client-secret", clientSecret: "your-client-secret-if-required",
realm: "your-realms", realm: "your-realms",
appName: "your-app-name", appName: "your-app-name",
scopeSeparator: "," scopeSeparator: ","