Refactoring OAuth utilities at UI Layer

merge-requests/7/head
dilanua 8 years ago
parent f7509f698d
commit a4c5aa5951

@ -38,13 +38,13 @@ var handlers = function () {
"client credentials to session context. No username is found as " + "client credentials to session context. No username is found as " +
"input - setUpEncodedTenantBasedClientCredentials(x)"); "input - setUpEncodedTenantBasedClientCredentials(x)");
} else { } else {
var dynamicClientCredentials = tokenUtil.getDynamicClientAppCredentials(); var dynamicClientAppCredentials = tokenUtil.getDynamicClientAppCredentials();
if (!dynamicClientCredentials) { if (!dynamicClientAppCredentials) {
throw new Error("{/app/modules/token-handlers.js} Could not set up encoded tenant based " + 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 " + "client credentials to session context as the server is unable to obtain " +
"dynamic client credentials - setUpEncodedTenantBasedClientCredentials(x)"); "dynamic client credentials - setUpEncodedTenantBasedClientCredentials(x)");
} else { } else {
var jwtToken = tokenUtil.getAccessTokenByJWTGrantType(dynamicClientCredentials); var jwtToken = tokenUtil.getAccessTokenByJWTGrantType(dynamicClientAppCredentials);
if (!jwtToken) { if (!jwtToken) {
throw new Error("{/app/modules/token-handlers.js} Could not set up encoded tenant based " + 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 " + "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 " + "token pair, encoded client credentials or both input are not found under " +
"session context - refreshToken()"); "session context - refreshToken()");
} else { } else {
var newAccessTokenPair = tokenUtil.refreshToken(accessTokenPair["refreshToken"], encodedClientCredentials); var newAccessTokenPair = tokenUtil.
getNewAccessTokenByRefreshToken(accessTokenPair["refreshToken"], encodedClientCredentials);
if (!newAccessTokenPair) { if (!newAccessTokenPair) {
log.error("{/app/modules/token-handlers.js} Error in refreshing tokens. Unable to update " + log.error("{/app/modules/token-handlers.js} Error in refreshing tokens. Unable to update " +
"session context with new access token pair - refreshToken()"); "session context with new access token pair - refreshToken()");

@ -24,10 +24,8 @@ var util = function () {
var Base64 = Packages.org.apache.commons.codec.binary.Base64; var Base64 = Packages.org.apache.commons.codec.binary.Base64;
var String = Packages.java.lang.String; 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 constants = require("/app/modules/constants.js");
var carbon = require("carbon"); var carbon = require("carbon");
@ -225,7 +223,7 @@ var util = function () {
"username - getTenantBasedClientAppCredentials(x, y)"); "username - getTenantBasedClientAppCredentials(x, y)");
return null; return null;
} else { } else {
var cachedTenantBasedClientAppCredentials = publicMethods. var cachedTenantBasedClientAppCredentials = privateMethods.
getCachedTenantBasedClientAppCredentials(tenantDomain); getCachedTenantBasedClientAppCredentials(tenantDomain);
if (cachedTenantBasedClientAppCredentials) { if (cachedTenantBasedClientAppCredentials) {
return cachedTenantBasedClientAppCredentials; return cachedTenantBasedClientAppCredentials;
@ -247,7 +245,7 @@ var util = function () {
var tenantBasedClientAppCredentials = {}; var tenantBasedClientAppCredentials = {};
tenantBasedClientAppCredentials["clientId"] = responsePayload["client_id"]; tenantBasedClientAppCredentials["clientId"] = responsePayload["client_id"];
tenantBasedClientAppCredentials["clientSecret"] = responsePayload["client_secret"]; tenantBasedClientAppCredentials["clientSecret"] = responsePayload["client_secret"];
publicMethods. privateMethods.
setCachedTenantBasedClientAppCredentials(tenantDomain, tenantBasedClientAppCredentials); setCachedTenantBasedClientAppCredentials(tenantDomain, tenantBasedClientAppCredentials);
return tenantBasedClientAppCredentials; return tenantBasedClientAppCredentials;
} else { } 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"]); var cachedTenantBasedClientAppCredentialsMap = application.get(constants["CACHED_CREDENTIALS"]);
if (!cachedTenantBasedClientAppCredentialsMap) { if (!cachedTenantBasedClientAppCredentialsMap) {
cachedTenantBasedClientAppCredentialsMap = {}; cachedTenantBasedClientAppCredentialsMap = {};
@ -271,7 +269,7 @@ var util = function () {
} }
}; };
publicMethods.getCachedTenantBasedClientAppCredentials = function (tenantDomain) { privateMethods.getCachedTenantBasedClientAppCredentials = function (tenantDomain) {
var cachedTenantBasedClientAppCredentialsMap = application.get(constants["CACHED_CREDENTIALS"]); var cachedTenantBasedClientAppCredentialsMap = application.get(constants["CACHED_CREDENTIALS"]);
if (!cachedTenantBasedClientAppCredentialsMap || if (!cachedTenantBasedClientAppCredentialsMap ||
!cachedTenantBasedClientAppCredentialsMap[tenantDomain]) { !cachedTenantBasedClientAppCredentialsMap[tenantDomain]) {

Loading…
Cancel
Save