mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
CE-508 - Updated to support setCredentialsInHeader
This commit is contained in:
@ -73,6 +73,7 @@ import com.kingsrook.qqq.backend.module.api.model.OutboundAPILog;
|
|||||||
import com.kingsrook.qqq.backend.module.api.model.metadata.APIBackendMetaData;
|
import com.kingsrook.qqq.backend.module.api.model.metadata.APIBackendMetaData;
|
||||||
import com.kingsrook.qqq.backend.module.api.model.metadata.APITableBackendDetails;
|
import com.kingsrook.qqq.backend.module.api.model.metadata.APITableBackendDetails;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.commons.lang.BooleanUtils;
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpEntityEnclosingRequest;
|
import org.apache.http.HttpEntityEnclosingRequest;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
@ -729,18 +730,27 @@ public class BaseAPIActionUtil
|
|||||||
// it as a "cheap & easy" way to "cache" the token within our process's memory... //
|
// it as a "cheap & easy" way to "cache" the token within our process's memory... //
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
String accessToken = ValueUtils.getValueAsString(backendMetaData.getCustomValue("accessToken"));
|
String accessToken = ValueUtils.getValueAsString(backendMetaData.getCustomValue("accessToken"));
|
||||||
|
Boolean setCredentialsInHeader = BooleanUtils.isTrue(ValueUtils.getValueAsBoolean(backendMetaData.getCustomValue("setCredentialsInHeader")));
|
||||||
|
|
||||||
if(!StringUtils.hasContent(accessToken))
|
if(!StringUtils.hasContent(accessToken))
|
||||||
{
|
{
|
||||||
String fullURL = backendMetaData.getBaseUrl() + "oauth/token";
|
String fullURL = backendMetaData.getBaseUrl() + "oauth/token";
|
||||||
String postBody = "grant_type=client_credentials&client_id=" + backendMetaData.getClientId() + "&client_secret=" + backendMetaData.getClientSecret();
|
String postBody = "grant_type=client_credentials";
|
||||||
|
|
||||||
LOG.info("Fetching OAuth2 token from " + fullURL);
|
if(!setCredentialsInHeader)
|
||||||
|
{
|
||||||
|
postBody += "&client_id=" + backendMetaData.getClientId() + "&client_secret=" + backendMetaData.getClientSecret();
|
||||||
|
}
|
||||||
|
|
||||||
try(CloseableHttpClient client = HttpClients.custom().setConnectionManager(new PoolingHttpClientConnectionManager()).build())
|
try(CloseableHttpClient client = HttpClients.custom().setConnectionManager(new PoolingHttpClientConnectionManager()).build())
|
||||||
{
|
{
|
||||||
HttpPost request = new HttpPost(fullURL);
|
HttpPost request = new HttpPost(fullURL);
|
||||||
request.setEntity(new StringEntity(postBody));
|
request.setEntity(new StringEntity(postBody));
|
||||||
|
|
||||||
|
if(setCredentialsInHeader)
|
||||||
|
{
|
||||||
|
request.addHeader("Authorization", getBasicAuthenticationHeader(backendMetaData.getClientId(), backendMetaData.getClientSecret()));
|
||||||
|
}
|
||||||
request.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
|
request.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
|
||||||
|
|
||||||
HttpResponse response = executeOAuthTokenRequest(client, request);
|
HttpResponse response = executeOAuthTokenRequest(client, request);
|
||||||
|
Reference in New Issue
Block a user