/** * 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"); } }