@Override public OfflineCredentials build() throws ValidationException { defaultOptionals(); validate(); return new OfflineCredentials(this); }
/** * Specifies which {@link OAuthConfig} should this {@code OfflineCredentials} be * used for. Should be called first before any other builder methods. */ public ForApiBuilder forApi(OAuthConfig oAuthConfig) { defaultOptionals(oAuthConfig); return new ForApiBuilder(oAuthConfig, oAuth2Helper); }
/** * Specifies which {@link Api} should this {@code GoogleClientSecrets} be * generated for. Should be called first before any other builder methods. */ public GoogleClientSecretsForApiBuilder forApi(Api api) { return new GoogleClientSecretsForApiBuilder(api); }
/** * Tests that the builder builds correctly using a service account key file. */ @Test public void testBuilder_serviceAccount() throws Exception { OfflineCredentials offlineCredentials = new OfflineCredentials.Builder() .forApi(OfflineCredentials.Api.AD_MANAGER) .withJsonKeyFilePath("jsonKeyFilePath") .build(); assertEquals("jsonKeyFilePath", offlineCredentials.getJsonKeyFilePath()); }
/** * Tests that the builder does not fail when missing everything but a service account key. */ @Test public void testReadPropertiesFromConfiguration_onlyKeyFilePath() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.jsonKeyFilePath", "jsonKeyFilePath"); new OfflineCredentials.Builder() .forApi(OfflineCredentials.Api.AD_MANAGER) .from(config) .build(); }
/** * Gets the OAuth2 header. * * @throws OAuthException if the OAuth2 token could not be refreshed. */ private String getOAuth2Header(OAuth2Compatible oAuth2Compatible) throws OAuthException { if (adsLibConfiguration.isAutoRefreshOAuth2TokenEnabled()) { try { oAuth2Helper.refreshCredential(oAuth2Compatible.getOAuth2Credential()); } catch (IOException e) { throw new OAuthException("OAuth2 token could not be refreshed.", e); } } return oAuth2AuthorizationHeaderProvider.getOAuth2AuthorizationHeader(oAuth2Compatible); } }
@Override public GoogleClientSecretsForApiBuilder fromFile() throws ConfigurationLoadException { return fromFile(com.google.api.ads.common.lib.utils.Builder.DEFAULT_CONFIGURATION_FILENAME); }
@Override public ForApiBuilder fromFile() throws ConfigurationLoadException { return fromFile(com.google.api.ads.common.lib.utils.Builder.DEFAULT_CONFIGURATION_FILENAME); }
/** * Adds the correct property key prefix to match the API. * * @param suffix the property suffix * @return property value for key */ private String getPropertyKey(String suffix) { return oAuthConfig.getPropertyKeyPrefix() + suffix; } }
/** * Adds the correct property key prefix to match the API. * * @param suffix the property suffix * @return property value for key */ private String getPropertyKey(String suffix) { return api.getPropKeyPrefix() + suffix; }
/** * Generates a file path warning for the key. */ private String generateFilePathWarning(String key) { return String.format(" as %s in %s.", getPropertyKey(key), filePath); } }
/** * Configure common Guice bindings. */ @Override protected void configure() { install(new AuthModule()); }
/** * Gets the OAuth2 header. * * @throws OAuthException if the OAuth2 token could not be refreshed. */ private String getOAuth2Header(OAuth2Compatible oAuth2Compatible) throws OAuthException { if (adsLibConfiguration.isAutoRefreshOAuth2TokenEnabled()) { try { oAuth2Helper.refreshCredential(oAuth2Compatible.getOAuth2Credential()); } catch (IOException e) { throw new OAuthException("OAuth2 token could not be refreshed.", e); } } return oAuth2AuthorizationHeaderProvider.getOAuth2AuthorizationHeader(oAuth2Compatible); } }
@Override public OfflineCredentials build() throws ValidationException { defaultOptionals(); validate(); return new OfflineCredentials(this); }
/** * Specifies which {@link OAuthConfig} should this {@code OfflineCredentials} be * used for. Should be called first before any other builder methods. */ public ForApiBuilder forApi(OAuthConfig oAuthConfig) { defaultOptionals(oAuthConfig); return new ForApiBuilder(oAuthConfig, oAuth2Helper); }
/** * Specifies which {@link Api} should this {@code GoogleClientSecrets} be * generated for. Should be called first before any other builder methods. */ public GoogleClientSecretsForApiBuilder forApi(Api api) { return new GoogleClientSecretsForApiBuilder(api); }
@Override public GoogleClientSecretsForApiBuilder fromFile() throws ConfigurationLoadException { return fromFile(com.google.api.ads.common.lib.utils.Builder.DEFAULT_CONFIGURATION_FILENAME); }
@Override public ForApiBuilder fromFile() throws ConfigurationLoadException { return fromFile(com.google.api.ads.common.lib.utils.Builder.DEFAULT_CONFIGURATION_FILENAME); }
/** * Adds the correct property key prefix to match the API. * * @param suffix the property suffix * @return property value for key */ private String getPropertyKey(String suffix) { return oAuthConfig.getPropertyKeyPrefix() + suffix; } }
/** * Adds the correct property key prefix to match the API. * * @param suffix the property suffix * @return property value for key */ private String getPropertyKey(String suffix) { return api.getPropKeyPrefix() + suffix; }