Hi,
Unfortunately "out of the box" the BoxConnector does not contain a JWT connection. We managed to implement our custom connections using the Box Java API. Here is a sample helper class that might get you going:
package boxconnectorcustom.actions.custom;
import com.box.sdk.*;
import com.eclipsesource.json.JsonObject;
import com.mendix.core.Core;
import com.mendix.systemwideinterfaces.core.IContext;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Date;
import static java.lang.Math.toIntExact;
/**
* Created by skruger on 10/6/2017.
*
*/
public class BoxConnectionHelper {
private static final String APPLICATION_SETTINGSFILENAME_CONSTANT = "BoxConnectorCustom.BoxAPI_Application_SettingsFileName";
public static final String APPLICATION_SETTINGSFILE = "/boxconnectorcustom/"+(String)Core.getConfiguration().getConstantValue(APPLICATION_SETTINGSFILENAME_CONSTANT);
public static BoxDeveloperEditionAPIConnection getBoxAppEnterpriseConnection(JsonObject appSettings, JWTEncryptionPreferences encryptionPref, IAccessTokenCache accessTokenCache) {
BoxDeveloperEditionAPIConnection connection = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(
appSettings.get("enterpriseID").asString(),
appSettings.get("boxAppSettings").asObject().get("clientID").asString(),
appSettings.get("boxAppSettings").asObject().get("clientSecret").asString(),
encryptionPref,accessTokenCache);
return connection;
}
public static BoxDeveloperEditionAPIConnection getBoxAppUserConnection(String userId, JsonObject appSettings, JWTEncryptionPreferences encryptionPref, IAccessTokenCache accessTokenCache) {
BoxDeveloperEditionAPIConnection connection = BoxDeveloperEditionAPIConnection.getAppUserConnection(
userId,
appSettings.get("boxAppSettings").asObject().get("clientID").asString(),
appSettings.get("boxAppSettings").asObject().get("clientSecret").asString(),
encryptionPref,accessTokenCache);
return connection;
}
public static JWTEncryptionPreferences getEncryptionPref(JsonObject appSettings){
JWTEncryptionPreferences encryptionPref = new JWTEncryptionPreferences();
encryptionPref.setPublicKeyID(appSettings.get("boxAppSettings").asObject()
.get("appAuth").asObject()
.get("publicKeyID").asString() );
encryptionPref.setPrivateKey(appSettings.get("boxAppSettings").asObject()
.get("appAuth").asObject()
.get("privateKey").asString() );
encryptionPref.setPrivateKeyPassword(appSettings.get("boxAppSettings").asObject()
.get("appAuth").asObject()
.get("passphrase").asString());
encryptionPref.setEncryptionAlgorithm(EncryptionAlgorithm.RSA_SHA_256);
return encryptionPref;
}
public static boxconnectorcustom.proxies.BoxAccessTokenCustom initialiseBoxAccessToken(BoxDeveloperEditionAPIConnection connection,DeveloperEditionEntityType connectionType) {
IContext context = Core.createSystemContext();
boxconnectorcustom.proxies.BoxAccessTokenCustom boxAccessToken = new boxconnectorcustom.proxies.BoxAccessTokenCustom(context);
boxAccessToken.settoken(connection.getAccessToken());
boxAccessToken.setrefreshToken(connection.getRefreshToken());
boxAccessToken.settokenType(connectionType.toString());
boxAccessToken.setexpiresIn(toIntExact(connection.getExpires()));
boxAccessToken.setExpireDate(new Date(connection.getLastRefresh() + connection.getExpires()));
boxAccessToken.setLastRefreshDate(new Date(connection.getLastRefresh()));
boxAccessToken.setUserAgent(connection.getUserAgent());
return boxAccessToken;
}
public static IAccessTokenCache getAccessTokenCacheSingleton() {
return TokenCacheSingleton.getInstance().getAccessTokenCache();
}
public static JsonObject readApplicationSettingsFromJSONFile() throws FileNotFoundException {
JsonObject applicationSettings;
try {
applicationSettings = JsonObject.readFrom(new FileReader(Core.getConfiguration().getResourcesPath()+APPLICATION_SETTINGSFILE));
} catch (IOException e) {
Core.getLogger("BoxConnectorCustom").error("Error occurred while reading Box application settings file: "+APPLICATION_SETTINGSFILE);
return null;
};
return applicationSettings;
}
}
You can get a connection as from a Java action:
// BEGIN USER CODE
Core.getLogger("BoxConnectorCustom").debug("Begin GetBoxEnterpriseConnection");
Core.getLogger("BoxConnectorCustom").debug("Reading Box application settings from json file:" + BoxConnectionHelper.APPLICATION_SETTINGSFILE);
JsonObject appSettings = BoxConnectionHelper.readApplicationSettingsFromJSONFile();
Core.getLogger("BoxConnectorCustom").debug("Encrypting RSA...");
JWTEncryptionPreferences encryptionPref = BoxConnectionHelper.getEncryptionPref(appSettings);
IAccessTokenCache accessTokenCache = BoxConnectionHelper.getAccessTokenCacheSingleton();
Core.getLogger("BoxConnectorCustom").debug("Establshing Box enterprise connection.");
BoxDeveloperEditionAPIConnection connection = BoxConnectionHelper.getBoxAppEnterpriseConnection(appSettings,encryptionPref,accessTokenCache);
Core.getLogger("BoxConnectorCustom").debug("Refreshing token if needed.");
if (connection.canRefresh() && connection.needsRefresh()) {
connection.refresh();
}
Core.getLogger("BoxConnectorCustom").debug("Creating BoxAPIConnection Object from connection...");
boxconnectorcustom.proxies.BoxAccessTokenCustom result = BoxConnectionHelper.initialiseBoxAccessToken(connection, DeveloperEditionEntityType.ENTERPRISE);
//result.setConnectionType(ConnectionType.Enterprise);
Core.getLogger("BoxConnectorCustom").debug("Connection successful.");
Core.getLogger("BoxConnectorCustom").debug("Connection details: "+connection.save());
return result.getMendixObject();
Have you looked at the Box connector in the appstore? You can find it here: https://appstore.home.mendix.com/link/app/40977/Mendix/Box-Connector
It provides server to server integration. The connector has a set of Java actions to enable you to access Box from your Mendix app.
To add to Mikes answer, here is the link to the github. It has more more detailed instructions for setup.
https://github.com/mendix/BoxConnector/blob/master/documentation/prerequisite-box-setup.md
Hi,
I went through the documentation and blog. The screen shots are pretty old and not matching with what I see in BOX now.
Also, the configuration setup is not talking about JWT Server-server authentication. Could you please share some more details on how I can configure.
I am not sure how to configure BOX connector with these details.
Regards.
I setup a project in box for JWT and got json file with following details.
{
"boxAppSettings": {
"clientID": "",
"clientSecret": "",
"appAuth": {
"publicKeyID": "",
"privateKey": "-----BEGIN ENCRYPTED PRIVATE KEY-----Some content here...\n-----END ENCRYPTED PRIVATE KEY-----\n",
"passphrase": ""
}
},
"enterpriseID": ""
}