Skip to content

Commit e4ba449

Browse files
update storage token key to become environment variable
1 parent 95e56bf commit e4ba449

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

.env.sample

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ UID2_CSTG_SUBSCRIPTION_ID="DMr7uHxqLU"
88
UID2_API_KEY="your-api-key"
99
UID2_CLIENT_SECRET="your-client-secret"
1010
UID2_JS_SDK_URL="https://cdn.integ.uidapi.com/uid2-sdk-4.0.1.js"
11-
UID2_JS_SDK_NAME="__uid2"
11+
UID2_JS_SDK_NAME="__uid2"
12+
UID2_STORAGE_KEY="__uid2_advertising_token"

web-integrations/prebid-integrations/client-server/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ Enter an opted-out email and click "Generate UID2".
172172
| `UID2_BASE_URL` | The UID2 Operator endpoint. Use `http://localhost:8080` for local or the integration URL. | `http://localhost:8080` |
173173
| `UID2_API_KEY` | Your UID2 API key with GENERATOR role. | `UID2-C-L-124-H8VwqX...` |
174174
| `UID2_CLIENT_SECRET` | Your UID2 client secret. | `NcMgi6Y8C80SlxvV7pYlfcvEIo+2b0508...` |
175+
| `UID2_STORAGE_KEY` | Your localStorage key for storing UID2 tokens. | `__uid2_advertising_token` |
175176

176177
**Note:** For Docker, use `http://host.docker.internal:8080` instead of `http://localhost:8080` to access services on your host machine.
177178

web-integrations/prebid-integrations/client-server/public/index.html

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<script>
1010
console.log('Initializing example.');
1111

12-
const UID2_STORAGE_KEY = '__uid2_advertising_token';
12+
let UID2_STORAGE_KEY = '__uid2_advertising_token'; // Default, will be loaded from server config
1313
let currentIdentity = null;
1414

1515
// Initialize Prebid.js queue if not already present
@@ -137,6 +137,17 @@
137137
location.reload();
138138
}
139139

140+
async function loadConfig() {
141+
try {
142+
const response = await fetch('/config');
143+
const config = await response.json();
144+
UID2_STORAGE_KEY = config.storageKey;
145+
console.log('Loaded config from server, storage key:', UID2_STORAGE_KEY);
146+
} catch (error) {
147+
console.log('Failed to load config from server, using default storage key');
148+
}
149+
}
150+
140151
function loadStoredIdentity() {
141152
const storedToken = localStorage.getItem(UID2_STORAGE_KEY);
142153
if (storedToken) {
@@ -154,9 +165,11 @@
154165
}
155166
}
156167

157-
function onDocumentReady() {
168+
async function onDocumentReady() {
158169
console.log('Setting up interface handlers.');
159170

171+
await loadConfig();
172+
160173
$('#login').click(handleLogin);
161174
$('#clear_storage').click(handleClearStorage);
162175

web-integrations/prebid-integrations/client-server/server.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const port = 3052;
1414
const uid2BaseUrl = process.env.UID2_BASE_URL || 'https://operator-integ.uidapi.com';
1515
const uid2ApiKey = process.env.UID2_API_KEY;
1616
const uid2ClientSecret = process.env.UID2_CLIENT_SECRET;
17+
const uid2StorageKey = process.env.UID2_STORAGE_KEY || '__uid2_advertising_token';
1718

1819
// Encryption constants
1920
const ivLength = 12;
@@ -95,9 +96,14 @@ function createEnvelope(payload) {
9596
}
9697

9798
// ============================================================================
98-
// API Endpoint
99+
// API Endpoints
99100
// ============================================================================
100101

102+
// GET /config - Returns client configuration
103+
app.get('/config', (req, res) => {
104+
res.json({ storageKey: uid2StorageKey });
105+
});
106+
101107
// POST /login - Generates UID2 token for email address
102108
app.post('/login', async (req, res) => {
103109
const jsonEmail = JSON.stringify({ email: req.body.email });

0 commit comments

Comments
 (0)