Skip to content

Commit ff73c1e

Browse files
add optout functionality for server-side
1 parent be5b234 commit ff73c1e

File tree

5 files changed

+45
-30
lines changed

5 files changed

+45
-30
lines changed

docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ services:
3131
env_file:
3232
- .env
3333

34+
google-secure-signals-server-side:
35+
build:
36+
context: .
37+
dockerfile: web-integrations/google-secure-signals/server-side/Dockerfile
38+
ports:
39+
- "3042:3042"
40+
container_name: google-secure-signals-server-side
41+
env_file:
42+
- .env
43+
3444
# prebid integrations
3545
prebid-client:
3646
build:
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
FROM node:20.11-alpine3.18
2-
WORKDIR /app
3-
COPY . .
1+
FROM node:20.11.0-alpine3.18
2+
3+
WORKDIR /usr/src/app
4+
5+
# Copy package files first for better caching
6+
COPY web-integrations/google-secure-signals/server-side/package*.json ./
47
RUN npm install
58

6-
RUN apk add --no-cache gettext
7-
RUN mv public/ads.js public/ads.js.template
8-
CMD /bin/sh -c "envsubst < public/ads.js.template > public/ads.js && npm start"
9+
# Copy application files
10+
COPY web-integrations/google-secure-signals/server-side/server.js ./
11+
COPY web-integrations/google-secure-signals/server-side/public ./public/
12+
COPY web-integrations/google-secure-signals/server-side/views ./views/
913

10-
EXPOSE 3000
14+
EXPOSE 3042
15+
CMD ["npm", "start"]

web-integrations/google-secure-signals/server-side/server.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const nocache = require('nocache');
88
const crypto = require('crypto');
99

1010
const app = express();
11-
const port = process.env.PORT || 3000;
11+
const port = process.env.PORT || 3042;
1212

1313
const uid2BaseUrl = process.env.UID2_BASE_URL;
1414
const uid2ApiKey = process.env.UID2_API_KEY;
@@ -207,7 +207,9 @@ function _GenerateTokenV1(req, res) {
207207
headers: { Authorization: 'Bearer ' + uid2ApiKey },
208208
})
209209
.then((response) => {
210-
if (response.data.status !== 'success') {
210+
if (response.data.status === 'optout') {
211+
res.render('optout');
212+
} else if (response.data.status !== 'success') {
211213
res.render('error', {
212214
error: 'Got unexpected token generate status: ' + response.data.status,
213215
response: response,
@@ -246,7 +248,9 @@ app.post('/login', async (req, res) => {
246248
); //if HTTP response code is not 200, this throws and is caught in the catch handler below.
247249
const response = decrypt(encryptedResponse.data, uid2ClientSecret, false, nonce);
248250

249-
if (response.status !== 'success') {
251+
if (response.status === 'optout') {
252+
res.render('optout');
253+
} else if (response.status !== 'success') {
250254
res.render('error', {
251255
error: 'Got unexpected token generate status in decrypted response: ' + response.status,
252256
response: response,
Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<%- include('header.html'); -%>
2-
<form action="/login" method="POST" id="loginForm">
2+
<form action="/login" method="POST">
33
<div class="email_prompt">
44
<input
55
type="text"
@@ -11,23 +11,4 @@
1111
</div>
1212
<div><input type="submit" value="Generate UID2" class="button" /></div>
1313
</form>
14-
<script>
15-
document.forms['loginForm'].addEventListener('submit', (event) => {
16-
event.preventDefault();
17-
fetch(event.target.action, {
18-
method: 'POST',
19-
body: new URLSearchParams(new FormData(event.target)),
20-
}).then((response) => {
21-
if (!response.ok) {
22-
throw new Error(`HTTP error! Status: ${response.status}`);
23-
}
24-
window.googletag = window.googletag || { cmd: [] };
25-
window.googletag.cmd.push(function () {
26-
window.googletag.secureSignalProviders = window.googletag.secureSignalProviders || [];
27-
window.googletag.secureSignalProviders.clearAllCache();
28-
});
29-
window.location.replace('/');
30-
});
31-
});
32-
</script>
3314
<%- include('footer.html'); -%>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<%- include('header.html'); -%>
2+
<div class="optout-message">
3+
<h2>This email has opted out</h2>
4+
<p>
5+
The email address you entered has opted out of UID2. No UID2 token can be generated for this
6+
email.
7+
</p>
8+
<p>
9+
For testing purposes, you can try with a different email address, such as
10+
<strong>[email protected]</strong>.
11+
</p>
12+
<p><a href="/login" class="button">Try Another Email</a></p>
13+
</div>
14+
<%- include('footer.html'); -%>
15+

0 commit comments

Comments
 (0)