|
|
@ -28,6 +28,7 @@ var handlers = function () {
|
|
|
|
var tokenUtil = require("/app/modules/oauth/token-handler-utils.js")["utils"];
|
|
|
|
var tokenUtil = require("/app/modules/oauth/token-handler-utils.js")["utils"];
|
|
|
|
var constants = require("/app/modules/constants.js");
|
|
|
|
var constants = require("/app/modules/constants.js");
|
|
|
|
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
|
|
|
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
|
|
|
|
|
|
|
var utility = require("/app/modules/utility.js")["utility"];
|
|
|
|
|
|
|
|
|
|
|
|
var publicMethods = {};
|
|
|
|
var publicMethods = {};
|
|
|
|
var privateMethods = {};
|
|
|
|
var privateMethods = {};
|
|
|
@ -49,6 +50,7 @@ var handlers = function () {
|
|
|
|
var tokenData;
|
|
|
|
var tokenData;
|
|
|
|
// tokenPair will include current access token as well as current refresh token
|
|
|
|
// tokenPair will include current access token as well as current refresh token
|
|
|
|
var arrayOfScopes = devicemgtProps["scopes"];
|
|
|
|
var arrayOfScopes = devicemgtProps["scopes"];
|
|
|
|
|
|
|
|
arrayOfScopes = arrayOfScopes.concat(utility.getDeviceTypesScopesList());
|
|
|
|
var stringOfScopes = "";
|
|
|
|
var stringOfScopes = "";
|
|
|
|
arrayOfScopes.forEach(function (entry) {
|
|
|
|
arrayOfScopes.forEach(function (entry) {
|
|
|
|
stringOfScopes += entry + " ";
|
|
|
|
stringOfScopes += entry + " ";
|
|
|
@ -78,19 +80,20 @@ var handlers = function () {
|
|
|
|
publicMethods["setupTokenPairBySamlGrantType"] = function (username, samlToken) {
|
|
|
|
publicMethods["setupTokenPairBySamlGrantType"] = function (username, samlToken) {
|
|
|
|
if (!username || !samlToken) {
|
|
|
|
if (!username || !samlToken) {
|
|
|
|
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up access token pair by " +
|
|
|
|
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up access token pair by " +
|
|
|
|
"saml grant type. Either username of logged in user, samlToken or both are missing " +
|
|
|
|
"saml grant type. Either username of logged in user, samlToken or both are missing " +
|
|
|
|
"as input - setupTokenPairByPasswordGrantType(x, y)");
|
|
|
|
"as input - setupTokenPairBySamlGrantType(x, y)");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
privateMethods.setUpEncodedTenantBasedClientAppCredentials(username);
|
|
|
|
privateMethods.setUpEncodedTenantBasedClientAppCredentials(username);
|
|
|
|
privateMethods.setUpEncodedTenantBasedWebSocketClientAppCredentials(username);
|
|
|
|
privateMethods.setUpEncodedTenantBasedWebSocketClientAppCredentials(username);
|
|
|
|
var encodedClientAppCredentials = session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS"]);
|
|
|
|
var encodedClientAppCredentials = session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS"]);
|
|
|
|
if (!encodedClientAppCredentials) {
|
|
|
|
if (!encodedClientAppCredentials) {
|
|
|
|
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up access token pair " +
|
|
|
|
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up access token pair " +
|
|
|
|
"by saml grant type. Encoded client credentials are " +
|
|
|
|
"by saml grant type. Encoded client credentials are " +
|
|
|
|
"missing - setupTokenPairByPasswordGrantType(x, y)");
|
|
|
|
"missing - setupTokenPairBySamlGrantType(x, y)");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
var tokenData;
|
|
|
|
var tokenData;
|
|
|
|
var arrayOfScopes = devicemgtProps["scopes"];
|
|
|
|
var arrayOfScopes = devicemgtProps["scopes"];
|
|
|
|
|
|
|
|
arrayOfScopes = arrayOfScopes.concat(utility.getDeviceTypesScopesList());
|
|
|
|
var stringOfScopes = "";
|
|
|
|
var stringOfScopes = "";
|
|
|
|
arrayOfScopes.forEach(function (entry) {
|
|
|
|
arrayOfScopes.forEach(function (entry) {
|
|
|
|
stringOfScopes += entry + " ";
|
|
|
|
stringOfScopes += entry + " ";
|
|
|
@ -98,11 +101,11 @@ var handlers = function () {
|
|
|
|
|
|
|
|
|
|
|
|
// accessTokenPair will include current access token as well as current refresh token
|
|
|
|
// accessTokenPair will include current access token as well as current refresh token
|
|
|
|
tokenData = tokenUtil.
|
|
|
|
tokenData = tokenUtil.
|
|
|
|
getTokenPairAndScopesBySAMLGrantType(samlToken, encodedClientAppCredentials, stringOfScopes);
|
|
|
|
getTokenPairAndScopesBySAMLGrantType(samlToken, encodedClientAppCredentials, stringOfScopes);
|
|
|
|
if (!tokenData) {
|
|
|
|
if (!tokenData) {
|
|
|
|
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up token " +
|
|
|
|
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up token " +
|
|
|
|
"pair by password grant type. Error in token " +
|
|
|
|
"pair by password grant type. Error in token " +
|
|
|
|
"retrieval - setupTokenPairByPasswordGrantType(x, y)");
|
|
|
|
"retrieval - setupTokenPairBySamlGrantType(x, y)");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
var tokenPair = {};
|
|
|
|
var tokenPair = {};
|
|
|
|
tokenPair["accessToken"] = tokenData["accessToken"];
|
|
|
|
tokenPair["accessToken"] = tokenData["accessToken"];
|
|
|
|