I am implementing Box API; I want to let external user select their existing files and then want to download those files in my application.
For that I have enterprise Application and I am using JWT Authorization.
I am able to generate Access Token using this code:
JWTEncryptionPreferences jwtPreferences = new JWTEncryptionPreferences();
jwtPreferences.setPublicKeyID("xxxx");
jwtPreferences.setPrivateKeyPassword("xxx");
jwtPreferences.setPrivateKey("-----BEGIN ENCRYPTED PRIVATE KEY-----\nxxxxxx\n-----END ENCRYPTED PRIVATE KEY-----\n");
jwtPreferences.setEncryptionAlgorithm(EncryptionAlgorithm.RSA_SHA_256);
BoxConfig boxConfig = new BoxConfig("xxxx", "xxxx", "xxx", jwtPreferences);
try {
BoxDeveloperEditionAPIConnection api = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(boxConfig);
LOG.info("token --" + api.getAccessToken());
return api;
} catch (BoxAPIException e) {
}
Then I am sending this token to the front end and Opening the Content Picker using that token. Code is same as below link
https://developer.box.com/docs/box-content-picker#section-sample-html
Now I am able to open picker just like the demo. But it is specific to one account. I want to implement the same for External Users of Box.
Is this possible?
What I am missing here?
Okay. I found solution for this. Posting this if it can help anyone.
I found that picking JWT
for existing app user is not a good choice.
So I have to choose OAuth2
for authenticating external users
From doc:
When to Use Choose OAuth 2 as your authentication method if:
- You are only working with users that have existing Box accounts.