Skip to content

Commit

Permalink
UID2: support Client-side token generation and build tag (#10510)
Browse files Browse the repository at this point in the history
* Add CSTG to common module

* Add generateToken calls

* Fix bug

* Use async function and clean up code

* Update xhrrequest to ajax

* Add try catch

* refactor

* add tests

* Fix tests after change to ajax

* Add new test cases for stored token expired

* Address feedbacks

* Add new test cases

* Using ramdom token instead

* Add tests for cstg-derived and non-cstg-derived token

* Store hashed identity instead of original DII

* Remove  X-UID2-Client-Version

* kick off integration tests

* kick off tests

* Add console log to debug integration tests

* Test action delay

* Mock window.crypto.subtle.digest

* Fix window.crypto.subtle.digest in firefox

* Decouple cstg

* Move uid2Cstg out

* Wrap cstg with feature flag

* Fix formatting

* Remove export

* Add cstg enabled check

* Fix tests

* Remove clientId

* wrap test with feature flag

* cleanup

* cleanup

* cleanup example

* add refresh token

* change back to const

* Fix tests

* restore pacakge lock

* Restore test files

* Add more tests

* Fix normalize email bug

* remove redundant condition

---------

Co-authored-by: Chris Huie <phoenixtechnerd@gmail.com>
  • Loading branch information
jingyi-gao-ttd and ChrisHuie authored Oct 23, 2023
1 parent db9d236 commit d0e981b
Show file tree
Hide file tree
Showing 6 changed files with 904 additions and 70 deletions.
3 changes: 2 additions & 1 deletion features.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[
"NATIVE",
"VIDEO"
"VIDEO",
"UID2_CSTG"
]
23 changes: 22 additions & 1 deletion modules/uid2IdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { logInfo, logWarn } from '../src/utils.js';
import {submodule} from '../src/hook.js';
import { submodule } from '../src/hook.js';
import {getStorageManager} from '../src/storageManager.js';
import {MODULE_TYPE_UID} from '../src/activities/modules.js';

Expand All @@ -33,6 +33,19 @@ function createLogger(logger, prefix) {
logger(prefix + ' ', ...strings);
}
}

function extractIdentityFromParams(params) {
const keysToCheck = ['emailHash', 'phoneHash', 'email', 'phone'];

for (let key of keysToCheck) {
if (params.hasOwnProperty(key)) {
return { [key]: params[key] };
}
}

return {};
}

const _logInfo = createLogger(logInfo, LOG_PRE_FIX);
const _logWarn = createLogger(logWarn, LOG_PRE_FIX);

Expand Down Expand Up @@ -79,6 +92,14 @@ export const uid2IdSubmodule = {
clientId: UID2_CLIENT_ID,
internalStorage: ADVERTISING_COOKIE
}

if (FEATURES.UID2_CSTG) {
mappedConfig.cstg = {
serverPublicKey: config?.params?.serverPublicKey,
subscriptionId: config?.params?.subscriptionId,
...extractIdentityFromParams(config?.params ?? {})
}
}
_logInfo(`UID2 configuration loaded and mapped.`, mappedConfig);
const result = Uid2GetId(mappedConfig, storage, _logInfo, _logWarn);
_logInfo(`UID2 getId returned`, result);
Expand Down
Loading

0 comments on commit d0e981b

Please sign in to comment.