mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Refactoring OAuth utilities at UI Layer
This commit is contained in:
parent
f7509f698d
commit
a4c5aa5951
@ -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()");
|
||||
|
||||
@ -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 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]) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user