mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-01 16:44:16 +00:00
fix: get certs and proxy config based on oauth2 token and refresh urls instead of resource url (#6164)
This commit is contained in:
@@ -58,6 +58,7 @@ const EnvironmentSecretsStore = require('../store/env-secrets');
|
||||
const CollectionSecurityStore = require('../store/collection-security');
|
||||
const UiStateSnapshotStore = require('../store/ui-state-snapshot');
|
||||
const interpolateVars = require('./network/interpolate-vars');
|
||||
const { interpolateString } = require('./network/interpolate-string');
|
||||
const { getEnvVars, getTreePathFromCollectionToItem, mergeVars, parseBruFileMeta, hydrateRequestWithUuid, transformRequestToSaveToFilesystem } = require('../utils/collection');
|
||||
const { getProcessEnvVars } = require('../store/process-env');
|
||||
const { getOAuth2TokenUsingAuthorizationCode, getOAuth2TokenUsingClientCredentials, getOAuth2TokenUsingPasswordCredentials, getOAuth2TokenUsingImplicitGrant, refreshOauth2Token } = require('../utils/oauth2');
|
||||
@@ -1290,19 +1291,63 @@ const registerRendererEventHandlers = (mainWindow, watcher) => {
|
||||
const requestTreePath = getTreePathFromCollectionToItem(collection, partialItem);
|
||||
mergeVars(collection, requestCopy, requestTreePath);
|
||||
const globalEnvironmentVariables = collection.globalEnvironmentVariables;
|
||||
|
||||
const promptVariables = collection.promptVariables;
|
||||
interpolateVars(requestCopy, envVars, runtimeVariables, processEnvVars);
|
||||
const certsAndProxyConfig = await getCertsAndProxyConfig({
|
||||
collectionUid,
|
||||
collection,
|
||||
request: requestCopy,
|
||||
envVars,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
collectionPath,
|
||||
globalEnvironmentVariables
|
||||
});
|
||||
const { oauth2: { grantType } } = requestCopy || {};
|
||||
const { oauth2: { grantType, accessTokenUrl, refreshTokenUrl }, collectionVariables, folderVariables, requestVariables } = requestCopy || {};
|
||||
|
||||
// For OAuth2 token requests, use accessTokenUrl for cert/proxy config instead of main request URL
|
||||
let certsAndProxyConfigForTokenUrl = null;
|
||||
let certsAndProxyConfigForRefreshUrl = null;
|
||||
|
||||
if (accessTokenUrl && grantType !== 'implicit') {
|
||||
const interpolatedTokenUrl = interpolateString(accessTokenUrl, {
|
||||
globalEnvironmentVariables,
|
||||
collectionVariables,
|
||||
envVars,
|
||||
folderVariables,
|
||||
requestVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
promptVariables
|
||||
});
|
||||
let tokenRequestForConfig = { ...requestCopy, url: interpolatedTokenUrl };
|
||||
certsAndProxyConfigForTokenUrl = await getCertsAndProxyConfig({
|
||||
collectionUid,
|
||||
collection,
|
||||
request: tokenRequestForConfig,
|
||||
envVars,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
collectionPath,
|
||||
globalEnvironmentVariables
|
||||
});
|
||||
}
|
||||
|
||||
// For refresh token requests, use refreshTokenUrl if available, otherwise accessTokenUrl
|
||||
const tokenUrlForRefresh = refreshTokenUrl || accessTokenUrl;
|
||||
if (tokenUrlForRefresh && grantType !== 'implicit') {
|
||||
const interpolatedRefreshUrl = interpolateString(tokenUrlForRefresh, {
|
||||
globalEnvironmentVariables,
|
||||
collectionVariables,
|
||||
envVars,
|
||||
folderVariables,
|
||||
requestVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
promptVariables
|
||||
});
|
||||
let refreshRequestForConfig = { ...requestCopy, url: interpolatedRefreshUrl };
|
||||
certsAndProxyConfigForRefreshUrl = await getCertsAndProxyConfig({
|
||||
collectionUid,
|
||||
collection,
|
||||
request: refreshRequestForConfig,
|
||||
envVars,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
collectionPath,
|
||||
globalEnvironmentVariables
|
||||
});
|
||||
}
|
||||
|
||||
const handleOAuth2Response = (response) => {
|
||||
if (response.error && !response.debugInfo) {
|
||||
@@ -1318,7 +1363,8 @@ const registerRendererEventHandlers = (mainWindow, watcher) => {
|
||||
request: requestCopy,
|
||||
collectionUid,
|
||||
forceFetch: true,
|
||||
certsAndProxyConfig
|
||||
certsAndProxyConfigForTokenUrl,
|
||||
certsAndProxyConfigForRefreshUrl
|
||||
}).then(handleOAuth2Response);
|
||||
|
||||
case 'client_credentials':
|
||||
@@ -1327,7 +1373,8 @@ const registerRendererEventHandlers = (mainWindow, watcher) => {
|
||||
request: requestCopy,
|
||||
collectionUid,
|
||||
forceFetch: true,
|
||||
certsAndProxyConfig
|
||||
certsAndProxyConfigForTokenUrl,
|
||||
certsAndProxyConfigForRefreshUrl
|
||||
}).then(handleOAuth2Response);
|
||||
|
||||
case 'password':
|
||||
@@ -1336,7 +1383,8 @@ const registerRendererEventHandlers = (mainWindow, watcher) => {
|
||||
request: requestCopy,
|
||||
collectionUid,
|
||||
forceFetch: true,
|
||||
certsAndProxyConfig
|
||||
certsAndProxyConfigForTokenUrl,
|
||||
certsAndProxyConfigForRefreshUrl
|
||||
}).then(handleOAuth2Response);
|
||||
|
||||
case 'implicit':
|
||||
|
||||
@@ -159,12 +159,66 @@ const configureRequest = async (
|
||||
|
||||
if (request.oauth2) {
|
||||
let requestCopy = cloneDeep(request);
|
||||
const { oauth2: { grantType, tokenPlacement, tokenHeaderPrefix, tokenQueryKey } = {} } = requestCopy || {};
|
||||
const { oauth2: { grantType, tokenPlacement, tokenHeaderPrefix, tokenQueryKey, accessTokenUrl, refreshTokenUrl } = {}, collectionVariables, folderVariables, requestVariables } = requestCopy || {};
|
||||
|
||||
// Get cert/proxy configs for token and refresh URLs
|
||||
let certsAndProxyConfigForTokenUrl = certsAndProxyConfig;
|
||||
let certsAndProxyConfigForRefreshUrl = certsAndProxyConfig;
|
||||
|
||||
if (accessTokenUrl && grantType !== 'implicit') {
|
||||
const interpolatedTokenUrl = interpolateString(accessTokenUrl, {
|
||||
globalEnvironmentVariables,
|
||||
collectionVariables,
|
||||
envVars,
|
||||
folderVariables,
|
||||
requestVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
promptVariables
|
||||
});
|
||||
const tokenRequestForConfig = { ...requestCopy, url: interpolatedTokenUrl };
|
||||
certsAndProxyConfigForTokenUrl = await getCertsAndProxyConfig({
|
||||
collectionUid,
|
||||
collection,
|
||||
request: tokenRequestForConfig,
|
||||
envVars,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
collectionPath,
|
||||
globalEnvironmentVariables
|
||||
});
|
||||
}
|
||||
|
||||
const tokenUrlForRefresh = refreshTokenUrl || accessTokenUrl;
|
||||
if (tokenUrlForRefresh && grantType !== 'implicit') {
|
||||
const interpolatedRefreshUrl = interpolateString(tokenUrlForRefresh, {
|
||||
globalEnvironmentVariables,
|
||||
collectionVariables,
|
||||
envVars,
|
||||
folderVariables,
|
||||
requestVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
promptVariables
|
||||
});
|
||||
const refreshRequestForConfig = { ...requestCopy, url: interpolatedRefreshUrl };
|
||||
certsAndProxyConfigForRefreshUrl = await getCertsAndProxyConfig({
|
||||
collectionUid,
|
||||
collection,
|
||||
request: refreshRequestForConfig,
|
||||
envVars,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
collectionPath,
|
||||
globalEnvironmentVariables
|
||||
});
|
||||
}
|
||||
|
||||
let credentials, credentialsId, oauth2Url, debugInfo;
|
||||
switch (grantType) {
|
||||
case 'authorization_code':
|
||||
interpolateVars(requestCopy, envVars, runtimeVariables, processEnvVars, promptVariables);
|
||||
({ credentials, url: oauth2Url, credentialsId, debugInfo } = await getOAuth2TokenUsingAuthorizationCode({ request: requestCopy, collectionUid, certsAndProxyConfig }));
|
||||
({ credentials, url: oauth2Url, credentialsId, debugInfo } = await getOAuth2TokenUsingAuthorizationCode({ request: requestCopy, collectionUid, certsAndProxyConfigForTokenUrl, certsAndProxyConfigForRefreshUrl }));
|
||||
request.oauth2Credentials = { credentials, url: oauth2Url, collectionUid, credentialsId, debugInfo, folderUid: request.oauth2Credentials?.folderUid };
|
||||
if (tokenPlacement == 'header' && credentials?.access_token) {
|
||||
request.headers['Authorization'] = `${tokenHeaderPrefix} ${credentials.access_token}`.trim();
|
||||
@@ -192,7 +246,7 @@ const configureRequest = async (
|
||||
break;
|
||||
case 'client_credentials':
|
||||
interpolateVars(requestCopy, envVars, runtimeVariables, processEnvVars, promptVariables);
|
||||
({ credentials, url: oauth2Url, credentialsId, debugInfo } = await getOAuth2TokenUsingClientCredentials({ request: requestCopy, collectionUid, certsAndProxyConfig }));
|
||||
({ credentials, url: oauth2Url, credentialsId, debugInfo } = await getOAuth2TokenUsingClientCredentials({ request: requestCopy, collectionUid, certsAndProxyConfigForTokenUrl, certsAndProxyConfigForRefreshUrl }));
|
||||
request.oauth2Credentials = { credentials, url: oauth2Url, collectionUid, credentialsId, debugInfo, folderUid: request.oauth2Credentials?.folderUid };
|
||||
if (tokenPlacement == 'header' && credentials?.access_token) {
|
||||
request.headers['Authorization'] = `${tokenHeaderPrefix} ${credentials.access_token}`.trim();
|
||||
@@ -206,7 +260,7 @@ const configureRequest = async (
|
||||
break;
|
||||
case 'password':
|
||||
interpolateVars(requestCopy, envVars, runtimeVariables, processEnvVars, promptVariables);
|
||||
({ credentials, url: oauth2Url, credentialsId, debugInfo } = await getOAuth2TokenUsingPasswordCredentials({ request: requestCopy, collectionUid, certsAndProxyConfig }));
|
||||
({ credentials, url: oauth2Url, credentialsId, debugInfo } = await getOAuth2TokenUsingPasswordCredentials({ request: requestCopy, collectionUid, certsAndProxyConfigForTokenUrl, certsAndProxyConfigForRefreshUrl }));
|
||||
request.oauth2Credentials = { credentials, url: oauth2Url, collectionUid, credentialsId, debugInfo, folderUid: request.oauth2Credentials?.folderUid };
|
||||
if (tokenPlacement == 'header' && credentials?.access_token) {
|
||||
request.headers['Authorization'] = `${tokenHeaderPrefix} ${credentials.access_token}`.trim();
|
||||
|
||||
@@ -4,6 +4,8 @@ const { getEnvVars, getTreePathFromCollectionToItem, mergeHeaders, mergeScripts,
|
||||
const { getProcessEnvVars } = require('../../store/process-env');
|
||||
const { getOAuth2TokenUsingPasswordCredentials, getOAuth2TokenUsingClientCredentials, getOAuth2TokenUsingAuthorizationCode } = require('../../utils/oauth2');
|
||||
const { setAuthHeaders } = require('./prepare-request');
|
||||
const { getCertsAndProxyConfig } = require('./cert-utils');
|
||||
const { interpolateString } = require('./interpolate-string');
|
||||
|
||||
const processHeaders = (headers) => {
|
||||
Object.entries(headers).forEach(([key, value]) => {
|
||||
@@ -30,25 +32,80 @@ const placeOAuth2Token = (grpcRequest, credentials, tokenPlacement, tokenHeaderP
|
||||
const configureRequest = async (grpcRequest, request, collection, envVars, runtimeVariables, processEnvVars, promptVariables, certsAndProxyConfig) => {
|
||||
if (grpcRequest.oauth2) {
|
||||
let requestCopy = cloneDeep(grpcRequest);
|
||||
const { oauth2: { grantType, tokenPlacement, tokenHeaderPrefix, tokenQueryKey } = {} } = requestCopy || {};
|
||||
const { uid: collectionUid, pathname: collectionPath, globalEnvironmentVariables } = collection;
|
||||
const { oauth2: { grantType, tokenPlacement, tokenHeaderPrefix, tokenQueryKey, accessTokenUrl, refreshTokenUrl } = {}, collectionVariables, folderVariables, requestVariables } = requestCopy || {};
|
||||
let credentials, credentialsId, oauth2Url, debugInfo;
|
||||
|
||||
// Get cert/proxy configs for token and refresh URLs
|
||||
let certsAndProxyConfigForTokenUrl = certsAndProxyConfig;
|
||||
let certsAndProxyConfigForRefreshUrl = certsAndProxyConfig;
|
||||
|
||||
if (accessTokenUrl && grantType !== 'implicit') {
|
||||
const interpolatedTokenUrl = interpolateString(accessTokenUrl, {
|
||||
globalEnvironmentVariables,
|
||||
collectionVariables,
|
||||
envVars,
|
||||
folderVariables,
|
||||
requestVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
promptVariables
|
||||
});
|
||||
const tokenRequestForConfig = { ...requestCopy, url: interpolatedTokenUrl };
|
||||
certsAndProxyConfigForTokenUrl = await getCertsAndProxyConfig({
|
||||
collectionUid,
|
||||
collection,
|
||||
request: tokenRequestForConfig,
|
||||
envVars,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
collectionPath,
|
||||
globalEnvironmentVariables
|
||||
});
|
||||
}
|
||||
|
||||
const tokenUrlForRefresh = refreshTokenUrl || accessTokenUrl;
|
||||
if (tokenUrlForRefresh && grantType !== 'implicit') {
|
||||
const interpolatedRefreshUrl = interpolateString(tokenUrlForRefresh, {
|
||||
globalEnvironmentVariables,
|
||||
collectionVariables,
|
||||
envVars,
|
||||
folderVariables,
|
||||
requestVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
promptVariables
|
||||
});
|
||||
const refreshRequestForConfig = { ...requestCopy, url: interpolatedRefreshUrl };
|
||||
certsAndProxyConfigForRefreshUrl = await getCertsAndProxyConfig({
|
||||
collectionUid,
|
||||
collection,
|
||||
request: refreshRequestForConfig,
|
||||
envVars,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
collectionPath,
|
||||
globalEnvironmentVariables
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
switch (grantType) {
|
||||
case 'authorization_code':
|
||||
interpolateVars(requestCopy, envVars, runtimeVariables, processEnvVars, promptVariables);
|
||||
({ credentials, url: oauth2Url, credentialsId, debugInfo } = await getOAuth2TokenUsingAuthorizationCode({ request: requestCopy, collectionUid: collection.uid, certsAndProxyConfig }));
|
||||
({ credentials, url: oauth2Url, credentialsId, debugInfo } = await getOAuth2TokenUsingAuthorizationCode({ request: requestCopy, collectionUid: collection.uid, certsAndProxyConfigForTokenUrl, certsAndProxyConfigForRefreshUrl }));
|
||||
grpcRequest.oauth2Credentials = { credentials, url: oauth2Url, collectionUid: collection.uid, credentialsId, debugInfo, folderUid: request.oauth2Credentials?.folderUid };
|
||||
placeOAuth2Token(grpcRequest, credentials, tokenPlacement, tokenHeaderPrefix, tokenQueryKey);
|
||||
break;
|
||||
case 'client_credentials':
|
||||
interpolateVars(requestCopy, envVars, runtimeVariables, processEnvVars, promptVariables);
|
||||
({ credentials, url: oauth2Url, credentialsId, debugInfo } = await getOAuth2TokenUsingClientCredentials({ request: requestCopy, collectionUid: collection.uid, certsAndProxyConfig }));
|
||||
({ credentials, url: oauth2Url, credentialsId, debugInfo } = await getOAuth2TokenUsingClientCredentials({ request: requestCopy, collectionUid: collection.uid, certsAndProxyConfigForTokenUrl, certsAndProxyConfigForRefreshUrl }));
|
||||
grpcRequest.oauth2Credentials = { credentials, url: oauth2Url, collectionUid: collection.uid, credentialsId, debugInfo, folderUid: request.oauth2Credentials?.folderUid };
|
||||
placeOAuth2Token(grpcRequest, credentials, tokenPlacement, tokenHeaderPrefix, tokenQueryKey);
|
||||
break;
|
||||
case 'password':
|
||||
interpolateVars(requestCopy, envVars, runtimeVariables, processEnvVars, promptVariables);
|
||||
({ credentials, url: oauth2Url, credentialsId, debugInfo } = await getOAuth2TokenUsingPasswordCredentials({ request: requestCopy, collectionUid: collection.uid, certsAndProxyConfig }));
|
||||
({ credentials, url: oauth2Url, credentialsId, debugInfo } = await getOAuth2TokenUsingPasswordCredentials({ request: requestCopy, collectionUid: collection.uid, certsAndProxyConfigForTokenUrl, certsAndProxyConfigForRefreshUrl }));
|
||||
grpcRequest.oauth2Credentials = { credentials, url: oauth2Url, collectionUid: collection.uid, credentialsId, debugInfo, folderUid: request.oauth2Credentials?.folderUid };
|
||||
placeOAuth2Token(grpcRequest, credentials, tokenPlacement, tokenHeaderPrefix, tokenQueryKey);
|
||||
break;
|
||||
|
||||
@@ -71,6 +71,7 @@ const prepareWsRequest = async (item, collection, environment, runtimeVariables,
|
||||
|
||||
const envVars = getEnvVars(environment);
|
||||
const processEnvVars = getProcessEnvVars(collection.uid);
|
||||
const { promptVariables = {} } = collection;
|
||||
|
||||
let wsRequest = {
|
||||
uid: item.uid,
|
||||
@@ -94,7 +95,61 @@ const prepareWsRequest = async (item, collection, environment, runtimeVariables,
|
||||
|
||||
if (wsRequest.oauth2) {
|
||||
let requestCopy = cloneDeep(wsRequest);
|
||||
const { oauth2: { grantType, tokenPlacement, tokenHeaderPrefix, tokenQueryKey } = {} } = requestCopy || {};
|
||||
const { oauth2: { grantType, tokenPlacement, tokenHeaderPrefix, tokenQueryKey, accessTokenUrl, refreshTokenUrl } = {}, collectionVariables, folderVariables, requestVariables } = requestCopy || {};
|
||||
|
||||
// Get cert/proxy configs for token and refresh URLs
|
||||
let certsAndProxyConfigForTokenUrl = certsAndProxyConfig;
|
||||
let certsAndProxyConfigForRefreshUrl = certsAndProxyConfig;
|
||||
|
||||
if (accessTokenUrl && grantType !== 'implicit') {
|
||||
const interpolatedTokenUrl = interpolateString(accessTokenUrl, {
|
||||
globalEnvironmentVariables: request.globalEnvironmentVariables,
|
||||
collectionVariables,
|
||||
envVars,
|
||||
folderVariables,
|
||||
requestVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
promptVariables
|
||||
});
|
||||
const tokenRequestForConfig = { ...requestCopy, url: interpolatedTokenUrl };
|
||||
certsAndProxyConfigForTokenUrl = await getCertsAndProxyConfig({
|
||||
collectionUid: collection.uid,
|
||||
collection,
|
||||
request: tokenRequestForConfig,
|
||||
envVars,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
collectionPath: collection.pathname,
|
||||
globalEnvironmentVariables: request.globalEnvironmentVariables
|
||||
});
|
||||
}
|
||||
|
||||
const tokenUrlForRefresh = refreshTokenUrl || accessTokenUrl;
|
||||
if (tokenUrlForRefresh && grantType !== 'implicit') {
|
||||
const interpolatedRefreshUrl = interpolateString(tokenUrlForRefresh, {
|
||||
globalEnvironmentVariables: request.globalEnvironmentVariables,
|
||||
collectionVariables,
|
||||
envVars,
|
||||
folderVariables,
|
||||
requestVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
promptVariables
|
||||
});
|
||||
const refreshRequestForConfig = { ...requestCopy, url: interpolatedRefreshUrl };
|
||||
certsAndProxyConfigForRefreshUrl = await getCertsAndProxyConfig({
|
||||
collectionUid: collection.uid,
|
||||
collection,
|
||||
request: refreshRequestForConfig,
|
||||
envVars,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
collectionPath: collection.pathname,
|
||||
globalEnvironmentVariables: request.globalEnvironmentVariables
|
||||
});
|
||||
}
|
||||
|
||||
let credentials, credentialsId, oauth2Url, debugInfo;
|
||||
|
||||
switch (grantType) {
|
||||
@@ -108,7 +163,8 @@ const prepareWsRequest = async (item, collection, environment, runtimeVariables,
|
||||
} = await getOAuth2TokenUsingAuthorizationCode({
|
||||
request: requestCopy,
|
||||
collectionUid: collection.uid,
|
||||
certsAndProxyConfig
|
||||
certsAndProxyConfigForTokenUrl,
|
||||
certsAndProxyConfigForRefreshUrl
|
||||
}));
|
||||
wsRequest.oauth2Credentials = {
|
||||
credentials,
|
||||
@@ -138,7 +194,8 @@ const prepareWsRequest = async (item, collection, environment, runtimeVariables,
|
||||
} = await getOAuth2TokenUsingClientCredentials({
|
||||
request: requestCopy,
|
||||
collectionUid: collection.uid,
|
||||
certsAndProxyConfig
|
||||
certsAndProxyConfigForTokenUrl,
|
||||
certsAndProxyConfigForRefreshUrl
|
||||
}));
|
||||
wsRequest.oauth2Credentials = {
|
||||
credentials,
|
||||
@@ -168,7 +225,8 @@ const prepareWsRequest = async (item, collection, environment, runtimeVariables,
|
||||
} = await getOAuth2TokenUsingPasswordCredentials({
|
||||
request: requestCopy,
|
||||
collectionUid: collection.uid,
|
||||
certsAndProxyConfig
|
||||
certsAndProxyConfigForTokenUrl,
|
||||
certsAndProxyConfigForRefreshUrl
|
||||
}));
|
||||
wsRequest.oauth2Credentials = {
|
||||
credentials,
|
||||
|
||||
@@ -52,7 +52,7 @@ const safeParseJSONBuffer = (data) => {
|
||||
const getCredentialsFromTokenUrl = async ({ requestConfig, certsAndProxyConfig }) => {
|
||||
const { proxyMode, proxyConfig, httpsAgentRequestFields, interpolationOptions } = certsAndProxyConfig;
|
||||
const axiosInstance = makeAxiosInstance({ proxyMode, proxyConfig, httpsAgentRequestFields, interpolationOptions });
|
||||
let requestDetails, parsedResponseData;
|
||||
let requestDetails = { request: {}, response: {} }, parsedResponseData;
|
||||
try {
|
||||
const response = await axiosInstance(requestConfig);
|
||||
const { url: responseUrl, headers: responseHeaders, status: responseStatus, statusText: responseStatusText, data: responseData, timeline, config } = response || {};
|
||||
@@ -112,7 +112,7 @@ const getCredentialsFromTokenUrl = async ({ requestConfig, certsAndProxyConfig }
|
||||
statusText: error?.code,
|
||||
headers: {},
|
||||
data: safeStringifyJSON(error?.errors),
|
||||
timeline: error?.response?.timeline
|
||||
timeline: error?.timeline
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -132,7 +132,7 @@ const getCredentialsFromTokenUrl = async ({ requestConfig, certsAndProxyConfig }
|
||||
|
||||
// AUTHORIZATION CODE
|
||||
|
||||
const getOAuth2TokenUsingAuthorizationCode = async ({ request, collectionUid, forceFetch = false, certsAndProxyConfig }) => {
|
||||
const getOAuth2TokenUsingAuthorizationCode = async ({ request, collectionUid, forceFetch = false, certsAndProxyConfigForTokenUrl, certsAndProxyConfigForRefreshUrl }) => {
|
||||
let codeVerifier = generateCodeVerifier();
|
||||
let codeChallenge = generateCodeChallenge(codeVerifier);
|
||||
|
||||
@@ -204,7 +204,7 @@ const getOAuth2TokenUsingAuthorizationCode = async ({ request, collectionUid, fo
|
||||
if (autoRefreshToken && storedCredentials.refresh_token) {
|
||||
// Try to refresh token
|
||||
try {
|
||||
const refreshedCredentialsData = await refreshOauth2Token({ requestCopy, collectionUid, certsAndProxyConfig });
|
||||
const refreshedCredentialsData = await refreshOauth2Token({ requestCopy, collectionUid, certsAndProxyConfig: certsAndProxyConfigForRefreshUrl });
|
||||
return { collectionUid, url, credentials: refreshedCredentialsData.credentials, credentialsId };
|
||||
} catch (error) {
|
||||
// Refresh failed
|
||||
@@ -281,7 +281,7 @@ const getOAuth2TokenUsingAuthorizationCode = async ({ request, collectionUid, fo
|
||||
}
|
||||
axiosRequestConfig.data = qs.stringify(data);
|
||||
try {
|
||||
const { credentials, requestDetails } = await getCredentialsFromTokenUrl({ requestConfig: axiosRequestConfig, certsAndProxyConfig });
|
||||
const { credentials, requestDetails } = await getCredentialsFromTokenUrl({ requestConfig: axiosRequestConfig, certsAndProxyConfig: certsAndProxyConfigForTokenUrl });
|
||||
|
||||
// Ensure debugInfo.data is initialized
|
||||
if (!debugInfo) {
|
||||
@@ -366,7 +366,7 @@ const getAdditionalHeaders = (params) => {
|
||||
|
||||
// CLIENT CREDENTIALS
|
||||
|
||||
const getOAuth2TokenUsingClientCredentials = async ({ request, collectionUid, forceFetch = false, certsAndProxyConfig }) => {
|
||||
const getOAuth2TokenUsingClientCredentials = async ({ request, collectionUid, forceFetch = false, certsAndProxyConfigForTokenUrl, certsAndProxyConfigForRefreshUrl }) => {
|
||||
let requestCopy = cloneDeep(request);
|
||||
const oAuth = get(requestCopy, 'oauth2', {});
|
||||
const {
|
||||
@@ -414,7 +414,7 @@ const getOAuth2TokenUsingClientCredentials = async ({ request, collectionUid, fo
|
||||
if (autoRefreshToken && storedCredentials.refresh_token) {
|
||||
// Try to refresh token
|
||||
try {
|
||||
const refreshedCredentialsData = await refreshOauth2Token({ requestCopy, collectionUid, certsAndProxyConfig });
|
||||
const refreshedCredentialsData = await refreshOauth2Token({ requestCopy, collectionUid, certsAndProxyConfig: certsAndProxyConfigForRefreshUrl });
|
||||
return { collectionUid, url, credentials: refreshedCredentialsData.credentials, credentialsId };
|
||||
} catch (error) {
|
||||
clearOauth2Credentials({ collectionUid, url, credentialsId });
|
||||
@@ -483,7 +483,7 @@ const getOAuth2TokenUsingClientCredentials = async ({ request, collectionUid, fo
|
||||
axiosRequestConfig.data = qs.stringify(data);
|
||||
let debugInfo = { data: [] };
|
||||
try {
|
||||
const { credentials, requestDetails } = await getCredentialsFromTokenUrl({ requestConfig: axiosRequestConfig, certsAndProxyConfig });
|
||||
const { credentials, requestDetails } = await getCredentialsFromTokenUrl({ requestConfig: axiosRequestConfig, certsAndProxyConfig: certsAndProxyConfigForTokenUrl });
|
||||
debugInfo.data.push(requestDetails);
|
||||
credentials && persistOauth2Credentials({ collectionUid, url, credentials, credentialsId });
|
||||
return { collectionUid, url, credentials, credentialsId, debugInfo };
|
||||
@@ -494,7 +494,7 @@ const getOAuth2TokenUsingClientCredentials = async ({ request, collectionUid, fo
|
||||
|
||||
// PASSWORD CREDENTIALS
|
||||
|
||||
const getOAuth2TokenUsingPasswordCredentials = async ({ request, collectionUid, forceFetch = false, certsAndProxyConfig }) => {
|
||||
const getOAuth2TokenUsingPasswordCredentials = async ({ request, collectionUid, forceFetch = false, certsAndProxyConfigForTokenUrl, certsAndProxyConfigForRefreshUrl }) => {
|
||||
let requestCopy = cloneDeep(request);
|
||||
const oAuth = get(requestCopy, 'oauth2', {});
|
||||
const {
|
||||
@@ -561,7 +561,7 @@ const getOAuth2TokenUsingPasswordCredentials = async ({ request, collectionUid,
|
||||
if (autoRefreshToken && storedCredentials.refresh_token) {
|
||||
// Try to refresh token
|
||||
try {
|
||||
const refreshedCredentialsData = await refreshOauth2Token({ requestCopy, collectionUid, certsAndProxyConfig });
|
||||
const refreshedCredentialsData = await refreshOauth2Token({ requestCopy, collectionUid, certsAndProxyConfig: certsAndProxyConfigForRefreshUrl });
|
||||
return { collectionUid, url, credentials: refreshedCredentialsData.credentials, credentialsId };
|
||||
} catch (error) {
|
||||
clearOauth2Credentials({ collectionUid, url, credentialsId });
|
||||
@@ -633,7 +633,7 @@ const getOAuth2TokenUsingPasswordCredentials = async ({ request, collectionUid,
|
||||
axiosRequestConfig.data = qs.stringify(data);
|
||||
let debugInfo = { data: [] };
|
||||
try {
|
||||
const { credentials, requestDetails } = await getCredentialsFromTokenUrl({ requestConfig: axiosRequestConfig, certsAndProxyConfig });
|
||||
const { credentials, requestDetails } = await getCredentialsFromTokenUrl({ requestConfig: axiosRequestConfig, certsAndProxyConfig: certsAndProxyConfigForTokenUrl });
|
||||
debugInfo.data.push(requestDetails);
|
||||
credentials && persistOauth2Credentials({ collectionUid, url, credentials, credentialsId });
|
||||
return { collectionUid, url, credentials, credentialsId, debugInfo };
|
||||
|
||||
Reference in New Issue
Block a user