From 5fa84ff5705de2b00e00528efe74a48fd9a49ab1 Mon Sep 17 00:00:00 2001 From: Eran Stiller Date: Sun, 4 Oct 2015 11:37:12 +0300 Subject: [PATCH] Add easy option to specify additional query parameters during the OAuth2 authorization process --- dist/index.html | 3 ++- dist/lib/swagger-oauth.js | 5 +++++ lib/swagger-oauth.js | 5 +++++ src/main/html/index.html | 3 ++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/dist/index.html b/dist/index.html index 3e47f2b8..d2577335 100644 --- a/dist/index.html +++ b/dist/index.html @@ -51,7 +51,8 @@ clientSecret: "your-client-secret", realm: "your-realms", appName: "your-app-name", - scopeSeparator: "," + scopeSeparator: ",", + additionalQueryStringParams: {} }); } diff --git a/dist/lib/swagger-oauth.js b/dist/lib/swagger-oauth.js index 3bb1c277..9a1030ac 100644 --- a/dist/lib/swagger-oauth.js +++ b/dist/lib/swagger-oauth.js @@ -7,6 +7,7 @@ var oauth2KeyName; var redirect_uri; var clientSecret; var scopeSeparator; +var additionalQueryStringParams; function handleLogin() { var scopes = []; @@ -156,6 +157,9 @@ function handleLogin() { url += '&client_id=' + encodeURIComponent(clientId); url += '&scope=' + encodeURIComponent(scopes.join(scopeSeparator)); url += '&state=' + encodeURIComponent(state); + for (var key in additionalQueryStringParams) { + url += '&' + key + '=' + encodeURIComponent(additionalQueryStringParams[key]); + } window.open(url); }); @@ -190,6 +194,7 @@ function initOAuth(opts) { clientSecret = (o.clientSecret||errors.push('missing client secret')); realm = (o.realm||errors.push('missing realm')); scopeSeparator = (o.scopeSeparator||' '); + additionalQueryStringParams = (o.additionalQueryStringParams||{}); if(errors.length > 0){ log('auth unable initialize oauth: ' + errors); diff --git a/lib/swagger-oauth.js b/lib/swagger-oauth.js index 3bb1c277..9a1030ac 100644 --- a/lib/swagger-oauth.js +++ b/lib/swagger-oauth.js @@ -7,6 +7,7 @@ var oauth2KeyName; var redirect_uri; var clientSecret; var scopeSeparator; +var additionalQueryStringParams; function handleLogin() { var scopes = []; @@ -156,6 +157,9 @@ function handleLogin() { url += '&client_id=' + encodeURIComponent(clientId); url += '&scope=' + encodeURIComponent(scopes.join(scopeSeparator)); url += '&state=' + encodeURIComponent(state); + for (var key in additionalQueryStringParams) { + url += '&' + key + '=' + encodeURIComponent(additionalQueryStringParams[key]); + } window.open(url); }); @@ -190,6 +194,7 @@ function initOAuth(opts) { clientSecret = (o.clientSecret||errors.push('missing client secret')); realm = (o.realm||errors.push('missing realm')); scopeSeparator = (o.scopeSeparator||' '); + additionalQueryStringParams = (o.additionalQueryStringParams||{}); if(errors.length > 0){ log('auth unable initialize oauth: ' + errors); diff --git a/src/main/html/index.html b/src/main/html/index.html index 3e47f2b8..d2577335 100644 --- a/src/main/html/index.html +++ b/src/main/html/index.html @@ -51,7 +51,8 @@ clientSecret: "your-client-secret", realm: "your-realms", appName: "your-app-name", - scopeSeparator: "," + scopeSeparator: ",", + additionalQueryStringParams: {} }); }