/** * Gets the OAuth2 authorization header for the parameters and request URL. * * @param oAuth2Compatible exposes the OAuth2 credentials * @return the {@code Authorization} header value to set */ public String getOAuth2AuthorizationHeader(OAuth2Compatible oAuth2Compatible) { return HEADER_PREFIX + oAuth2Compatible.getOAuth2Credential().getAccessToken(); } }
/** * Gets the OAuth2 authorization header for the parameters and request URL. * * @param oAuth2Compatible exposes the OAuth2 credentials * @return the {@code Authorization} header value to set */ public String getOAuth2AuthorizationHeader(OAuth2Compatible oAuth2Compatible) { return HEADER_PREFIX + oAuth2Compatible.getOAuth2Credential().getAccessToken(); } }
/** * Gets a header value that can be set to the {@code Authorization} HTTP * header. The endpoint URL can be {@code null} if it's not needed for the * authentication mechanism (i.e. OAuth2). * * @param adsSession the session to pull authentication information from * @param endpointUrl the endpoint URL used for authentication mechanisms like * OAuth. * @return the authorization header * @throws AuthenticationException if the authorization header could not be * created * @throws IllegalArgumentException if no valid authentication information * exists within the session. */ public String getAuthorizationHeader(AdsSession adsSession, @Nullable String endpointUrl) throws AuthenticationException { if (adsSession instanceof OAuth2Compatible && ((OAuth2Compatible) adsSession).getOAuth2Credential() != null) { return getOAuth2Header((OAuth2Compatible) adsSession); } else { throw new IllegalArgumentException( "Session does not have any valid authentication mechanisms"); } }
/** * Gets a header value that can be set to the {@code Authorization} HTTP * header. The endpoint URL can be {@code null} if it's not needed for the * authentication mechanism (i.e. OAuth2). * * @param adsSession the session to pull authentication information from * @param endpointUrl the endpoint URL used for authentication mechanisms like * OAuth. * @return the authorization header * @throws AuthenticationException if the authorization header could not be * created * @throws IllegalArgumentException if no valid authentication information * exists within the session. */ public String getAuthorizationHeader(AdsSession adsSession, @Nullable String endpointUrl) throws AuthenticationException { if (adsSession instanceof OAuth2Compatible && ((OAuth2Compatible) adsSession).getOAuth2Credential() != null) { return getOAuth2Header((OAuth2Compatible) adsSession); } else { throw new IllegalArgumentException( "Session does not have any valid authentication mechanisms"); } }
/** * 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); } }
/** * 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); } }