@@ -178,26 +171,19 @@ const OAuth2PasswordCredentials = ({ save, item = {}, request, handleRun, update
-
} placement="bottom-end">
-
{
- dropdownTippyRef.current.hide();
- handleChange('tokenPlacement', 'header');
- }}
- >
- Header
+
handleChange('tokenPlacement', 'header') },
+ { id: 'url', label: 'URL', onClick: () => handleChange('tokenPlacement', 'url') }
+ ]}
+ selectedItemId={tokenPlacement}
+ placement="bottom-end"
+ >
+
+ {tokenPlacement == 'url' ? 'URL' : 'Headers'}
+
- {
- dropdownTippyRef.current.hide();
- handleChange('tokenPlacement', 'url');
- }}
- >
- URL
-
-
+
{
diff --git a/packages/bruno-converters/package.json b/packages/bruno-converters/package.json
index 326bbc97e..0753c4150 100644
--- a/packages/bruno-converters/package.json
+++ b/packages/bruno-converters/package.json
@@ -28,7 +28,7 @@
"devDependencies": {
"@babel/core": "^7.25.2",
"@babel/preset-env": "^7.25.4",
- "@opencollection/types": "~0.5.0",
+ "@opencollection/types": "~0.8.0",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-commonjs": "^23.0.2",
"@rollup/plugin-node-resolve": "^15.0.1",
diff --git a/packages/bruno-electron/src/ipc/network/index.js b/packages/bruno-electron/src/ipc/network/index.js
index 0942ac374..1cadc8de0 100644
--- a/packages/bruno-electron/src/ipc/network/index.js
+++ b/packages/bruno-electron/src/ipc/network/index.js
@@ -160,7 +160,7 @@ const configureRequest = async (
if (request.oauth2) {
let requestCopy = cloneDeep(request);
- const { oauth2: { grantType, tokenPlacement, tokenHeaderPrefix, tokenQueryKey, accessTokenUrl, refreshTokenUrl } = {}, collectionVariables, folderVariables, requestVariables } = requestCopy || {};
+ const { oauth2: { grantType, tokenPlacement, tokenHeaderPrefix, tokenQueryKey, tokenSource, accessTokenUrl, refreshTokenUrl } = {}, collectionVariables, folderVariables, requestVariables } = requestCopy || {};
// Get cert/proxy configs for token and refresh URLs
let certsAndProxyConfigForTokenUrl = certsAndProxyConfig;
@@ -221,56 +221,68 @@ const configureRequest = async (
interpolateVars(requestCopy, envVars, runtimeVariables, processEnvVars, promptVariables);
({ 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();
- } else {
- try {
- const url = new URL(request.url);
- url?.searchParams?.set(tokenQueryKey, credentials?.access_token);
- request.url = url?.toString();
- } catch (error) {}
+ {
+ const tokenValue = tokenSource === 'id_token' ? credentials?.id_token : credentials?.access_token;
+ if (tokenPlacement == 'header' && tokenValue) {
+ request.headers['Authorization'] = `${tokenHeaderPrefix} ${tokenValue}`.trim();
+ } else if (tokenValue) {
+ try {
+ const url = new URL(request.url);
+ url.searchParams.set(tokenQueryKey, tokenValue);
+ request.url = url.toString();
+ } catch (error) {}
+ }
}
break;
case 'implicit':
interpolateVars(requestCopy, envVars, runtimeVariables, processEnvVars, promptVariables);
({ credentials, url: oauth2Url, credentialsId, debugInfo } = await getOAuth2TokenUsingImplicitGrant({ request: requestCopy, collectionUid }));
request.oauth2Credentials = { credentials, url: oauth2Url, collectionUid, credentialsId, debugInfo, folderUid: request.oauth2Credentials?.folderUid };
- if (tokenPlacement == 'header') {
- request.headers['Authorization'] = `${tokenHeaderPrefix} ${credentials?.access_token}`;
- } else {
- try {
- const url = new URL(request.url);
- url?.searchParams?.set(tokenQueryKey, credentials?.access_token);
- request.url = url?.toString();
- } catch (error) {}
+ {
+ const tokenValue = tokenSource === 'id_token' ? credentials?.id_token : credentials?.access_token;
+ if (tokenPlacement == 'header' && tokenValue) {
+ request.headers['Authorization'] = `${tokenHeaderPrefix} ${tokenValue}`.trim();
+ } else if (tokenValue) {
+ try {
+ const url = new URL(request.url);
+ url.searchParams.set(tokenQueryKey, tokenValue);
+ request.url = url.toString();
+ } catch (error) {}
+ }
}
break;
case 'client_credentials':
interpolateVars(requestCopy, envVars, runtimeVariables, processEnvVars, promptVariables);
({ 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();
- } else {
- try {
- const url = new URL(request.url);
- url?.searchParams?.set(tokenQueryKey, credentials?.access_token);
- request.url = url?.toString();
- } catch (error) {}
+ {
+ const tokenValue = tokenSource === 'id_token' ? credentials?.id_token : credentials?.access_token;
+ if (tokenPlacement == 'header' && tokenValue) {
+ request.headers['Authorization'] = `${tokenHeaderPrefix} ${tokenValue}`.trim();
+ } else if (tokenValue) {
+ try {
+ const url = new URL(request.url);
+ url.searchParams.set(tokenQueryKey, tokenValue);
+ request.url = url.toString();
+ } catch (error) {}
+ }
}
break;
case 'password':
interpolateVars(requestCopy, envVars, runtimeVariables, processEnvVars, promptVariables);
({ 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();
- } else {
- try {
- const url = new URL(request.url);
- url?.searchParams?.set(tokenQueryKey, credentials?.access_token);
- request.url = url?.toString();
- } catch (error) {}
+ {
+ const tokenValue = tokenSource === 'id_token' ? credentials?.id_token : credentials?.access_token;
+ if (tokenPlacement == 'header' && tokenValue) {
+ request.headers['Authorization'] = `${tokenHeaderPrefix} ${tokenValue}`.trim();
+ } else if (tokenValue) {
+ try {
+ const url = new URL(request.url);
+ url.searchParams.set(tokenQueryKey, tokenValue);
+ request.url = url.toString();
+ } catch (error) {}
+ }
}
break;
}
diff --git a/packages/bruno-electron/src/ipc/network/prepare-request.js b/packages/bruno-electron/src/ipc/network/prepare-request.js
index 2990f9530..7172b1454 100644
--- a/packages/bruno-electron/src/ipc/network/prepare-request.js
+++ b/packages/bruno-electron/src/ipc/network/prepare-request.js
@@ -89,6 +89,7 @@ const setAuthHeaders = (axiosRequest, request, collectionRoot) => {
tokenPlacement: get(collectionAuth, 'oauth2.tokenPlacement'),
tokenHeaderPrefix: get(collectionAuth, 'oauth2.tokenHeaderPrefix'),
tokenQueryKey: get(collectionAuth, 'oauth2.tokenQueryKey'),
+ tokenSource: get(collectionAuth, 'oauth2.tokenSource'),
autoFetchToken: get(collectionAuth, 'oauth2.autoFetchToken'),
autoRefreshToken: get(collectionAuth, 'oauth2.autoRefreshToken'),
additionalParameters: get(collectionAuth, 'oauth2.additionalParameters', { authorization: [], token: [], refresh: [] })
@@ -111,6 +112,7 @@ const setAuthHeaders = (axiosRequest, request, collectionRoot) => {
tokenPlacement: get(collectionAuth, 'oauth2.tokenPlacement'),
tokenHeaderPrefix: get(collectionAuth, 'oauth2.tokenHeaderPrefix'),
tokenQueryKey: get(collectionAuth, 'oauth2.tokenQueryKey'),
+ tokenSource: get(collectionAuth, 'oauth2.tokenSource'),
autoFetchToken: get(collectionAuth, 'oauth2.autoFetchToken'),
autoRefreshToken: get(collectionAuth, 'oauth2.autoRefreshToken'),
additionalParameters: get(collectionAuth, 'oauth2.additionalParameters', { authorization: [], token: [], refresh: [] })
@@ -128,6 +130,7 @@ const setAuthHeaders = (axiosRequest, request, collectionRoot) => {
tokenPlacement: get(collectionAuth, 'oauth2.tokenPlacement'),
tokenHeaderPrefix: get(collectionAuth, 'oauth2.tokenHeaderPrefix'),
tokenQueryKey: get(collectionAuth, 'oauth2.tokenQueryKey'),
+ tokenSource: get(collectionAuth, 'oauth2.tokenSource'),
autoFetchToken: get(collectionAuth, 'oauth2.autoFetchToken'),
additionalParameters: get(collectionAuth, 'oauth2.additionalParameters', { authorization: [], token: [], refresh: [] })
};
@@ -145,6 +148,7 @@ const setAuthHeaders = (axiosRequest, request, collectionRoot) => {
tokenPlacement: get(collectionAuth, 'oauth2.tokenPlacement'),
tokenHeaderPrefix: get(collectionAuth, 'oauth2.tokenHeaderPrefix'),
tokenQueryKey: get(collectionAuth, 'oauth2.tokenQueryKey'),
+ tokenSource: get(collectionAuth, 'oauth2.tokenSource'),
autoFetchToken: get(collectionAuth, 'oauth2.autoFetchToken'),
autoRefreshToken: get(collectionAuth, 'oauth2.autoRefreshToken'),
additionalParameters: get(collectionAuth, 'oauth2.additionalParameters', { authorization: [], token: [], refresh: [] })
@@ -206,6 +210,7 @@ const setAuthHeaders = (axiosRequest, request, collectionRoot) => {
tokenPlacement: get(request, 'auth.oauth2.tokenPlacement'),
tokenHeaderPrefix: get(request, 'auth.oauth2.tokenHeaderPrefix'),
tokenQueryKey: get(request, 'auth.oauth2.tokenQueryKey'),
+ tokenSource: get(request, 'auth.oauth2.tokenSource'),
autoFetchToken: get(request, 'auth.oauth2.autoFetchToken'),
autoRefreshToken: get(request, 'auth.oauth2.autoRefreshToken'),
additionalParameters: get(request, 'auth.oauth2.additionalParameters', { authorization: [], token: [], refresh: [] })
@@ -228,6 +233,7 @@ const setAuthHeaders = (axiosRequest, request, collectionRoot) => {
tokenPlacement: get(request, 'auth.oauth2.tokenPlacement'),
tokenHeaderPrefix: get(request, 'auth.oauth2.tokenHeaderPrefix'),
tokenQueryKey: get(request, 'auth.oauth2.tokenQueryKey'),
+ tokenSource: get(request, 'auth.oauth2.tokenSource'),
autoFetchToken: get(request, 'auth.oauth2.autoFetchToken'),
autoRefreshToken: get(request, 'auth.oauth2.autoRefreshToken'),
additionalParameters: get(request, 'auth.oauth2.additionalParameters', { authorization: [], token: [], refresh: [] })
@@ -245,6 +251,7 @@ const setAuthHeaders = (axiosRequest, request, collectionRoot) => {
tokenPlacement: get(request, 'auth.oauth2.tokenPlacement'),
tokenHeaderPrefix: get(request, 'auth.oauth2.tokenHeaderPrefix'),
tokenQueryKey: get(request, 'auth.oauth2.tokenQueryKey'),
+ tokenSource: get(request, 'auth.oauth2.tokenSource'),
autoFetchToken: get(request, 'auth.oauth2.autoFetchToken'),
additionalParameters: get(request, 'auth.oauth2.additionalParameters', { authorization: [], token: [], refresh: [] })
};
@@ -262,6 +269,7 @@ const setAuthHeaders = (axiosRequest, request, collectionRoot) => {
tokenPlacement: get(request, 'auth.oauth2.tokenPlacement'),
tokenHeaderPrefix: get(request, 'auth.oauth2.tokenHeaderPrefix'),
tokenQueryKey: get(request, 'auth.oauth2.tokenQueryKey'),
+ tokenSource: get(request, 'auth.oauth2.tokenSource'),
autoFetchToken: get(request, 'auth.oauth2.autoFetchToken'),
autoRefreshToken: get(request, 'auth.oauth2.autoRefreshToken'),
additionalParameters: get(request, 'auth.oauth2.additionalParameters', { authorization: [], token: [], refresh: [] })
diff --git a/packages/bruno-filestore/src/formats/yml/common/auth-oauth2.ts b/packages/bruno-filestore/src/formats/yml/common/auth-oauth2.ts
index fd005b47a..9be961e27 100644
--- a/packages/bruno-filestore/src/formats/yml/common/auth-oauth2.ts
+++ b/packages/bruno-filestore/src/formats/yml/common/auth-oauth2.ts
@@ -114,6 +114,8 @@ const buildTokenConfig = (oauth: BrunoOAuth2): OAuth2TokenConfig | undefined =>
};
}
+ tokenConfig.source = oauth.tokenSource || 'access_token';
+
return Object.keys(tokenConfig).length > 0 ? tokenConfig : undefined;
};
@@ -345,6 +347,7 @@ export const toBrunoOAuth2 = (oauth: AuthOAuth2 | null | undefined): BrunoOAuth2
tokenPlacement: null,
tokenHeaderPrefix: null,
tokenQueryKey: null,
+ tokenSource: 'access_token',
refreshTokenUrl: null,
autoRefreshToken: false, // Default to false
autoFetchToken: true, // Default to true
@@ -363,6 +366,7 @@ export const toBrunoOAuth2 = (oauth: AuthOAuth2 | null | undefined): BrunoOAuth2
// token config
if (oauth.tokenConfig?.id) brunoOAuth.credentialsId = oauth.tokenConfig.id;
+ if (oauth.tokenConfig?.source) brunoOAuth.tokenSource = oauth.tokenConfig.source || 'access_token';
if (oauth.tokenConfig?.placement) {
if ('header' in oauth.tokenConfig.placement) {
brunoOAuth.tokenPlacement = 'header';
@@ -408,6 +412,7 @@ export const toBrunoOAuth2 = (oauth: AuthOAuth2 | null | undefined): BrunoOAuth2
// token config
if (oauth.tokenConfig?.id) brunoOAuth.credentialsId = oauth.tokenConfig.id;
+ if (oauth.tokenConfig?.source) brunoOAuth.tokenSource = oauth.tokenConfig.source || 'access_token';
if (oauth.tokenConfig?.placement) {
if ('header' in oauth.tokenConfig.placement) {
brunoOAuth.tokenPlacement = 'header';
@@ -454,6 +459,7 @@ export const toBrunoOAuth2 = (oauth: AuthOAuth2 | null | undefined): BrunoOAuth2
// token config
if (oauth.tokenConfig?.id) brunoOAuth.credentialsId = oauth.tokenConfig.id;
+ if (oauth.tokenConfig?.source) brunoOAuth.tokenSource = oauth.tokenConfig.source || 'access_token';
if (oauth.tokenConfig?.placement) {
if ('header' in oauth.tokenConfig.placement) {
brunoOAuth.tokenPlacement = 'header';
@@ -502,6 +508,7 @@ export const toBrunoOAuth2 = (oauth: AuthOAuth2 | null | undefined): BrunoOAuth2
// token config
if (oauth.tokenConfig?.id) brunoOAuth.credentialsId = oauth.tokenConfig.id;
+ if (oauth.tokenConfig?.source) brunoOAuth.tokenSource = oauth.tokenConfig.source || 'access_token';
if (oauth.tokenConfig?.placement) {
if ('header' in oauth.tokenConfig.placement) {
brunoOAuth.tokenPlacement = 'header';
diff --git a/packages/bruno-lang/v2/src/bruToJson.js b/packages/bruno-lang/v2/src/bruToJson.js
index 0538cc048..710197e39 100644
--- a/packages/bruno-lang/v2/src/bruToJson.js
+++ b/packages/bruno-lang/v2/src/bruToJson.js
@@ -731,6 +731,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
const tokenQueryKeyKey = _.find(auth, { name: 'token_query_key' });
const autoFetchTokenKey = _.find(auth, { name: 'auto_fetch_token' });
const autoRefreshTokenKey = _.find(auth, { name: 'auto_refresh_token' });
+ const tokenSourceKey = _.find(auth, { name: 'token_source' });
return {
auth: {
oauth2:
@@ -746,6 +747,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
scope: scopeKey ? scopeKey.value : '',
credentialsPlacement: credentialsPlacementKey?.value ? credentialsPlacementKey.value : 'body',
credentialsId: credentialsIdKey?.value ? credentialsIdKey.value : 'credentials',
+ tokenSource: tokenSourceKey?.value ? tokenSourceKey.value : 'access_token',
tokenPlacement: tokenPlacementKey?.value ? tokenPlacementKey.value : 'header',
tokenHeaderPrefix: tokenHeaderPrefixKey?.value ? tokenHeaderPrefixKey.value : '',
tokenQueryKey: tokenQueryKeyKey?.value ? tokenQueryKeyKey.value : 'access_token',
@@ -766,6 +768,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
pkce: pkceKey ? safeParseJson(pkceKey?.value) ?? false : false,
credentialsPlacement: credentialsPlacementKey?.value ? credentialsPlacementKey.value : 'body',
credentialsId: credentialsIdKey?.value ? credentialsIdKey.value : 'credentials',
+ tokenSource: tokenSourceKey?.value ? tokenSourceKey.value : 'access_token',
tokenPlacement: tokenPlacementKey?.value ? tokenPlacementKey.value : 'header',
tokenHeaderPrefix: tokenHeaderPrefixKey?.value ? tokenHeaderPrefixKey.value : '',
tokenQueryKey: tokenQueryKeyKey?.value ? tokenQueryKeyKey.value : 'access_token',
@@ -782,6 +785,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
scope: scopeKey ? scopeKey.value : '',
credentialsPlacement: credentialsPlacementKey?.value ? credentialsPlacementKey.value : 'body',
credentialsId: credentialsIdKey?.value ? credentialsIdKey.value : 'credentials',
+ tokenSource: tokenSourceKey?.value ? tokenSourceKey.value : 'access_token',
tokenPlacement: tokenPlacementKey?.value ? tokenPlacementKey.value : 'header',
tokenHeaderPrefix: tokenHeaderPrefixKey?.value ? tokenHeaderPrefixKey.value : '',
tokenQueryKey: tokenQueryKeyKey?.value ? tokenQueryKeyKey.value : 'access_token',
@@ -797,6 +801,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
scope: scopeKey ? scopeKey.value : '',
state: stateKey ? stateKey.value : '',
credentialsId: credentialsIdKey?.value ? credentialsIdKey.value : 'credentials',
+ tokenSource: tokenSourceKey?.value ? tokenSourceKey.value : 'access_token',
tokenPlacement: tokenPlacementKey?.value ? tokenPlacementKey.value : 'header',
tokenHeaderPrefix: tokenHeaderPrefixKey?.value ? tokenHeaderPrefixKey.value : '',
tokenQueryKey: tokenQueryKeyKey?.value ? tokenQueryKeyKey.value : 'access_token',
diff --git a/packages/bruno-lang/v2/src/collectionBruToJson.js b/packages/bruno-lang/v2/src/collectionBruToJson.js
index 8fe6eced4..2c4ec492a 100644
--- a/packages/bruno-lang/v2/src/collectionBruToJson.js
+++ b/packages/bruno-lang/v2/src/collectionBruToJson.js
@@ -344,6 +344,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
const tokenQueryKeyKey = _.find(auth, { name: 'token_query_key' });
const autoFetchTokenKey = _.find(auth, { name: 'auto_fetch_token' });
const autoRefreshTokenKey = _.find(auth, { name: 'auto_refresh_token' });
+ const tokenSourceKey = _.find(auth, { name: 'token_source' });
return {
auth: {
oauth2:
@@ -359,6 +360,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
scope: scopeKey ? scopeKey.value : '',
credentialsPlacement: credentialsPlacementKey?.value ? credentialsPlacementKey.value : 'body',
credentialsId: credentialsIdKey?.value ? credentialsIdKey.value : 'credentials',
+ tokenSource: tokenSourceKey?.value ? tokenSourceKey.value : 'access_token',
tokenPlacement: tokenPlacementKey?.value ? tokenPlacementKey.value : 'header',
tokenHeaderPrefix: tokenHeaderPrefixKey?.value ? tokenHeaderPrefixKey.value : '',
tokenQueryKey: tokenQueryKeyKey?.value ? tokenQueryKeyKey.value : 'access_token',
@@ -379,6 +381,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
pkce: pkceKey ? safeParseJson(pkceKey?.value) ?? false : false,
credentialsPlacement: credentialsPlacementKey?.value ? credentialsPlacementKey.value : 'body',
credentialsId: credentialsIdKey?.value ? credentialsIdKey.value : 'credentials',
+ tokenSource: tokenSourceKey?.value ? tokenSourceKey.value : 'access_token',
tokenPlacement: tokenPlacementKey?.value ? tokenPlacementKey.value : 'header',
tokenHeaderPrefix: tokenHeaderPrefixKey?.value ? tokenHeaderPrefixKey.value : '',
tokenQueryKey: tokenQueryKeyKey?.value ? tokenQueryKeyKey.value : 'access_token',
@@ -394,6 +397,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
scope: scopeKey ? scopeKey.value : '',
state: stateKey ? stateKey.value : '',
credentialsId: credentialsIdKey?.value ? credentialsIdKey.value : 'credentials',
+ tokenSource: tokenSourceKey?.value ? tokenSourceKey.value : 'access_token',
tokenPlacement: tokenPlacementKey?.value ? tokenPlacementKey.value : 'header',
tokenHeaderPrefix: tokenHeaderPrefixKey?.value ? tokenHeaderPrefixKey.value : '',
tokenQueryKey: tokenQueryKeyKey?.value ? tokenQueryKeyKey.value : 'access_token',
@@ -409,6 +413,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
scope: scopeKey ? scopeKey.value : '',
credentialsPlacement: credentialsPlacementKey?.value ? credentialsPlacementKey.value : 'body',
credentialsId: credentialsIdKey?.value ? credentialsIdKey.value : 'credentials',
+ tokenSource: tokenSourceKey?.value ? tokenSourceKey.value : 'access_token',
tokenPlacement: tokenPlacementKey?.value ? tokenPlacementKey.value : 'header',
tokenHeaderPrefix: tokenHeaderPrefixKey?.value ? tokenHeaderPrefixKey.value : '',
tokenQueryKey: tokenQueryKeyKey?.value ? tokenQueryKeyKey.value : 'access_token',
diff --git a/packages/bruno-lang/v2/src/jsonToBru.js b/packages/bruno-lang/v2/src/jsonToBru.js
index 420ca90d7..3add8aff2 100644
--- a/packages/bruno-lang/v2/src/jsonToBru.js
+++ b/packages/bruno-lang/v2/src/jsonToBru.js
@@ -268,6 +268,7 @@ ${indentString(`client_secret: ${auth?.oauth2?.clientSecret || ''}`)}
${indentString(`scope: ${auth?.oauth2?.scope || ''}`)}
${indentString(`credentials_placement: ${auth?.oauth2?.credentialsPlacement || ''}`)}
${indentString(`credentials_id: ${auth?.oauth2?.credentialsId || ''}`)}
+${indentString(`token_source: ${auth?.oauth2?.tokenSource || 'access_token'}`)}
${indentString(`token_placement: ${auth?.oauth2?.tokenPlacement || ''}`)}${
auth?.oauth2?.tokenPlacement == 'header' ? '\n' + indentString(`token_header_prefix: ${auth?.oauth2?.tokenHeaderPrefix || ''}`) : ''
}${
@@ -293,6 +294,7 @@ ${indentString(`state: ${auth?.oauth2?.state || ''}`)}
${indentString(`pkce: ${(auth?.oauth2?.pkce || false).toString()}`)}
${indentString(`credentials_placement: ${auth?.oauth2?.credentialsPlacement || ''}`)}
${indentString(`credentials_id: ${auth?.oauth2?.credentialsId || ''}`)}
+${indentString(`token_source: ${auth?.oauth2?.tokenSource || 'access_token'}`)}
${indentString(`token_placement: ${auth?.oauth2?.tokenPlacement || ''}`)}${
auth?.oauth2?.tokenPlacement == 'header' ? '\n' + indentString(`token_header_prefix: ${auth?.oauth2?.tokenHeaderPrefix || ''}`) : ''
}${
@@ -314,6 +316,7 @@ ${indentString(`client_secret: ${auth?.oauth2?.clientSecret || ''}`)}
${indentString(`scope: ${auth?.oauth2?.scope || ''}`)}
${indentString(`credentials_placement: ${auth?.oauth2?.credentialsPlacement || ''}`)}
${indentString(`credentials_id: ${auth?.oauth2?.credentialsId || ''}`)}
+${indentString(`token_source: ${auth?.oauth2?.tokenSource || 'access_token'}`)}
${indentString(`token_placement: ${auth?.oauth2?.tokenPlacement || ''}`)}${
auth?.oauth2?.tokenPlacement == 'header' ? '\n' + indentString(`token_header_prefix: ${auth?.oauth2?.tokenHeaderPrefix || ''}`) : ''
}${
@@ -334,6 +337,7 @@ ${indentString(`client_id: ${auth?.oauth2?.clientId || ''}`)}
${indentString(`scope: ${auth?.oauth2?.scope || ''}`)}
${indentString(`state: ${auth?.oauth2?.state || ''}`)}
${indentString(`credentials_id: ${auth?.oauth2?.credentialsId || ''}`)}
+${indentString(`token_source: ${auth?.oauth2?.tokenSource || 'access_token'}`)}
${indentString(`token_placement: ${auth?.oauth2?.tokenPlacement || ''}`)}${
auth?.oauth2?.tokenPlacement == 'header' ? '\n' + indentString(`token_header_prefix: ${auth?.oauth2?.tokenHeaderPrefix || ''}`) : ''
}${
diff --git a/packages/bruno-lang/v2/src/jsonToCollectionBru.js b/packages/bruno-lang/v2/src/jsonToCollectionBru.js
index cc5428996..41301cc52 100644
--- a/packages/bruno-lang/v2/src/jsonToCollectionBru.js
+++ b/packages/bruno-lang/v2/src/jsonToCollectionBru.js
@@ -157,6 +157,7 @@ ${indentString(`client_secret: ${auth?.oauth2?.clientSecret || ''}`)}
${indentString(`scope: ${auth?.oauth2?.scope || ''}`)}
${indentString(`credentials_placement: ${auth?.oauth2?.credentialsPlacement || ''}`)}
${indentString(`credentials_id: ${auth?.oauth2?.credentialsId || ''}`)}
+${indentString(`token_source: ${auth?.oauth2?.tokenSource || 'access_token'}`)}
${indentString(`token_placement: ${auth?.oauth2?.tokenPlacement || ''}`)}${
auth?.oauth2?.tokenPlacement == 'header' ? '\n' + indentString(`token_header_prefix: ${auth?.oauth2?.tokenHeaderPrefix || ''}`) : ''
}${
@@ -182,6 +183,7 @@ ${indentString(`state: ${auth?.oauth2?.state || ''}`)}
${indentString(`pkce: ${(auth?.oauth2?.pkce || false).toString()}`)}
${indentString(`credentials_placement: ${auth?.oauth2?.credentialsPlacement || ''}`)}
${indentString(`credentials_id: ${auth?.oauth2?.credentialsId || ''}`)}
+${indentString(`token_source: ${auth?.oauth2?.tokenSource || 'access_token'}`)}
${indentString(`token_placement: ${auth?.oauth2?.tokenPlacement || ''}`)}${
auth?.oauth2?.tokenPlacement == 'header' ? '\n' + indentString(`token_header_prefix: ${auth?.oauth2?.tokenHeaderPrefix || ''}`) : ''
}${
@@ -202,6 +204,7 @@ ${indentString(`client_id: ${auth?.oauth2?.clientId || ''}`)}
${indentString(`scope: ${auth?.oauth2?.scope || ''}`)}
${indentString(`state: ${auth?.oauth2?.state || ''}`)}
${indentString(`credentials_id: ${auth?.oauth2?.credentialsId || ''}`)}
+${indentString(`token_source: ${auth?.oauth2?.tokenSource || 'access_token'}`)}
${indentString(`token_placement: ${auth?.oauth2?.tokenPlacement || ''}`)}${
auth?.oauth2?.tokenPlacement == 'header' ? '\n' + indentString(`token_header_prefix: ${auth?.oauth2?.tokenHeaderPrefix || ''}`) : ''
}${
@@ -222,6 +225,7 @@ ${indentString(`client_secret: ${auth?.oauth2?.clientSecret || ''}`)}
${indentString(`scope: ${auth?.oauth2?.scope || ''}`)}
${indentString(`credentials_placement: ${auth?.oauth2?.credentialsPlacement || ''}`)}
${indentString(`credentials_id: ${auth?.oauth2?.credentialsId || ''}`)}
+${indentString(`token_source: ${auth?.oauth2?.tokenSource || 'access_token'}`)}
${indentString(`token_placement: ${auth?.oauth2?.tokenPlacement || ''}`)}${
auth?.oauth2?.tokenPlacement == 'header' ? '\n' + indentString(`token_header_prefix: ${auth?.oauth2?.tokenHeaderPrefix || ''}`) : ''
}${
diff --git a/packages/bruno-lang/v2/tests/examples/fixtures/bru/oauth2-examples.bru b/packages/bruno-lang/v2/tests/examples/fixtures/bru/oauth2-examples.bru
index 1b0e77097..b88aeb3eb 100644
--- a/packages/bruno-lang/v2/tests/examples/fixtures/bru/oauth2-examples.bru
+++ b/packages/bruno-lang/v2/tests/examples/fixtures/bru/oauth2-examples.bru
@@ -27,6 +27,7 @@ auth:oauth2 {
pkce: true
credentials_placement: header
credentials_id: authorization
+ token_source: access_token
token_placement: header
token_header_prefix: Bearer
auto_fetch_token: true
diff --git a/packages/bruno-lang/v2/tests/examples/fixtures/json/oauth2-examples.json b/packages/bruno-lang/v2/tests/examples/fixtures/json/oauth2-examples.json
index 9b625908a..58fbade63 100644
--- a/packages/bruno-lang/v2/tests/examples/fixtures/json/oauth2-examples.json
+++ b/packages/bruno-lang/v2/tests/examples/fixtures/json/oauth2-examples.json
@@ -31,6 +31,7 @@
"pkce": true,
"credentialsPlacement": "header",
"credentialsId": "authorization",
+ "tokenSource": "access_token",
"tokenPlacement": "header",
"tokenHeaderPrefix": "Bearer",
"tokenQueryKey": "access_token",
diff --git a/packages/bruno-lang/v2/tests/fixtures/request.bru b/packages/bruno-lang/v2/tests/fixtures/request.bru
index c10982f6e..3bb33bb15 100644
--- a/packages/bruno-lang/v2/tests/fixtures/request.bru
+++ b/packages/bruno-lang/v2/tests/fixtures/request.bru
@@ -81,6 +81,7 @@ auth:oauth2 {
pkce: false
credentials_placement: body
credentials_id: credentials
+ token_source: access_token
token_placement: header
token_header_prefix: Bearer
auto_fetch_token: true
diff --git a/packages/bruno-lang/v2/tests/fixtures/request.json b/packages/bruno-lang/v2/tests/fixtures/request.json
index 86cb48e5d..bc5218ece 100644
--- a/packages/bruno-lang/v2/tests/fixtures/request.json
+++ b/packages/bruno-lang/v2/tests/fixtures/request.json
@@ -141,6 +141,7 @@
"clientId": "client_id_1",
"clientSecret": "client_secret_1",
"credentialsId": "credentials",
+ "tokenSource": "access_token",
"credentialsPlacement": "body",
"grantType": "authorization_code",
"pkce": false,
diff --git a/packages/bruno-requests/src/auth/oauth2-helper.ts b/packages/bruno-requests/src/auth/oauth2-helper.ts
index d398694ce..de37e43ee 100644
--- a/packages/bruno-requests/src/auth/oauth2-helper.ts
+++ b/packages/bruno-requests/src/auth/oauth2-helper.ts
@@ -27,6 +27,7 @@ export interface OAuth2Config {
credentialsId?: string;
autoRefreshToken?: boolean;
autoFetchToken?: boolean;
+ tokenSource?: 'access_token' | 'id_token';
additionalParameters?: {
token?: AdditionalParameter[];
};
@@ -320,7 +321,8 @@ export const getOAuth2Token = async (oauth2Config: OAuth2Config, tokenStore: Tok
grantType,
accessTokenUrl,
credentialsId = 'default',
- autoFetchToken = true
+ autoFetchToken = true,
+ tokenSource = 'access_token'
} = oauth2Config;
if (verbose) {
@@ -346,7 +348,7 @@ export const getOAuth2Token = async (oauth2Config: OAuth2Config, tokenStore: Tok
// Check if token is expired
if (!isTokenExpired(existingToken)) {
// Token is valid, use it
- return existingToken.access_token;
+ return tokenSource === 'id_token' ? existingToken.id_token : existingToken.access_token;
} else {
// Token is expired
if (autoFetchToken) {
@@ -354,7 +356,7 @@ export const getOAuth2Token = async (oauth2Config: OAuth2Config, tokenStore: Tok
await tokenStore.deleteCredential({ url: accessTokenUrl, credentialsId });
} else {
// Return expired token if autoFetchToken is disabled
- return existingToken.access_token;
+ return tokenSource === 'id_token' ? existingToken.id_token : existingToken.access_token;
}
}
} else {
@@ -393,5 +395,5 @@ export const getOAuth2Token = async (oauth2Config: OAuth2Config, tokenStore: Tok
console.warn('OAuth2: Failed to save token to store, but proceeding with token');
}
- return tokenResponse.access_token;
+ return tokenSource === 'id_token' ? tokenResponse.id_token : tokenResponse.access_token;
};
diff --git a/packages/bruno-schema-types/src/common/auth.ts b/packages/bruno-schema-types/src/common/auth.ts
index b620d64b3..c8a31499b 100644
--- a/packages/bruno-schema-types/src/common/auth.ts
+++ b/packages/bruno-schema-types/src/common/auth.ts
@@ -77,6 +77,7 @@ export interface OAuth2 {
refreshTokenUrl?: string | null;
autoRefreshToken?: boolean | null;
autoFetchToken?: boolean | null;
+ tokenSource?: 'access_token' | 'id_token';
additionalParameters?: OAuthAdditionalParameters | null;
}
diff --git a/packages/bruno-schema/src/collections/index.js b/packages/bruno-schema/src/collections/index.js
index 92787067c..a2f35abb9 100644
--- a/packages/bruno-schema/src/collections/index.js
+++ b/packages/bruno-schema/src/collections/index.js
@@ -285,6 +285,11 @@ const oauth2Schema = Yup.object({
then: Yup.string().nullable(),
otherwise: Yup.string().nullable().strip()
}),
+ tokenSource: Yup.string().when('grantType', {
+ is: (val) => ['client_credentials', 'password', 'authorization_code', 'implicit'].includes(val),
+ then: Yup.string().oneOf(['access_token', 'id_token']).optional(),
+ otherwise: Yup.string().optional().strip()
+ }),
tokenPlacement: Yup.string().when('grantType', {
is: (val) => ['client_credentials', 'password', 'authorization_code', 'implicit'].includes(val),
then: Yup.string().nullable(),