Join BoxWorks in San Francisco Nov 12-13! Keynotes, product demos, and Box Master Classes. Reserve your spot!

Java SDK JWT authentication

New post

Comments

3 comments

  • kendomen

    If you get your managed user like this:

     

    BoxDeveloperEditionAPIConnection userApi = BoxDeveloperEditionAPIConnection.getAppUserConnection("userid", CLIENT_ID, CLIENT_SECRET, encryptionPref, accessTokenCache);
    
    

    that should work.

     

    Here's the entire example:

    https://github.com/kendomen/BoxJavaJWTExamples/blob/master/src/com/nike/box/UploadFileAsEnterpriseAdmin.java

    0
    Comment actions Permalink
  • narendraN

    Thank you for your reply ...

     

    I replaced Enterprise id with userID  got below exception

     

    BoxDeveloperEditionAPIConnection userApi = BoxDeveloperEditionAPIConnection.getAppUserConnection("userid","fthdms9f0s89nwfvsl4uamikeu7txh20", "3wUzMT7cjWktvEmlcddzSSLpUFmcteWl", encryption, accessTokenCache);

     

    {invalid_grant","error_description":"Please check the 'exp' claim."} , i found solution  to

    update the Unix time on your machine to match the Unix time  ,

    but i am using windows machine. how can i set this unix time or set 'exp' claim programatically  ?

     

    Any help is greatly appreciated..

     

    0
    Comment actions Permalink
  • kendomen

    That's in box-java-sdk in class BoxDeveloperEditionApiConnection

     

    private String constructJWTAssertion() {
            JwtClaims claims = new JwtClaims();
            claims.setIssuer(this.getClientID());
            claims.setAudience(JWT_AUDIENCE);
            claims.setExpirationTimeMinutesInTheFuture(1.0f);
            claims.setSubject(this.entityID);
            claims.setClaim("box_sub_type", this.entityType.toString());
            claims.setGeneratedJwtId(64);
    
            JsonWebSignature jws = new JsonWebSignature();
            jws.setPayload(claims.toJson());
            jws.setKey(this.decryptPrivateKey());
            jws.setAlgorithmHeaderValue(this.getAlgorithmIdentifier());
            jws.setHeader("typ", "JWT");

     

    0
    Comment actions Permalink

Please sign in to leave a comment.