Level up your Box knowledge with brand new learning paths on Box University. Visit training.box.com to get started

how to set private key and passphrase for JWT assertion using BOX JAVA SDK

Answered
New post

Comments

5 comments

  • LoCortes

    Hello ,

     

    you are using the BoxConfig and the BoxDeveloperEditionAPIConnection I understand

     

    - https://github.com/box/box-java-sdk/blob/master/src/main/java/com/box/sdk/BoxConfig.java

    - https://github.com/box/box-java-sdk/blob/master/src/main/java/com/box/sdk/BoxDeveloperEditionAPIConnection.java

     

    So, based on this example, everything should be working with needing extra effort.

    https://github.com/box/box-java-sdk/blob/master/src/example/java/com/box/sdk/example/AccessAsAppUser.java

     

    Have you tried this approach?

     

    Thanks

    0
    Comment actions Permalink
  • aclark1

    Hi ,

     

    First off, thank you for your reply!  

     

    In the example it is using user based authentication however, I am using enterprise based authentication (.getAppEnterpriseConnection(...) vs getAppUserConnection(...)).

     

    I was successful in at least getting the token to work by simply taking the Box provided private key and passphrase (generated for me when I created the public/private key pair in box dev console) and putting them both in the JWTEncryptionPreferences setPrivateKey() and setPrivateKeyPassword methods.

     

    What made the difference was using the entire private key verbatim as it is provided from box no alterations and also I noticed I was getting an illegal key size error which was rectified by installing the following libraries: unlimitedJCEPolicy (the correct one for your JDK) and adding that to my classpath AS WELL as these particular jars which came with the slf4j-1.7.25 library:

    • slf4j-jdk14-7.25.jar
    • slf4j-ext.1.7.25.jar
    • slf4j-api-1.7.25.jar
    • osgi-over-slf4j-1.7.25.jar
    • log4j-over-slf4j-1.7.25.jar
    • jul-to-slf4j-1.7.25.jar
    • jcl-over-slf4j-1.7.25.jar

    I am now successfully getting an access token however when trying to create a folder I am getting a 404.  I "believe" i need to create an app user and get a user specific access token to perform this action so I will try that.  If all I want to do however is create files and folders I'm wondering if I shouldn't just skip the enterprise access altogether and go with a user based authentication but I've seen conflicting info that states I should be using the former.

     

     

    0
    Comment actions Permalink
  • LoCortes

    Hello!

    the 404 error is probably because you are trying to create the folder into another folder where you don't have access to.

    You can create appusers or use the same service account. Remember that those users behave as any other user... they do not have access to everything so they have to be invited to collaborate also.

    Thanks

    0
    Comment actions Permalink
  • aclark1

    Thanks again , I meant to reply to this thread yesterday.  Fortunately I was able to get it to work and I believe the symptom was exactly as you said.

     

    I had to use the access token to create a user and then invite the user to collaborate on a particular folder and lastly user the getAppuserToken method using the previously created user as the argument (as well as the accesstoken) and then I was able to successfully perform user actions such as creating folders, uploading files, creating metadata etc.

     

    Thanks for all the help!

    0
    Comment actions Permalink
  • LoCortes

    Glad it work!

     

    A pleasure 😉

    0
    Comment actions Permalink

Please sign in to leave a comment.