Skip to content

Commit f1329a4

Browse files
authored
Merge pull request #31 from IABTechLab/aaq-UID2-2877-dsp-check-client-refactor
Add BidStreamClient and SharingClient
2 parents bbc2ec9 + 588e980 commit f1329a4

32 files changed

+1654
-316
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ test:
66
shell:
77
docker run -it -w $(PWD) -v $(PWD):$(PWD) -u `id -u`:`id -g` $(DOCKERIMAGE) /bin/bash
88

9-
examples: example_client example_auto_refresh example_sharing example_publisher
9+
examples: example_client example_auto_refresh example_sharing example_publisher example_bidstream_client example_sharing_client
1010

1111
example_client:
1212
docker run -w $(PWD) -v $(PWD):$(PWD) -u `id -u`:`id -g` -e PYTHONPATH=$(PWD) $(DOCKERIMAGE) python3 examples/sample_client.py "$(BASE_URL)" "$(AUTH_KEY)" "$(SECRET_KEY)" "$(AD_TOKEN)"
@@ -23,6 +23,12 @@ example_sharing:
2323
example_publisher:
2424
docker run -w $(PWD) -v $(PWD):$(PWD) -u `id -u`:`id -g` -e PYTHONPATH=$(PWD) $(DOCKERIMAGE) python3 examples/sample_token_generate_refresh.py "$(BASE_URL)" "$(AUTH_KEY)" "$(SECRET_KEY)"
2525

26+
example_bidstream_client:
27+
docker run -w $(PWD) -v $(PWD):$(PWD) -u `id -u`:`id -g` -e PYTHONPATH=$(PWD) $(DOCKERIMAGE) python3 examples/sample_bidstream_client.py "$(BASE_URL)" "$(AUTH_KEY)" "$(SECRET_KEY)" "$(DOMAIN)" "$(AD_TOKEN)"
28+
29+
example_sharing_client:
30+
docker run -w $(PWD) -v $(PWD):$(PWD) -u `id -u`:`id -g` -e PYTHONPATH=$(PWD) $(DOCKERIMAGE) python3 examples/sample_sharing_client.py "$(BASE_URL)" "$(AUTH_KEY)" "$(SECRET_KEY)" "$(RAW_UID)"
31+
2632
docker:
2733
docker build -t $(DOCKERIMAGE) -f Dockerfile.dev .
2834

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ To run all the example applications:
6767
```
6868
make examples BASE_URL=https://prod.uidapi.com AUTH_KEY=my-auth-key SECRET_KEY=my-secret-key \
6969
AD_TOKEN=AgAAAANRdREk+IWqqnQkZ2rZdK0TgSUP/owLryysSkUGZJT+Gy551L1WJMAZA/G2B1UMDQ20WAqwwTu6o9TexWyux0lg0HHIbmJjN6IYwo+42KC8ugaR+PX0y18qQ+3yzkxmJ/ee//4IGu/1Yq4AmO4ArXN6CeszPTxByTkysVqyQVNY2A== \
70-
RAW_UID=JCqmlLXpbbu/jTdpB2a1cNAVs8O72eMXPaQzC9Ic9mE=
70+
RAW_UID=JCqmlLXpbbu/jTdpB2a1cNAVs8O72eMXPaQzC9Ic9mE= \
71+
DOMAIN=example.com
7172
```
7273

7374
Alternatively, you can run specific examples:

examples/sample_auto_refresh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _usage():
3030
if refresh_result.ready:
3131
print('Keys are ready, last refreshed (UTC):', refresh_result.last_success_time, flush=True)
3232
result = client.decrypt(ad_token)
33-
print('UID2 =', result.uid2, flush=True)
33+
print('UID =', result.uid, flush=True)
3434
else:
3535
print('Keys are not ready yet, last error:', refresh_result.last_error[1], flush=True)
3636
time.sleep(1)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import sys
2+
3+
from uid2_client import BidstreamClient
4+
5+
6+
# this sample client decrypts an advertising token into a raw UID2
7+
# to demonstrate decryption for DSPs
8+
9+
def _usage():
10+
print('Usage: python3 sample_bidstream_client.py <base_url> <auth_key> <secret_key> <domain_name> <ad_token>', file=sys.stderr)
11+
sys.exit(1)
12+
13+
14+
if len(sys.argv) < 6:
15+
_usage()
16+
17+
base_url = sys.argv[1]
18+
auth_key = sys.argv[2]
19+
secret_key = sys.argv[3]
20+
domain_name = sys.argv[4]
21+
ad_token = sys.argv[5]
22+
23+
client = BidstreamClient(base_url, auth_key, secret_key)
24+
refresh_response = client.refresh()
25+
if not refresh_response.success:
26+
print('Failed to refresh keys due to =', refresh_response.reason)
27+
sys.exit(1)
28+
29+
decrypt_result = client.decrypt_token_into_raw_uid(ad_token, domain_name)
30+
31+
print('Status =', decrypt_result.status)
32+
print('UID =', decrypt_result.uid)
33+
print('Established =', decrypt_result.established)
34+
print('Site ID =', decrypt_result.site_id)
35+
print('Identity Type =', decrypt_result.identity_type)
36+
print('Advertising Token Version =', decrypt_result.advertising_token_version)
37+
print('Is Client Side Generated =', decrypt_result.is_client_side_generated)

examples/sample_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# THIS FILE IS DEPRECATED!
2+
# To learn how to decrypt a UID2 advertising token for DSPs, see sample_bidstream_client.py
3+
14
import sys
25

36
from uid2_client.euid_client_factory import EuidClientFactory

examples/sample_encryption.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
from uid2_client import encrypt_data, decrypt_data
66

77
# THIS FILE IS DEPRECATED!
8-
# To learn how to encrypt and decrypt a UID2 advertising token, see sample_sharing.py (For sharers. See sample_client.py for DSPs)
8+
# To learn how to encrypt and decrypt a UID2 sharing token, see sample_sharing_client.py (For sharers. See sample_bidstream_client.py for DSPs)
99

1010
def _usage():
1111
print('Usage: python3 sample_encryption.py <base_url> <auth_key> <secret_key> <ad_token> <data>', file=sys.stderr)
1212
sys.exit(1)
1313

14-
1514
if len(sys.argv) <= 5:
1615
_usage()
1716

examples/sample_sharing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# THIS FILE IS DEPRECATED!
2+
# To learn how to encrypt and decrypt a UID2 sharing token, see sample_sharing_client.py (For sharers. See sample_bidstream_client.py for DSPs)
3+
14
import sys
25

36
from uid2_client import EuidClientFactory
@@ -31,7 +34,7 @@ def _usage():
3134

3235
decrypt_result = client.decrypt(new_ad_token)
3336

34-
print('Decrypted UID2 =', decrypt_result.uid2)
37+
print('Decrypted UID =', decrypt_result.uid)
3538
print('Established =', decrypt_result.established)
3639
print('Site ID =', decrypt_result.site_id)
3740
print('Site Key Site ID =', decrypt_result.site_key_site_id)

examples/sample_sharing_client.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import sys
2+
3+
from uid2_client import SharingClient
4+
5+
6+
# this sample client encrypts and decrypts a raw uid to a sharing token
7+
# to demonstrate encryption and decryption for sharers
8+
9+
def _usage():
10+
print('Usage: python3 sample_sharing_client.py <base_url> <auth_key> <secret_key> <raw_uid>', file=sys.stderr)
11+
sys.exit(1)
12+
13+
14+
if len(sys.argv) <= 4:
15+
_usage()
16+
17+
base_url = sys.argv[1]
18+
auth_key = sys.argv[2]
19+
secret_key = sys.argv[3]
20+
raw_uid = sys.argv[4]
21+
22+
client = SharingClient(base_url, auth_key, secret_key)
23+
refresh_response = client.refresh()
24+
if not refresh_response.success:
25+
print('Failed to refresh keys due to =', refresh_response.reason)
26+
sys.exit(1)
27+
28+
encryption_data_response = client.encrypt_raw_uid_into_token(raw_uid)
29+
30+
print('New Sharing Token =', encryption_data_response.encrypted_data)
31+
32+
decrypt_result = client.decrypt_token_into_raw_uid(encryption_data_response.encrypted_data)
33+
34+
print('Status =', decrypt_result.status)
35+
print('Decrypted UID =', decrypt_result.uid)
36+
print('UID =', decrypt_result.uid)
37+
print('Established =', decrypt_result.established)
38+
print('Site ID =', decrypt_result.site_id)
39+
print('Identity Type =', decrypt_result.identity_type)
40+
print('Advertising Token Version =', decrypt_result.advertising_token_version)

0 commit comments

Comments
 (0)