Skip to content

Commit

Permalink
[gh-#1168] inject shopify accessToken into the header (#1184)
Browse files Browse the repository at this point in the history
  • Loading branch information
khaliqgant authored Oct 25, 2023
1 parent 4e87480 commit 7ff9df6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/server/lib/controllers/proxy.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,10 @@ See https://docs.nango.dev/guides/proxy#proxy-requests for more information.`
if ('proxy' in config.template && 'headers' in config.template.proxy) {
headers = Object.entries(config.template.proxy.headers).reduce(
(acc: Record<string, string>, [key, value]: [string, string]) => {
acc[key] = interpolateIfNeeded(value, config.token as unknown as Record<string, string>);
// allows oauth2 acessToken key to be interpolated and injected
// into the header in addition to api key values
const tokenPair = config.template.auth_mode === AuthModes.OAuth2 ? { accessToken: config.token } : config.token;
acc[key] = interpolateIfNeeded(value, tokenPair as unknown as Record<string, string>);
return acc;
},
{ ...headers }
Expand Down
22 changes: 22 additions & 0 deletions packages/server/lib/controllers/proxy.controller.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,28 @@ describe('Proxy Controller Construct Header Tests', () => {
});
});

it('Should correctly insert headers with dynamic values for oauth', () => {
const config = {
template: {
auth_mode: 'OAUTH2',
proxy: {
headers: {
'X-Access-Token': '${accessToken}'
}
}
},
token: 'some-oauth-access-token'
};

// @ts-ignore
const result = proxyController.constructHeaders(config);

expect(result).toEqual({
Authorization: 'Bearer some-oauth-access-token',
'X-Access-Token': 'some-oauth-access-token'
});
});

it('Should correctly merge provided headers', () => {
const config = {
template: {
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/providers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,8 @@ shopify:
token_url: https://${connectionConfig.subdomain}.myshopify.com/admin/oauth/access_token
proxy:
base_url: https://${connectionConfig.subdomain}.myshopify.com
headers:
X-Shopify-Access-Token: ${accessToken}
shortcut:
auth_mode: API_KEY
proxy:
Expand Down

0 comments on commit 7ff9df6

Please # to comment.