/** * Provides a token generator which tries to always provide a valid token. * * @param config the configuration to fetch a token * @param httpClient used http client * @param closeHttpClient set to true, if the httpClient should be closed with the created SphereAccessTokenSupplier * @return token service */ static SphereAccessTokenSupplier ofAutoRefresh(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) { return AutoRefreshSphereAccessTokenSupplierImpl.createAndBeginRefreshInBackground(config, httpClient, closeHttpClient); }
/** * Provides a token generator which tries to always provide a valid token. * * @param config the configuration to fetch a token * @param httpClient used http client * @param closeHttpClient set to true, if the httpClient should be closed with the created SphereAccessTokenSupplier * @return token service */ static SphereAccessTokenSupplier ofAutoRefresh(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) { return AutoRefreshSphereAccessTokenSupplierImpl.createAndBeginRefreshInBackground(config, httpClient, closeHttpClient); }
/** * Provides a token generator which tries to always provide a valid token. * * @param config the configuration to fetch a token * @param httpClient used http client * @param closeHttpClient set to true, if the httpClient should be closed with the created SphereAccessTokenSupplier * @return token service */ static SphereAccessTokenSupplier ofAutoRefresh(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) { return AutoRefreshSphereAccessTokenSupplierImpl.createAndBeginRefreshInBackground(config, httpClient, closeHttpClient); }
/** * Provides a token generator which tries to always provide a valid token. * * @param config the configuration to fetch a token * @param httpClient used http client * @param closeHttpClient set to true, if the httpClient should be closed with the created SphereAccessTokenSupplier * @return token service */ static SphereAccessTokenSupplier ofAutoRefresh(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) { return AutoRefreshSphereAccessTokenSupplierImpl.createAndBeginRefreshInBackground(config, httpClient, closeHttpClient); }
@Test public void refreshesAfterTimeoutOfToken() throws Exception { final TestDoubleHttpClient httpClient = getHttpClient(); try(final SphereAccessTokenSupplier supplier = AutoRefreshSphereAccessTokenSupplierImpl.createAndBeginRefreshInBackground(SphereAuthConfig.of("project-key", "client-id", "clientSecret"), httpClient, true)) { Thread.sleep(3000); assertThat(httpClient.getTimesCalledCount()).isGreaterThan(2).isLessThan(5); } }