public void authenticate ( String authCode ) { URL url = null ; try { url = new URL ( this . tokenURL ) ; } catch ( MalformedURLException e ) { assert false : "An invalid token URL indicates a bug in the SDK." ; throw new RuntimeException ( "An invalid token URL indicates a bug in the SDK." , e ) ; } String urlParameters = String . format ( "grant_type=authorization_code&code=%s&client_id=%s&client_secret=%s" , authCode , this . clientID , this . clientSecret ) ; BoxAPIRequest request = new BoxAPIRequest ( this , url , "POST" ) ; request . shouldAuthenticate ( false ) ; request . setBody ( urlParameters ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; String json = response . getJSON ( ) ; JsonObject jsonObject = JsonObject . readFrom ( json ) ; this . accessToken = jsonObject . get ( "access_token" ) . asString ( ) ; this . refreshToken = jsonObject . get ( "refresh_token" ) . asString ( ) ; this . lastRefresh = System . currentTimeMillis ( ) ; this . expires = jsonObject . get ( "expires_in" ) . asLong ( ) * 1000 ; }
Authenticates the API connection by obtaining access and refresh tokens using the auth code that was obtained from the first half of OAuth .