@Test public void shouldRefreshAccessTokenIfItsTheFirstTimeApiIsInvoked() throws Exception { final OAuthRefreshTokenProcessor processor = createProcessor( "{\"access_token\": \"new-access-token\", \"refresh_token\": \"new-refresh-token\", \"expires_in\": 3600}"); processor.state.update("access-token", currentTime + OAuthRefreshTokenProcessor.AHEAD_OF_TIME_REFRESH_MILIS + 1000, null); processor.process(exchange); assertThat(processor.state.getAccessToken()).isEqualTo("new-access-token"); assertThat(processor.state.getRefreshToken()).isEqualTo("new-refresh-token"); assertThat(processor.state.getAccessTokenExpiresAt()).isEqualTo(currentTime + 3600000L); }
@Override public void process(final Exchange exchange) throws Exception { if (state.getRefreshToken() != null && (isFirstTime.get() || state.getAccessTokenExpiresAt() - AHEAD_OF_TIME_REFRESH_MILIS <= now())) { tryToRefreshAccessToken(); } final Message in = exchange.getIn(); in.setHeader("Authorization", "Bearer " + state.getAccessToken()); SyndesisHeaderStrategy.whitelist(exchange, "Authorization"); }
OAuthRefreshTokenProcessor implements Processor { @Override public void process(final Exchange exchange) throws Exception { if (state.getRefreshToken() != null && (isFirstTime.get() || state.getAccessTokenExpiresAt() - AHEAD_OF_TIME_REFRESH_MILIS <= now())) { tryToRefreshAccessToken(); } final Message in = exchange.getIn(); in.setHeader("Authorization", "Bearer " + state.getAccessToken()); SyndesisHeaderStrategy.whitelist(exchange, "Authorization"); } }
OAuthRefreshTokenProcessor implements Processor { @Override public void process(final Exchange exchange) throws Exception { if (state.getRefreshToken() != null && (isFirstTime.get() || state.getAccessTokenExpiresAt() - AHEAD_OF_TIME_REFRESH_MILIS <= now())) { tryToRefreshAccessToken(); } final Message in = exchange.getIn(); in.setHeader("Authorization", "Bearer " + state.getAccessToken()); SyndesisHeaderStrategy.whitelist(exchange, "Authorization"); } OAuthRefreshTokenProcessor(final OAuthState state, final Configuration configuration); }
OAuthRefreshTokenProcessor implements Processor { @Override public void process(final Exchange exchange) throws Exception { if (state.getRefreshToken() != null && (isFirstTime.get() || state.getAccessTokenExpiresAt() - AHEAD_OF_TIME_REFRESH_MILIS <= now())) { tryToRefreshAccessToken(); } final Message in = exchange.getIn(); in.setHeader("Authorization", "Bearer " + state.getAccessToken()); SyndesisHeaderStrategy.whitelist(exchange, "Authorization"); } OAuthRefreshTokenProcessor(final OAuthState state, final Configuration configuration); @Override void process(final Exchange exchange); }
OAuthRefreshTokenProcessor implements Processor { @Override public void process(final Exchange exchange) throws Exception { if (state.getRefreshToken() != null && (isFirstTime.get() || state.getAccessTokenExpiresAt() - AHEAD_OF_TIME_REFRESH_MILIS <= now())) { tryToRefreshAccessToken(); } final Message in = exchange.getIn(); in.setHeader("Authorization", "Bearer " + state.getAccessToken()); SyndesisHeaderStrategy.whitelist(exchange, "Authorization"); } OAuthRefreshTokenProcessor(final OAuthState state, final Configuration configuration); @Override void process(final Exchange exchange);  }