AccessToken refreshToken(AccessToken auth2Token) throws IOException { AccessToken newToken = auth2Service.refresh(auth2Token.getRefreshToken(), sessionConfiguration.getClientId()) .execute().body(); tokenStorage.setAccessToken(newToken); return newToken; }
AccessToken refreshToken(AccessToken auth2Token) throws IOException { AccessToken newToken = auth2Service.refresh(auth2Token.getRefreshToken(), sessionConfiguration.getClientId()) .execute().body(); tokenStorage.setAccessToken(newToken); return newToken; }
/** * Set the {@link SessionConfiguration} information */ public Builder setSessionConfiguration(SessionConfiguration configuration) { if (scopes != null) { this.scopes = new HashSet<>(configuration.getScopes()); } if (customScopes != null) { this.customScopes = new HashSet<>(configuration.getCustomScopes()); } this.clientId = configuration.getClientId(); this.clientSecret = configuration.getClientSecret(); this.redirectUri = configuration.getRedirectUri(); this.loginHost = configuration.getLoginHost(); return this; }
/** * Creates an {@link OAuth2Credentials} object that can be used by any of the servlets. */ public static OAuth2Credentials createOAuth2Credentials(SessionConfiguration sessionConfiguration) throws Exception { // Store the users OAuth2 credentials in their home directory. File credentialDirectory = new File(System.getProperty("user.home") + File.separator + ".uber_credentials"); credentialDirectory.setReadable(true, true); credentialDirectory.setWritable(true, true); // If you'd like to store them in memory or in a DB, any DataStoreFactory can be used. AbstractDataStoreFactory dataStoreFactory = new FileDataStoreFactory(credentialDirectory); // Build an OAuth2Credentials object with your secrets. return new OAuth2Credentials.Builder() .setCredentialDataStoreFactory(dataStoreFactory) .setRedirectUri(sessionConfiguration.getRedirectUri()) .setClientSecrets(sessionConfiguration.getClientId(), sessionConfiguration.getClientSecret()) .build(); }
@Test public void testRefreshToken() throws Exception { when(accessToken.getRefreshToken()).thenReturn("refresh"); when(config.getClientId()).thenReturn("clientId"); when(service.refresh(eq("refresh"), eq("clientId"))).thenReturn(serviceResult); when(serviceResult.execute()).thenReturn(retrofit2.Response.success(accessToken)); assertEquals(accessToken, authenticator.refreshToken(accessToken)); verify(accessTokenStorage).setAccessToken(accessToken); }
@Test public void getClientId_whenSetOnBuilder_setsOnConfiguration() throws Exception { SessionConfiguration config = new SessionConfiguration.Builder() .setClientId("clientId") .build(); assertEquals("clientId", config.getClientId()); }
@Test public void newBuilder_copiesConfiguration() throws Exception { SessionConfiguration config = new SessionConfiguration.Builder() .setClientId("clientId") .setRedirectUri("test") .build(); SessionConfiguration config2 = config.newBuilder().setClientId("clientId2").build(); assertEquals("clientId", config.getClientId()); assertEquals("clientId2", config2.getClientId()); assertEquals("test", config2.getRedirectUri()); }
/** * Creates an {@link OAuth2Credentials} object that can be used by any of the servlets. * * Throws an {@throws IOException} when no client ID or secret found in secrets.properties */ static OAuth2Credentials createOAuth2Credentials(SessionConfiguration config) throws IOException { return new OAuth2Credentials.Builder() .setCredentialDataStoreFactory(MemoryDataStoreFactory.getDefaultInstance()) .setRedirectUri(config.getRedirectUri()) .setScopes(config.getScopes()) .setClientSecrets(config.getClientId(), config.getClientSecret()) .build(); }