Skip to content

Commit 47baea4

Browse files
authored
feat: add sdk log auth header (#1175)
1 parent 17b7c71 commit 47baea4

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/utils/logger.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ZalgoPromise } from '@krakenjs/zalgo-promise/src';
88
import { getGlobalUrl } from './global';
99
import { request } from './miscellaneous';
1010

11-
import { getLibraryVersion, getDisableSetCookie } from './sdk';
11+
import { getLibraryVersion, getDisableSetCookie, getClientId } from './sdk';
1212

1313
function generateLogPayload(account, { meta, events: bizEvents, tracking }) {
1414
const { deviceID, sessionID, integration_type, messaging_version, globalSessionID } = meta.global ?? {};
@@ -174,6 +174,18 @@ export const logger = Logger({
174174
? `${url}?disableSetCookie=true&features=disable-set-cookie`
175175
: url;
176176

177+
// Send authorization header with tracking event
178+
if (__MESSAGES__.__TARGET__ === 'SDK') {
179+
const encodedClientId = btoa(getClientId());
180+
// eslint-disable-next-line no-param-reassign
181+
headers.Authorization = `Basic ${encodedClientId}`;
182+
}
183+
if (__MESSAGES__.__TARGET__ === 'STANDALONE' || __MESSAGES__.__TARGET__ === 'STANDALONE_MODAL') {
184+
const encodedPayerId = btoa(trimmedMeta['1'].account);
185+
// eslint-disable-next-line no-param-reassign
186+
headers.Authorization = `Basic ${encodedPayerId}`;
187+
}
188+
177189
return ZalgoPromise.all(
178190
translateLogData(trimmedLog).map(data => {
179191
return request(method, urlWithCookieParams, {

src/utils/sdk.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ export function getAccount() {
7272
return undefined;
7373
}
7474
}
75+
76+
export function getClientId() {
77+
if (__MESSAGES__.__TARGET__ === 'SDK') {
78+
return getClientID();
79+
} else {
80+
return undefined;
81+
}
82+
}
83+
7584
export function getPageType() {
7685
if (__MESSAGES__.__TARGET__ === 'SDK') {
7786
return getSDKPageType();

0 commit comments

Comments
 (0)