From a4c5aa59517ef410329b5308c6d229d96feb773f Mon Sep 17 00:00:00 2001 From: dilanua Date: Fri, 29 Jul 2016 15:15:02 +0530 Subject: [PATCH] Refactoring OAuth utilities at UI Layer --- .../devicemgt/app/modules/token-handlers.js | 9 +++++---- .../jaggeryapps/devicemgt/app/modules/util.js | 12 +++++------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/token-handlers.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/token-handlers.js index 8883cd6eed6..4aa17fb54ba 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/token-handlers.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/token-handlers.js @@ -38,13 +38,13 @@ var handlers = function () { "client credentials to session context. No username is found as " + "input - setUpEncodedTenantBasedClientCredentials(x)"); } else { - var dynamicClientCredentials = tokenUtil.getDynamicClientAppCredentials(); - if (!dynamicClientCredentials) { + var dynamicClientAppCredentials = tokenUtil.getDynamicClientAppCredentials(); + if (!dynamicClientAppCredentials) { throw new Error("{/app/modules/token-handlers.js} Could not set up encoded tenant based " + "client credentials to session context as the server is unable to obtain " + "dynamic client credentials - setUpEncodedTenantBasedClientCredentials(x)"); } else { - var jwtToken = tokenUtil.getAccessTokenByJWTGrantType(dynamicClientCredentials); + var jwtToken = tokenUtil.getAccessTokenByJWTGrantType(dynamicClientAppCredentials); if (!jwtToken) { throw new Error("{/app/modules/token-handlers.js} Could not set up encoded tenant based " + "client credentials to session context as the server is unable to obtain " + @@ -141,7 +141,8 @@ var handlers = function () { "token pair, encoded client credentials or both input are not found under " + "session context - refreshToken()"); } else { - var newAccessTokenPair = tokenUtil.refreshToken(accessTokenPair["refreshToken"], encodedClientCredentials); + var newAccessTokenPair = tokenUtil. + getNewAccessTokenByRefreshToken(accessTokenPair["refreshToken"], encodedClientCredentials); if (!newAccessTokenPair) { log.error("{/app/modules/token-handlers.js} Error in refreshing tokens. Unable to update " + "session context with new access token pair - refreshToken()"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/util.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/util.js index f9b6bb77b7a..2236c44dddb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/util.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/util.js @@ -24,10 +24,8 @@ var util = function () { var Base64 = Packages.org.apache.commons.codec.binary.Base64; var String = Packages.java.lang.String; - var deviceMgtProps = require("/app/conf/reader/main.js")["conf"]; - - var adminUser = deviceMgtProps["adminUser"]; + var deviceMgtProps = require("/app/conf/reader/main.js")["conf"]; var constants = require("/app/modules/constants.js"); var carbon = require("carbon"); @@ -225,7 +223,7 @@ var util = function () { "username - getTenantBasedClientAppCredentials(x, y)"); return null; } else { - var cachedTenantBasedClientAppCredentials = publicMethods. + var cachedTenantBasedClientAppCredentials = privateMethods. getCachedTenantBasedClientAppCredentials(tenantDomain); if (cachedTenantBasedClientAppCredentials) { return cachedTenantBasedClientAppCredentials; @@ -247,7 +245,7 @@ var util = function () { var tenantBasedClientAppCredentials = {}; tenantBasedClientAppCredentials["clientId"] = responsePayload["client_id"]; tenantBasedClientAppCredentials["clientSecret"] = responsePayload["client_secret"]; - publicMethods. + privateMethods. setCachedTenantBasedClientAppCredentials(tenantDomain, tenantBasedClientAppCredentials); return tenantBasedClientAppCredentials; } else { @@ -260,7 +258,7 @@ var util = function () { } }; - publicMethods.setCachedTenantBasedClientAppCredentials = function (tenantDomain, clientCredentials) { + privateMethods.setCachedTenantBasedClientAppCredentials = function (tenantDomain, clientCredentials) { var cachedTenantBasedClientAppCredentialsMap = application.get(constants["CACHED_CREDENTIALS"]); if (!cachedTenantBasedClientAppCredentialsMap) { cachedTenantBasedClientAppCredentialsMap = {}; @@ -271,7 +269,7 @@ var util = function () { } }; - publicMethods.getCachedTenantBasedClientAppCredentials = function (tenantDomain) { + privateMethods.getCachedTenantBasedClientAppCredentials = function (tenantDomain) { var cachedTenantBasedClientAppCredentialsMap = application.get(constants["CACHED_CREDENTIALS"]); if (!cachedTenantBasedClientAppCredentialsMap || !cachedTenantBasedClientAppCredentialsMap[tenantDomain]) {