Skip to content

Commit 1e3429d

Browse files
authored
Merge pull request #142 from IABTechLab/sas-UID2-6301-samples-pages-integ
Sas UI d2 6301 samples pages integ
2 parents 8954264 + 95260f7 commit 1e3429d

File tree

14 files changed

+533
-213
lines changed

14 files changed

+533
-213
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@
44

55
# Node.js
66
node_modules/
7-
**/node_modules/
7+
**/node_modules/
8+
9+
# Local SSL certificates (generated by npm run createCA)
10+
ca/

README.md

Lines changed: 67 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,104 @@
11
# UID2 Integration Examples
22

3-
The [UID2 framework](https://unifiedid.com/docs/intro) enables publishers to integrate in either of the following ways:
3+
Sample sites demonstrating UID2/EUID integration patterns.
44

5-
- Via the standard integration workflow, using the [UID2 SDK for JavaScript](https://unifiedid.com/docs/sdks/client-side-identity) (also known as the UID2 SDK).
6-
- Via the server-only (custom) integration workflow, by building a direct integration without using the UID2 SDK.
5+
## Prerequisites
76

8-
If you are a content publisher interested in generating UID2 tokens for the real-time bidding (RTB) bid stream and want to see how you can use the UID2 services and which integration fits your needs best, you can build and run an example application for each integration.
7+
### 1. Set Up Environment Variables
98

10-
The following table summarizes both examples and provides links to the example applications, their documentation, and the respective step-by-step integration guides.
9+
Copy one of the sample environment files:
1110

12-
| Environment | Documentation | Description | Primary Audience | Integration Guide |
13-
|-------------|----------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
14-
| Node.js | [UID2 SDK Integration Example](./publisher/standard/README.md) | Demonstrates how to use the UID2 services with the [UID2 client SDK](https://unifiedid.com/docs/sdks/client-side-identity) to implement the standard UID2 integration workflow. | Publishers with web assets | [Client SDK Integration Guide](https://unifiedid.com/docs/guides/publisher-client-side) |
15-
| Node.js | [Server-Only UID2 Integration Example](https://github.com/UnifiedID2/uid2-examples/tree/main/publisher/server_only) | Demonstrates how to use the UID2 services to implement a custom (server-only) UID2 integration workflow without relying on an SDK for establishing client UID2 identity and retrieving advertising tokens. | App developers and CTV broadcasters | [Server-Only UID2 Integration Guide](https://unifiedid.com/docs/guides/custom-publisher-integration) |
16-
| Java | [Java SDK Integration Example](./publisher/uid2-java-test-site/README.md) | Demonstrates use of the [UID2 Java SDK](https://github.com/IABTechLab/uid2-client-java) for both a server-only UID2 integration, and a standard (client SDK and server SDK) integration. | Publishers with web assets, app developers, CTV broadcasters | [Server-Only](https://unifiedid.com/docs/guides/custom-publisher-integration); [Client SDK](https://unifiedid.com/docs/guides/publisher-client-side) |
11+
```bash
12+
# For UID2
13+
cp .env.sample.uid2 .env
1714

18-
The example applications illustrate the basic steps that you need to consider for your integration. For example, you need to decide how to do the following:
19-
- Implement user login and logout.
20-
- Manage UID2 identity information and use it for targeted advertising.
21-
- Refresh tokens.
22-
- Deal with missing identities.
23-
- Handle user opt-outs.
15+
# For EUID
16+
cp .env.sample.euid .env
17+
```
2418

25-
## Docker Compose Setup
19+
Edit `.env` and add your credentials:
20+
- `UID_API_KEY` - Your API key
21+
- `UID_CLIENT_SECRET` - Your client secret
22+
- `UID_CSTG_SERVER_PUBLIC_KEY` - Your CSTG public key
23+
- `UID_CSTG_SUBSCRIPTION_ID` - Your CSTG subscription ID
2624

27-
This repository includes Docker Compose configuration for easy development and testing of multiple UID2 integration examples.
25+
### 2. Run a Local Operator (Required)
2826

29-
### Quick Start
27+
These sample sites require a local UID2 operator instance.
3028

31-
**Start all services:**
32-
```bash
33-
docker-compose up -d
34-
```
29+
1. Clone the operator repo:
30+
```bash
31+
git clone https://github.com/IABTechLab/uid2-operator.git
32+
```
3533

36-
**Start a single service:**
37-
```bash
38-
# Start only the Prebid.js client-side integration
39-
docker-compose up -d prebid-client
34+
2. Follow the setup instructions in the [uid2-operator README](https://github.com/IABTechLab/uid2-operator#readme)
4035

41-
# Start with live logs (foreground)
42-
docker-compose up prebid-client
43-
```
36+
3. Ensure the operator is running on `http://localhost:8080`
37+
38+
---
39+
40+
## Running the Sample Sites
41+
42+
### Start All Services
4443

45-
**Stop services:**
4644
```bash
45+
# Start all sample sites
46+
docker-compose up -d
47+
4748
# Stop all services
4849
docker-compose down
50+
```
51+
52+
### Start a Single Service
53+
54+
```bash
55+
# Start only prebid-client
56+
docker-compose up -d prebid-client
4957

5058
# Stop a single service
5159
docker-compose stop prebid-client
5260
```
5361

54-
**View logs:**
55-
```bash
56-
# View all logs
57-
docker-compose logs -f
5862

59-
# View logs for a specific service
60-
docker-compose logs -f prebid-client
61-
```
63+
### Rebuild After Code Changes
6264

63-
**Rebuild and restart:**
6465
```bash
65-
# Rebuild and restart all services
66+
# Rebuild all
6667
docker-compose up -d --build
6768

68-
# Rebuild and restart a single service
69+
# Rebuild a single service
6970
docker-compose up -d --build prebid-client
7071
```
72+
See the list below for the name of all individual services.
7173

72-
### Available Services
73-
74-
- **`prebid-client`** - Prebid.js client-side integration (Port: 3031)
75-
- **`javascript-sdk-client`** - JavaScript SDK client-server integration (Port: 3051)
76-
- *More services will be added as they are containerized*
74+
---
7775

78-
### Environment Configuration
76+
## Available Sample Sites
7977

80-
This repository includes sample environment files for both UID2 and EUID configurations:
78+
| Service Name | Description | Port | URL |
79+
|--------------|-------------|------|-----|
80+
| `javascript-sdk-client-side` | JavaScript SDK Client Side | 3031 | http://localhost:3031 |
81+
| `javascript-sdk-client-server` | JavaScript SDK Client Server | 3032 | http://localhost:3032 |
82+
| `server-side` | Server Side Integration | 3033 | http://localhost:3033 |
83+
| `javascript-sdk-react-client-side` | JavaScript SDK React | 3034 | http://localhost:3034 |
84+
| `google-secure-signals-client-server` | Google Secure Signals Client Server | 3041 | http://localhost:3041 |
85+
| `google-secure-signals-client-side` | Google Secure Signals Client Side | 3042 | http://localhost:3042 |
86+
| `google-secure-signals-server-side` | Google Secure Signals Server Side | 3043 | http://localhost:3043 |
87+
| `google-secure-signals-react-client-side` | Google Secure Signals React | 3044 | http://localhost:3044 |
88+
| `prebid-client` | Prebid Client Side | 3051 | http://localhost:3051 |
89+
| `prebid-client-server` | Prebid Client Server | 3052 | http://localhost:3052 |
90+
| `prebid-client-side-deferred` | Prebid Client Side Deferred | 3053 | http://localhost:3053 |
91+
| `prebid-secure-signals-client-side` | Prebid Secure Signals | 3061 | http://localhost:3061 |
8192

82-
- **`.env.sample.uid2`** - UID2 configuration template
83-
- **`.env.sample.euid`** - EUID configuration template
93+
---
8494

85-
**To get started:**
86-
87-
1. Copy the appropriate sample file to `.env`:
88-
```bash
89-
# For UID2
90-
cp .env.sample.uid2 .env
91-
92-
# For EUID
93-
cp .env.sample.euid .env
94-
```
95+
## Run Without Local Operator (Using Integ Environment)
9596

96-
2. Update the `.env` file with your credentials:
97-
- Replace `your-api-key` with your actual API key
98-
- Replace `your-client-secret` with your actual client secret
99-
- Update other placeholder values as needed
97+
If you don't want to run a local operator, you can use HTTPS with custom domains to hit the integration environment operator instead.
10098

101-
The sample files include all necessary environment variables for running the examples, including configuration for:
102-
- Core API endpoints
103-
- JavaScript SDK settings
104-
- Google Secure Signals integration
105-
- Prebid integration
106-
- React client examples
107-
- UI/Display preferences
99+
This setup:
100+
- Uses `https://` with subdomains (e.g., `https://prebid-client.sample-dev.com`)
101+
- Connects to the UID2 integration operator (no local operator required)
102+
- Requires certificate setup and hosts file configuration
108103

104+
See [tools/reverse-proxy/README.md](tools/reverse-proxy/README.md) for setup instructions.

createCA.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { createCA, createCert } from 'mkcert';
2+
import { allDomains } from './siteDetails';
3+
import fs from 'node:fs/promises';
4+
5+
const domains = allDomains;
6+
7+
const caFolder = './ca/';
8+
const caFile = `${caFolder}ca.crt`;
9+
const caKey = `${caFolder}ca.key`;
10+
const certFile = `${caFolder}cert.crt`;
11+
const certKey = `${caFolder}cert.key`;
12+
13+
const overwriteFileOptions = {
14+
flag: 'w',
15+
};
16+
const failIfExistsFileOptions = {
17+
flag: 'wx',
18+
};
19+
20+
const fileExists = async (path: string) => !!(await fs.stat(path).catch((e) => false));
21+
22+
const getOrCreateCA = async () => {
23+
if (await fileExists(caFile)) {
24+
console.log('Found existing CA, loading...');
25+
return {
26+
cert: await fs.readFile(caFile, { encoding: 'utf8' }),
27+
key: await fs.readFile(caKey, { encoding: 'utf8' }),
28+
};
29+
} else {
30+
console.log('Creating new CA...');
31+
const ca = await createCA({
32+
organization: 'UID2 Examples local dev CA',
33+
countryCode: 'AU',
34+
state: 'NSW',
35+
locality: 'Sydney',
36+
validity: 3650,
37+
});
38+
await fs.mkdir(caFolder, { recursive: true });
39+
await fs.writeFile(caFile, ca.cert, failIfExistsFileOptions);
40+
await fs.writeFile(caKey, ca.key, failIfExistsFileOptions);
41+
return ca;
42+
}
43+
};
44+
45+
async function createCerts() {
46+
const ca = await getOrCreateCA();
47+
console.log(`Creating a certificate for ${domains.join(', ')}`);
48+
const cert = await createCert({
49+
ca: { key: ca.key, cert: ca.cert },
50+
domains,
51+
validity: 3650,
52+
});
53+
console.log('Certificate created.');
54+
55+
await fs.writeFile(certFile, `${cert.cert}${ca.cert}`, overwriteFileOptions);
56+
await fs.writeFile(certKey, cert.key, overwriteFileOptions);
57+
58+
console.log('Certificate saved to ./ca/ folder.');
59+
console.log('');
60+
console.log('Next steps:');
61+
console.log('1. Trust the CA certificate (ca.crt) in your system/browser');
62+
console.log('2. Add the domains to your hosts file (see README.md)');
63+
console.log('3. Run: docker-compose up');
64+
}
65+
66+
createCerts();
67+

docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ services:
66
dockerfile: Dockerfile
77
ports:
88
- "80:80"
9+
- "443:443"
10+
volumes:
11+
- ./ca:/etc/nginx/certs:ro
912
container_name: reverse-proxy
1013
environment:
1114
- DOMAIN=${DOMAIN:-sample-dev.com}
@@ -115,6 +118,16 @@ services:
115118
env_file:
116119
- .env
117120

121+
prebid-client-side-deferred:
122+
build:
123+
context: web-integrations/prebid-integrations
124+
dockerfile: client-side-deferred/Dockerfile
125+
ports:
126+
- "3053:3053"
127+
container_name: prebid-client-side-deferred
128+
env_file:
129+
- .env
130+
118131
# prebid + secure signals integrations
119132
prebid-secure-signals-client-side:
120133
build:

package-lock.json

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,15 @@
33
"version": "0.2.71",
44
"private": true,
55
"description": "UID2 Integration Examples",
6-
"license": "BSD-2-Clause"
6+
"license": "BSD-2-Clause",
7+
"engines": {
8+
"node": ">=18"
9+
},
10+
"scripts": {
11+
"createCA": "tsx createCA.ts"
12+
},
13+
"devDependencies": {
14+
"mkcert": "^3.2.0",
15+
"tsx": "^4.19.1"
16+
}
717
}

0 commit comments

Comments
 (0)