public synchronized FutureTask < BoxAuthenticationInfo > refresh ( BoxSession session ) { BoxUser user = session . getUser ( ) ; if ( user == null ) { return doRefresh ( session , session . getAuthInfo ( ) ) ; } // Fetch auth info map from storage if not present. getAuthInfoMap ( session . getApplicationContext ( ) ) ; BoxAuthenticationInfo info = mCurrentAccessInfo . get ( user . getId ( ) ) ; if ( info == null ) { // session has info that we do not. ? is there any other situation we want to update our info based on session info? we can do checks against // refresh time. mCurrentAccessInfo . put ( user . getId ( ) , session . getAuthInfo ( ) ) ; info = mCurrentAccessInfo . get ( user . getId ( ) ) ; } // No need to refresh if we have already refreshed within 15 seconds or have a newer access token already. if ( session . getAuthInfo ( ) . accessToken ( ) == null || ( ! session . getAuthInfo ( ) . accessToken ( ) . equals ( info . accessToken ( ) ) && info . getRefreshTime ( ) != null && System . currentTimeMillis ( ) - info . getRefreshTime ( ) < 15000 ) ) { final BoxAuthenticationInfo latestInfo = info ; // this session is probably using old information. Give it our information. BoxAuthenticationInfo . cloneInfo ( session . getAuthInfo ( ) , info ) ; FutureTask task = new FutureTask <> ( new Callable < BoxAuthenticationInfo > ( ) { @ Override public BoxAuthenticationInfo call ( ) throws Exception { return latestInfo ; } } ) ; AUTH_EXECUTOR . execute ( task ) ; return task ; } FutureTask task = mRefreshingTasks . get ( user . getId ( ) ) ; if ( task != null && ! ( task . isCancelled ( ) || task . isDone ( ) ) ) { // We already have a refreshing task for this user. No need to do anything. return task ; } // long currentTime = System.currentTimeMillis(); // if ((currentTime - info.refreshTime) > info.refreshTime - EXPIRATION_GRACE) { // this access info is close to expiration or has passed expiration time needs to be refreshed before usage. // } // create the task to do the refresh and put it in mRefreshingTasks and execute it. return doRefresh ( session , info ) ; }
Refresh the OAuth in the given BoxSession . This method is called when OAuth token expires .